草庐IT

nullable-reference-types

全部标签

c# - 在 Debug 中使用 Project Reference,在 Release 中使用 Nuget

我想同时在我的项目(A)和依赖的Nuget包(B)中工作,而不需要在每次更改时都发布nuget包。是否可以在构建调试时从解决方案(A)中引用Nuget项目(B)。在构建Release时使用Source中的Nuget包? 最佳答案 一种方法是手动编辑csproj文件。如果您当前已经引用了NuGet包,那么您将在csproj文件中拥有这样的部分:......\packages\log4net.2.0.8\lib\net45-full\log4net.dllTrue....在这个例子中,使用了log4net。对于您的NuGet包,公钥to

c# - "Both use the XML type name X, use XML attributes to specify a unique XML name and/or namespace for the type"怎么解决?

我有以下枚举定义...namespaceItemTable{publicenumDisplayMode{Tiles,Default}}namespaceEffectiveItemPermissionTable{publicenumDisplayMode{Tree,FullPaths}}...然后我有以下类(class)...publicclassTablewhereTDisplayMode:struct{//publicpublicTDisplayModeDisplayMode{get{returnmDisplayMode;}set{mDisplayMode=value;}}//pri

c# - IServiceLocator.GetInstance(Type) 的意图与 IServiceProvider.GetService(Type) 的意图有何不同?

方法签名的意图是否存在差异IServiceProvider.GetService(TypeserviceType)和IServiceLocator.GetInstance(TypeserviceType)?如果有,区别是什么?我一直将它们视为等同的,但为了保持一致性,我选择使用单一方法。对于处理这两个接口(interface)来说,这似乎是一个足够好的解决方案,但我真的很想知道它们的实际用途是怎样的,这样我就可以确定我在正确的地方使用了正确的接口(interface)。如果他们的意图实际上是相同的,那么是否有任何理由为了同一目的而使用多组语义?(我理解theGetInstancesig

c# - 当我尝试重命名方法时,为什么 Visual Studio 告诉我有 "compiler generated references"?

我有一个名为FormattedJoin()的方法在名为ArrayUtil的实用程序类中.我尝试重命名FormattedJoin()只是Join()因为它的行为类似于.NET的string.Join()所以我认为使用相同的名称是有意义的。但是,当我尝试使用VisualStudio重命名该方法时,我收到此警告:Thismembermayhavecompilergeneratedreferenceswiththesamename.Refactoringthememberwillnotupdatethesereferences,whichmayintroducesemanticchangesa

c# - Visual Studio 2015 中是否有用于 C# 的 "Go To Variable Type Declaration"函数或一个免费插件?

voidMagicalFunction(MagicalTypemagic){...magic.Poof("something");...varfoo=magic.GetFoo();...}在变量magic上按下热键将导航到类型MagicalType的定义。在foo上按下热键将转到类型Foo的定义,由于类型推断,它在这里不直接可见。Resharper插件具有此功能(称为GoToTypeofSymbol),但是是否有内置的替代方案或免费扩展来执行此操作? 最佳答案 右键单击“var”关键字,从上下文菜单中选择“Gotodefinitio

c# - 如何确定 System.Type 是自定义类型还是框架类型?

我想清楚地确定我拥有的类型是自定义类类型(MyClass)还是框架提供的类型(System.String)。有什么方法可以将我的类类型与system.string或其他框架提供的类型区分开来吗? 最佳答案 安全检查类型是否属于程序集的唯一方法是检查程序集的完全限定名称,其中包含其名称、版本、区域性和公钥(如果已签名)。所有.Net基类库(BCL)均由Microsoft使用其私钥签名。这使得其他任何人几乎不可能创建与基类库具有相同完全限定名称的程序集。//addmore.NetBCLnamesasnecessaryvarsystemN

c# - 在 Linq-To-Sql 中避免 "Nullable object must have a value."

我有一个这样的方法查询:publicIListGetBusinessObject(Guid?filterId){using(vardb=newL2SDataContext()){varresult=fromboindb.BusinessObjectswhere(filterId.HasValue)?bo.Filter==filterId.value:trueorderbybo.NameselectSqlModelConverters.ConvertBusinessObject(bo);returnresult.ToList();}}在运行时,这会抛出一个System.InvalidOp

c# - ExecuteScalar 调用抛出异常 "Object reference not set to an instance of an object"

在单元测试中调试以下方法时出现以下错误Objectreferencenotsettoaninstanceofanobject点击以下行时result=(int)validateDatabase.ExecuteScalar();方法是publicstaticBooleanValidate(stringargument1,stringargument2){intresult=-1;using(varconnection=newSqlConnection("connectionstring")){SqlCommandvalidateDatabase=newSqlCommand("PROCED

c# - 在单个 C# 泛型方法中返回 nullable 和 null?

是否可以在C#泛型方法中返回对象类型或Nullable类型?例如,如果我有一个List的安全索引访问器我想返回一个值,以后可以用==null检查或.HasValue().我目前有以下两种方法:staticT?SafeGet(Listlist,intindex)whereT:struct{if(list==null||index=list.Count){returnnull;}returnlist[index];}staticTSafeGetObj(Listlist,intindex)whereT:class{if(list==null||index=list.Count){return

c# - 类型 'MyObject' 必须是不可为 null 的值类型才能将其用作泛型类型或方法 'T' 中的参数 'Nullable<T>'

我正在使用.netframework4.5我得到以下错误ErrorCS0453Thetype'MyObject'mustbeanon-nullablevaluetypeinordertouseitasparameter'T'inthegenerictypeormethod'Nullable'publicasyncTask>MyMethod(stringmyParamter){}我也试过publicasyncTaskMyMethod(stringmyParamter){}如果我将事物设置为可为空,那么为什么我会在方法名称下方看到一条红线并显示此错误消息计算器answer很简单,使返回类型