草庐IT

current_index

全部标签

c# - 更改 IEnumerator<T>.Current 的属性

今天我很惊讶地观察到以下行为:给定一个类classFoo{propintFooNumber{get;set;}}和这段代码IEnumerablefoos=Enumerable.Range(0,3).Select(newFoo());foreach(varfooinfoos)foo.Bar=5;foreach(varfooinfoos)Console.Write(foo.Bar);//Writes000初始化时foos至newList{newFoo(),newFoo(),newFoo()}使循环写入“555”。我的问题:为什么会发生这种情况,有没有办法在不使用.ToList()的情况下避

c# - 测试使用 HttpContext.Current.Request.Files 的 Web API 方法?

我正在尝试为使用HttpContext.Current.Request.Files的WebAPI方法编写测试,经过详尽的搜索和实验后,我无法弄清楚如何模拟它。正在测试的方法如下所示:[HttpPost]publicHttpResponseMessagePost(){varrequestFiles=HttpContext.Current.Request.Files;varfile=requestFiles.Get(0);//dosomeotherstuff...}我意识到有otherquestionssimilartothis,但他们没有解决这个具体情况。如果我尝试模拟上下文,我会遇到H

c# - 格式化日期时间错误 "Templates can be used only with field access, property access, single-dimension array index.."

在MVCRazorView中,我试图将DateTime字段格式化为仅显示时间。使用下面的代码我收到错误“模板只能用于字段访问、属性访问、一维数组索引或单参数自定义索引器表达式。”@(Html.DisplayFor(m=>row.LastUpdatedDate.ToString("HH:mm:ss")))任何帮助请问是什么导致了这个错误以及如何解决它?感谢您的帮助。 最佳答案 我遇到了同样的问题,我已经解决了。如果您想将“LastUpdatedDate”转换为特定格式,那么您可以试试这个:@Html.TextBoxFor(m=>row

c# - HttpContext.Current.Request.UserHostAddress 为空

在我的开发机器中HttpContext.Current.Request.UserHostAddress为空。为什么?我怎样才能打开它?如果是代理客户端,如何获取Ips列表?WCF服务与ASP.net4window7。谢谢 最佳答案 为避免此问题,您可以解析最后输入IP的HTTP_X_FORWARDED_FOR。ip=Request.ServerVariables["HTTP_X_FORWARDED_FOR"];if(!string.IsNullOrEmpty(ip)){string[]ipRange=ip.Split(',');in

c# - 通过反射调用 this[int index]

我尝试为MicrosoftOffice实现一个基于反射的后期绑定(bind)库。OfficeCOM对象的属性和方法调用方式如下:Typetype=Type.GetTypeFromProgID("Word.Application");objectcomObject=Activator.CreateInstance(type);type.InvokeMember(,,null,comObject,newobject[]{});InvokeMember是唯一可能的方法,因为Type.GetMethod/GetProperty无法正确处理COM对象。可以使用InvokeMember调用方法和属

c# - "The breakpoint will not currently be hit. A copy of file was found in dll file, but the current source code is different"

我不断收到此错误消息,提示存在.cs文件的副本,因此不会命中断点。我尝试过清理解决方案、重建、删除obj和bin文件夹中的.pdb文件、关闭VS并重新启动它、重新启动整个机器(这是Windows!有时最复杂、无法解释的问题会像这样解决:\)知道我还能尝试什么吗?这是VS2015上的.net项目 最佳答案 我发现了问题,原来IIS配置为使用我备份文件夹中项目的不同副本。这听起来很傻,但如果有人有类似的问题,我会保留这个问题。 关于c#-"Thebreakpointwillnotcurren

c# - 异步任务中的 HttpContext.Current null

我有一个使用存储库的方法(userRepo):publicoverrideTaskCreateLocalUserAsync(IUseruser,stringpassword,CancellationTokencancellationToken){vartask=newTask(()=>{TUserEntitynewUser=newTUserEntity{Id=user.Id,UserName=user.UserName,Password=password};userRepo.Save(newUser).Flush();returnnewIdentityResult(true);},ca

c# - HttpContext.Current.Cache 是线程安全的吗?

请检查下面的代码:objDDLTable=HttpContext.Current.Cache["TestSet"]asHashtable;if(objDDLTable==null){objDDLTable=newHashtable();arrDDLItems=GetDropDownList("testDropDown");objDDLTable.Add("testDropDown",arrDDLItems);HttpContext.Current.Cache["TestSet"]=objDDLTable;}elseif(objDDLTable!=null&&!objDDLTable.C

c# - 使用最小起订量模拟 HttpContext.Current.Server.MapPath?

我正在对我的家庭Controller进行单元测试。在我添加保存图像的新功能之前,此测试运行良好。导致问题的方法如下所示。publicstaticvoidSaveStarCarCAPImage(intcapID){byte[]capBinary=Motorpoint2011Data.RetrieveCapImageData(capID);if(capBinary!=null){MemoryStreamioStream=newMemoryStream();ioStream=newMemoryStream(capBinary);//savethememorystreamasanimage//

c# - LinqToSQL 错误 : Operation is not valid due to the current state of the object

在更新命令期间,我收到以下错误:Operationisnotvalidduetothecurrentstateoftheobject我试图从更新命令中删除一列并且它工作正常。此列是一个FK,与其他工作正常的FK相似。这是执行更新的代码:ti.NumeroTitolo=titolo.Numero;ti.RKTipoTitoloGenereTitolo=titolo.RkTipoTitoloGenereTitolo;ti.RKBanca=titolo.RkBanca;ti.DataScadenza=titolo.DataScadenza;ti.RKTipoEsito=titolo.RkTi