草庐IT

find-objects

全部标签

c# - 将 Func<T> 转换为 Func<object>

我想知道如何通过Func至Func方法参数:publicvoidFoo(Funcp)whereT:class{Foo(p);}publicvoidFoo(Funcp){}奇怪的是,它在NET4.0类库中有效,但在Silverlight4类库中无效。实际上我希望它在Silverlight中工作,并且我有像Func这样的输入参数 最佳答案 这样就可以了:publicvoidFoo(Funcp)whereT:class{Funcf=()=>p();Foo(f);} 关于c#-将Func转换为F

c# - 什么是 Humble Object 模式,它何时有用?

我正在阅读anarticlebyDinoEspositoonhowtotestAsyncConrollersinASP.NETMVC并且在那里他使用了“不起眼的对象”模式,但没有详细介绍。我在谷歌上也没有太多运气。那么,什么是谦虚对象模式?什么时候有用? 最佳答案 有athoroughdescriptionatxunitpatterns.com.基本上,您将所有逻辑拉到一个单独的对象中,您可以轻松地对其进行测试-而您的“低级对象”将成为您可测试对象的包装器;只是不起眼的对象还依赖于难以测试的事物,例如异步服务或GUI类。这个想法是在

c# - WPF 调度程序 {"The calling thread cannot access this object because a different thread owns it."}

首先我需要说我是WPF和C#的菜鸟。应用程序:创建Mandelbrot图像(GUI)在这种情况下,我的调度员工作得很好:privatevoidprogressBarRefresh(){while((con.Progress)尝试使用以下代码执行此操作时,我收到了消息(标题):bmp=BitmapSource.Create(width,height,96,96,pf,null,rawImage,stride);this.Dispatcher.Invoke(DispatcherPriority.Send,newAction(delegate{img.Source=bmp;ViewBox.C

c# - 如何在一行 C# 3.0 中将 object[] 转换为 List<string>?

好吧,我放弃了,你如何在一行中做到这一点?publicobjectConvert(object[]values,TypetargetType,objectparameter,System.Globalization.CultureInfoculture){//Listfields=values.ToList();//Listfields=valuesasList;//Listfields=(List)values;Listfields=newList();foreach(objectvalueinvalues){fields.Add(value.ToString());}//proce

c# - 嵌入式 RavenDB 出现 "Could not find transactional storage type"错误

我能够根据在以下位置找到的代码成功运行RavenDB的简单测试:http://ravendb.net/tutorials/hello-world接下来我尝试以嵌入式方式运行它,但我不断收到以下错误:Message:Couldnotfindtransactionalstoragetype:Raven.Storage.Esent.TransactionalStorage,Raven.Storage.EsentStackTrace:atRaven.Database.Config.InMemoryRavenConfiguration.CreateTransactionalStorage(Act

c# - 为什么 Object.GetType() 不是虚拟的?

取自MSDN的代码示例publicclassTest{publicstaticvoidMain(){MyBaseClassmyBase=newMyBaseClass();MyDerivedClassmyDerived=newMyDerivedClass();objecto=myDerived;MyBaseClassb=myDerived;Console.WriteLine("mybase:Typeis{0}",myBase.GetType());Console.WriteLine("myDerived:Typeis{0}",myDerived.GetType());Console.Wr

c# - Windows7 中的 VS 2010 设计器错误 'Could not find type XYZ'。在 XP 中工作正常

我在VS2010C#.NET中遇到了一个问题。我在WindowsXP上有一个项目,其中包括表单、类和一些我自己的自定义组件。这些组件是内置MS组件的简单扩展(例如DataGridViewEx作为DataGridView的扩展)。在XP中一切正常。我正在尝试将此项目移植到Windows7/x64上的VS2010。我有在Windows7上编译正常的解决方案,但是在设计模式下,当我打开包含自定义控件之一的窗体时,出现错误“找不到类型XYZ.DataGridViewEx”。请确保引用了包含此类型的程序集。'XYZ是我用于这些控件的命名空间,它与使用这些控件的窗体是同一个命名空间。所有都是同一个

c# - Visual Studio 2008/C# : How to find dead code in a project?

如何在VisualStudio2008C#项目中找到死代码?比如未使用的类、未使用的变量或未使用的资源? 最佳答案 你可以试试FxCop,它以代码分析的名称集成在VisualStudio2008中。您只需右键单击项目文件并选择“运行代码分析”。FxCopisanapplicationthatanalyzesmanagedcodeassemblies(codethattargetsthe.NETFrameworkcommonlanguageruntime)andreportsinformationabouttheassemblies,

c# - 如何结合 Find() 和 AsNoTracking()?

如何在查询EF上下文时将Find()与AsNoTracking()结合使用,以防止跟踪返回的对象。这是我做不到的_context.Set().AsNoTracking().Find(id);我该怎么做?我使用的是EF版本6。注意:我不想使用SingleOrDefault()或Where。我不能,因为参数Id是通用的,它是一个struct,在这种情况下我不能为泛型应用运算符==。 最佳答案 因此,除了使用AsNoTracking(),您可以做的是Find(),然后将其从上下文中分离出来。我相信除了跟踪实体的额外开销之外,这会为您提供与

c# - 为什么 var 在 "foreach (var row in table.Rows)"中评估为 System.Object ?

当我输入此foreach语句时...foreach(varrowintable.Rows)...var的工具提示显示classSystem.Object我很困惑为什么它不是classSystem.Data.DataRow。(如果您想知道,是的,我的代码文件顶部有usingSystem.Data。)如果我显式声明类型,如...foreach(DataRowrowintable.Rows)...它工作正常,没有错误。如果我这样做...varnumbers=newint[]{1,2,3};foreach(varnumberinnumbers)...var的计算结果为structSystem.