草庐IT

TYPE_NULL

全部标签

c# - 销毁对象时自定义事件是否需要设置为null?

假设我们有2个对象,Broadcaster和Listener。Broadcaster有一个名为Broadcast的事件,Listener订阅了该事件。如果Listener在没有取消订阅Broadcast事件的情况下被释放,它将保留在内存中,因为Broadcaster包含引用它的事件委托(delegate)。我很好奇的是,如果Broadcaster在没有Listener取消订阅或Broadcaster设置Broadcast=null的情况下被处置,Broadcaster是否会保留在内存中?除了一位博主认为不将事件设置为null会将源保留在内存中(找到here)之外,我无法找到任何对这个问

c# - ASP.net Core 2.0 中的 appsettings.json 预览配置 GetSection null

我试图从Startup.cs中的注入(inject)配置调用GetSection。值为null,而indexer到具体部分值返回non-null值。在我看来,GetSection方法背后有一个错误,或者我错了?appsettings.json:{"MyConfig":{"ConfigA":"valueA","ConfigB":"valueB"}}程序.cs:publicstaticvoidMain(string[]args){varhost=BuildWebHost(args);host.Run();}publicstaticIWebHostBuildWebHost(string[]a

c# - ConfigurationManager 返回 null 而不是字符串值

我正在尝试从存储在我的工作目录中的App.config文件中检索值,但是当我运行该程序时它返回null。我很困惑为什么会这样,并且多次查看代码以试图发现错误。这是我的App.config文件代码:这是我的C#代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Configuration;usingSystem.Data;usingSystem.Data.Common;namespaceDataProviderFun{classProgram{static

c# - T4 模板错误 : loading the include file ef. utility.cs.ttinclude 返回了 null 或空字符串

我已经覆盖了Controller生成T4模板(ControllerWithContext.tt),如here所述.我想利用在POCO模型生成器T4模板中使用的EF.utility.CS.ttinclude中的代码帮助实用程序。因此,我将以下行从我的Model.tt复制到我的ControllerWithContext.tt。但是,当我尝试添加Controller时,我收到了错误消息Loadingtheincludefile'EF.utility.CS.ttinclude'returnedanulloremptystring根据MSDNdocumentation,这个错误是因为包含的文件是

c# - .NETStandard 1.0/.NET Core 中 Type.GetGenericArguments() 的等价物是什么?

.NETStandard1.0中“缺少”方法System.Type.GetGenericArguments(),我认为TypeInfo.GenericTypeArguments是的替代品GetGenericArguments(),但不幸的是,当提供开放泛型类型时,它们的行为会有所不同。以下面的代码为例:Typetype=typeof(ICommandHandler);type.GetGenericArguments();//return{TCommand}type.GetTypeInfo().GenericTypeArguments;//returnsemptyarray虽然GetGe

c# - 需要重载 operator< 和 null 检查

我在C#中重载了lessthan运算符,我想知道这是否需要检查null。您可以在下面找到一个示例:publicstaticbooloperator或者这是正确的:publicstaticbooloperator我没有找到任何关于此的说明。但也许我错过了什么。 最佳答案 答案取决于您的预期使用模式。如果您计划混合使用空值,并且您希望null值小于非空值,那么您的实现是正确的;如果您想将null值视为大于非null对象,则注释掉的返回值(false和true)应该被使用。如果您不打算在混合中允许空值,则抛出ArgumentNullExc

c# - Dapper 抛出 "Invalid type owner for DynamicMethod."

所以我正在尝试使用Dapper.net,而且我很喜欢它。我不喜欢的是当我尝试批量插入实体时抛出以下错误:DynamicMethod的类型所有者无效。atSystem.Reflection.Emit.DynamicMethod.Init(Stringname,MethodAttributesattributes,CallingConventionscallingConvention,TypereturnType,Type[]signature,Typeowner,Modulem,BooleanskipVisibility,BooleantransparentMethod,StackCra

c# - 如何从基类中获取子类的 `Type`

我有一个抽象基类,我想在其中实现一个方法来检索继承类的特性属性。像这样的……publicabstractclassMongoEntityBase:IMongoEntity{publicvirtualobjectGetAttributeValue(stringpropertyName)whereT:Attribute{varattribute=(T)typeof(this).GetCustomAttribute(typeof(T));returnattribute!=null?attribute.GetType().GetProperty(propertyName).GetValue(a

c# - XML 序列化错误 : 2 types both use the XML type name, 'Relationship',来自命名空间 ''

我在通过XML进行序列化时遇到问题,因为2个类使用一个类(尽管类不同!)称为关系。我尝试使用XML属性用另一个名称装饰其中的一个类,但它仍然给我以下错误:{"Types'SiteServer.Relationship'and'LocalServer.Relationship'bothusetheXMLtypename,'Relationship',fromnamespace''.UseXMLattributestospecifyauniqueXMLnameand/ornamespaceforthetype."}这是我的2个类(class),有人知道为什么吗??我使用了错误的属性吗?它似

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

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