草庐IT

大有可为

全部标签

c# - 反射 - 检查所有可为空的属性是否有值

我必须遍历几个类中的所有属性并检查任何可为null的属性以查看它们是否具有值。如何将从propertyInfo.GetValue()返回的值转换为通用可为null的类型,以便检查HasValue属性?为简洁起见,代码被剪掉了:foreach(PropertyInfopropInfointhis.GetType().GetProperties()){if(){//Howdoicastthisproperlyinheretoallowmetodo:if(!((Nullable)propInfo.GetValue(this,null)).HasValue)//Morecodehere}}

c# - C# 中的可选/可为空的 OUT 参数

我有一个方法有多个覆盖。在一个更扩展的覆盖中,我想返回一个OUT参数,但不是在我的更简单的覆盖中。例如:publicboolIsPossible(stringparam1,intparam2)publicboolIsPossible(stringparam1,intparam2,outboolparam3)我目前实现这一目标的方式是这样的:publicboolIsPossible(stringparam1,intparam2){booltemp;returnIsPossible(param1,param2,outtemp);}有没有更好的方法来实现这一点?我可以(或者我应该)使用可为n

c# - C# 中的可选/可为空的 OUT 参数

我有一个方法有多个覆盖。在一个更扩展的覆盖中,我想返回一个OUT参数,但不是在我的更简单的覆盖中。例如:publicboolIsPossible(stringparam1,intparam2)publicboolIsPossible(stringparam1,intparam2,outboolparam3)我目前实现这一目标的方式是这样的:publicboolIsPossible(stringparam1,intparam2){booltemp;returnIsPossible(param1,param2,outtemp);}有没有更好的方法来实现这一点?我可以(或者我应该)使用可为n

c# - 属性构造函数或属性中的可为空的 int

所以我有一个自定义属性,我们称它为MyCustomAttribute,它有一个构造函数,如下所示:publicMyCustomAttribute(int?i){//Codegoeshere}并声明一个属性:publicint?DefaultProperty{get;set;}现在,如果我想使用该属性,我需要传入一个int或null,这正是我所期望的。但这会导致编译错误:[MyCustomAttribute(1,DefaultProperty=1)]publicint?MyProperty{get;set;}还有这个:[MyCustomAttribute(null,DefaultProp

c# - 属性构造函数或属性中的可为空的 int

所以我有一个自定义属性,我们称它为MyCustomAttribute,它有一个构造函数,如下所示:publicMyCustomAttribute(int?i){//Codegoeshere}并声明一个属性:publicint?DefaultProperty{get;set;}现在,如果我想使用该属性,我需要传入一个int或null,这正是我所期望的。但这会导致编译错误:[MyCustomAttribute(1,DefaultProperty=1)]publicint?MyProperty{get;set;}还有这个:[MyCustomAttribute(null,DefaultProp

c# - 在 Linq to SQL 中订购可为 null 的 DateTime

我已经开始将LinqtoSQL用于我正在进行的项目,并且在按DateTime字段排序时遇到了问题,但是由于DateTime允许空值,因此出现的空值小于实际日期。所以我非常希望有日期的排在最前面(无论哪种方式排序),然后所有没有设置日期的排在最前面。jobList=fromjuincontext.Job_Users_Assignedwhereju.UserID==user.IDselectju.Job;returnjobList.OrderByDescending(j=>j.EndDate); 最佳答案 这有点hack,但它似乎适用于

c# - 在 Linq to SQL 中订购可为 null 的 DateTime

我已经开始将LinqtoSQL用于我正在进行的项目,并且在按DateTime字段排序时遇到了问题,但是由于DateTime允许空值,因此出现的空值小于实际日期。所以我非常希望有日期的排在最前面(无论哪种方式排序),然后所有没有设置日期的排在最前面。jobList=fromjuincontext.Job_Users_Assignedwhereju.UserID==user.IDselectju.Job;returnjobList.OrderByDescending(j=>j.EndDate); 最佳答案 这有点hack,但它似乎适用于

c# - 比较可为空的 DateTime?

寻找比以下更好的方法来比较可为null的日期时间:有什么建议吗?//myobject.ExpireDatetimeisofDateTime?//if(!myobject.ExpireDateTime.IsNull()&&DateTime.Compare((DateTime)myobject.ExpireDateTime,DateTime.Now.ToUniversalTime())Edited:Sorryforconfusion...myobject.ExpireDatetimeisoftypeDateTime. 最佳答案 我不太清

c# - 比较可为空的 DateTime?

寻找比以下更好的方法来比较可为null的日期时间:有什么建议吗?//myobject.ExpireDatetimeisofDateTime?//if(!myobject.ExpireDateTime.IsNull()&&DateTime.Compare((DateTime)myobject.ExpireDateTime,DateTime.Now.ToUniversalTime())Edited:Sorryforconfusion...myobject.ExpireDatetimeisoftypeDateTime. 最佳答案 我不太清

c# - 可为空的 GUID

在我的数据库中,在其中一个表中有一个允许空值的GUID列。我有一个带有Guid的方法?在表中插入新数据行的参数。但是,当我说myNewRow.myGuidColumn=myGuid时,出现以下错误:“无法隐式转换类型‘System.Guid?’到'System.Guid'。” 最佳答案 ADO.NETAPI在处理可空值类型时存在一些问题(即它无法正常工作)。我们遇到了无穷无尽的问题,因此得出的结论是最好手动将值设置为null,例如myNewRow.myGuidColumn=myGuid==null?(object)DBNull.Va