草庐IT

sonata_type_collection

全部标签

c# - 保留一个 Dictionary<Type, MyClass<T>> ,其中元素可以按类型引用

我有一个名为EntityTypeTransform的抽象类,它有一个抽象方法,用于保存将IDataRecord转换为T实例的Func委托(delegate)。publicabstractclassEntityTypeTransformwhereTEntityType:class{publicabstractFuncGetDataTransform();}该类的实现可能看起来像(看起来像):publicclassTaskParameterEntityTypeTransform:EntityTypeTransform{publicoverrideFuncGetDataTransform()

c# - 编译转换 : The type 'Object' is defined in an assembly that is not referenced

我正在对一个asp.NetMVC5网络应用程序进行一些更改,我在其中使用了typelite从C#类创建.ts定义(非常方便)。出于某种原因,现在我在执行T4时遇到了这个错误:Compilingtransformation:Thetype'Object'isdefinedinanassemblythatisnotreferenced.Youmustaddareferencetoassembly'mscorlib,Version=2.0.5.0,Culture=neutral,PublicKeyToken=7cec85d7bea7798e,Retargetable=Yes'.和这个警告:C

c# - 使用 Type 变量转换对象

当然,以下是行不通的。有没有一种可能的方法,与此非常相似?TypenewObjectType=typeof(MyClass);varnewObject=givenObjectasnewObjectType; 最佳答案 newObjectType是Type类(包含有关类型的元数据)的实例,而不是type本身.这应该可行varnewObject=givenObjectasMyClass;或varnewObject=(MyClass)givenObject;转换为类型实例确实没有意义,因为编译时必须知道变量类型应该是什么,而类型实例是运行

c# - 包含路径表达式必须引用 type.in 预加载中定义的导航属性

我尝试像这样包含匿名类型:除了CompanyTitle,PeriodTypeName之外,我还想要所有incomelist属性varincomeList=ctx.IncomeLists.Include(i=>new{CompanyTitle=i.CompanyId.ToString()+"/"+i.Company.CompanyName,PeriodTypeName=i.ListPeriods.Select(lp=>lp.PeriodType.PeriodTypeName)}).ToList()我的模型部分是这样的:但我得到以下异常:TheIncludepathexpressionmu

C# 功能请求 : implement interfaces on anonymous types

我想知道做这样的事情需要什么:usingSystem;classProgram{staticvoidMain(){varf=newIFoo{Foo="foo",Print=()=>Console.WriteLine(Foo)};}}interfaceIFoo{StringFoo{get;set;}voidPrint();}创建的匿名类型看起来像这样:internalsealedclassf__AnonymousType0j__TPar>:IFoo{readonlyj__TPari__Field;publicf__AnonymousType0(j__TParFoo){this.i__Fi

c# - 无法将带有 [] 的索引应用于 mvc Controller 中类型为“System.Collections.Generic.ICollection<int>”的表达式

publicActionResultaddstandardpackage1(ICollectionSingleStay,ICollectionDOUBLESTAY,ICollectionTRIBLESTAY,ICollectionFAMILYSTAY,ICollectionEXTRABED){vars=SingleStay;for(inti=0;i在for循环中,我收到类似无法将带[]的索引应用于类型表达式的错误,但我需要在for循环中,在我得到的每个中。因为基于for循环,我会将详细信息与其他集合列表绑定(bind)。请帮助我。我在varcal=Singlestay[i]中遇到错误。

c# - 在 C# 中使用 Type.GetType() 返回的类型

我有一个关于如何可能的问题(如果可能的话:)例如,使用Type.GetType()返回的类型引用来创建该类型的IList?这里是示例代码:Typecustomer=Type.GetType("myapp.Customer");IListcustomerList=newList();//gotanerrorhere=[提前致谢! 最佳答案 像这样:TypelistType=typeof(List).MakeGenericType(customer);IListcustomerList=(IList)Activator.CreateIn

c# - GC.Collect() 阻塞了吗?

我正在对我的代码运行一些基准测试,我想确保在我的一个基准测试期间不会发生垃圾收集,因为它正在清理先前测试的困惑情况。我认为我最好的机会是在开始基准测试之前强制收集。所以我在基准测试开始之前调用GC.Collect()但不确定收集是否继续在单独的线程中运行,等等并立即返回。如果它确实在BG线程上运行,我想知道如何同步调用它或至少等到它完成收集。 最佳答案 如MSDN所述-使用此方法尝试回收所有不可访问的内存。无论如何,如果它确实开始了垃圾收集,您应该在开始基准测试之前等待所有终结器完成。GC.Collect();GC.WaitForP

c# - 使用 MultipartFormDataContent 生成错误的 Content-Type header

我有以下代码:privatestaticstringboundary="----CustomBoundary"+DateTime.Now.Ticks.ToString("x");privatestaticasyncTaskPostTest(){stringservResp="";using(varcontent=newMultipartFormDataContent(boundary)){content.Add(newStringContent("105212"),"case-id");content.Add(newStringContent("1/14/2014"),"dateFro

c# - 序列化异常 : Type is not resolved for member "..."

我一直在尝试将程序集动态加载到AppDomain。我需要这样做是因为我想动态调用一个方法,但在我的应用程序运行时不要保留DLL的句柄,以便在需要时可以替换它。但我收到此SerializationException异常:类型未解析成员“...”这是我的代码:AppDomaindomain=AppDomain.CreateDomain("TempAppDomain",null,AppDomain.CurrentDomain.SetupInformation);try{objectobj=domain.CreateInstanceFromAndUnwrap(dllPath,typeName)