草庐IT

Property_value

全部标签

c# - Newtonsoft.Json.JsonSerializationException(从“System.Data.SqlTypes.SqlDouble”上的 'Value' 获取值时出错)序列化 SqlGeography

我尝试在数据库SQLServer2012中使用Newtonsoft.Json版本“Newtonsoft.Json.10.0.3”将DataTable对象序列化为Json。该表有一个类型为“geography”的列,其中包含类型为SqlGeography的实例.用于生成json的代码:publicstringSerializeToJson(){varconnstring1="DataSource=server1;InitialCatalog=database1;user=xxx;password=yyy";varsql="SELECT*FROMtable_1";//table_1hasa

c# - 通用约束 : Can I test Equality of generic that can be a reference or value type?

我想要一个通用类,它可以接受引用类型或值类型,并且只执行基于相等性测试的操作。考虑以下几点:publicclassPropertywhereTProp:struct,IEquatable{publicTPropValue;publicvoidSetValue(ObservableObjectowner,TPropvalue){if(!Value.Equals(value))//cannotuse!=onstructconstrainedTProp{//...settheproperty}}}publicclassByRefPropertywhereTProp:class//Dontwa

c# - .Net 4 : How to reference a dynamic object with property named "return"

我正在从公共(public)api检索json并使用JsonFx将其转换为动态对象。JsonFx.Json.JsonReaderreader=newJsonFx.Json.JsonReader();dynamicresponse=reader.Read(jsonAsString);json包含一个名为return的属性。例如{"result":"success","return":{"high":{"value":"3.85001","value_int":"385001","display":"3.85001\u00a0\u20ac","currency":"EUR"}}JsonFx

c# - EF lambda : The Include path expression must refer to a navigation property

这个问题在这里已经有了答案:EF:Includewithwhereclause[duplicate](5个答案)关闭5年前。这是我的表达:Coursecourse=db.Courses.Include(i=>i.Modules.Where(m=>m.IsDeleted==false).Select(s=>s.Chapters.Where(c=>c.IsDeleted==false))).Include(i=>i.Lab).Single(x=>x.Id==id);我知道原因是模块部分的Where(m=>m.IsDeleted==false),但为什么会导致错误?更重要的是,我该如何修复它

c# - 将导致 "A potentially dangerous Request.Form value was detected..."错误的输入值列表

我知道和>字符会导致此错误,但还有哪些其他字符/输入会导致此错误?我正在Global.asax中测试此错误,并重新定位到一个错误页面,我想在其中列出导致此错误的所有可能值,以便用户可以返回到他们的页面并删除它们。我已经进行了一些谷歌搜索,但目前我所看到的只有和>字符……肯定还有更多字符。 最佳答案 这是将导致错误的实际完整输入列表:请注意,尖括号本身的'有一个similarquestion有一个更完整的答案,包括一些代码,这是我从中得出列表的地方。当然你总是可以看here如果您担心的话,请继续阅读其余内容。

c# - 处理 DBNull.Value

我经常需要处理连接到网格控件的数据表,自定义更新似乎总是会产生大量与DBNull.Value相关的代码。我在这里看到了类似的问题,但认为一定有更好的答案:WhatisthebestwaytodealwithDBNull's我发现我倾向于将我的数据库更新封装在方法中,所以我最终得到如下代码,我将DBNull.value移动到可为null的类型,然后返回以进行更新:privatevoidUpdateRowEventHandler(objectsender,EventArgse){Boolean?requiresSupport=null;if(grdMainLevel1.GetFocused

c# - 为什么 Property 执行比 Field 或 Method 执行慢?

在CLRviaCSharp第10章“属性”JeffRichter写道:Apropertymethodcantakealongtimetoexecute;fieldaccessalwayscompletesimmediately.Acommonreasontousepropertiesistoperformthreadsynchroni-zation,whichcanstopthethreadforever,andtherefore,apropertyshouldnotbeusedifthreadsynchronizationisrequired.Inthatsituation,ameth

c# - MVC4 TDD - System.ArgumentNullException : Value cannot be null.

我是mvc4和TDD的新手。当我尝试运行这个测试时它失败了,我不知道为什么。我已经尝试了很多东西,我开始原地踏步。//GETapi/User/5[HttpGet]publicHttpResponseMessageGetUserById(intid){varuser=db.Users.Find(id);if(user==null){//returnRequest.CreateResponse(HttpStatusCode.NotFound);thrownewHttpResponseException(Request.CreateResponse(HttpStatusCode.NotFou

c# - MVC3 asp.net 错误 : Value cannot be null. 参数名称:下拉列表中的项目

在尝试发布数据时,我只在服务器中而不是在我的本地系统中得到转储。有一个页面向数据库提交了一些值。我还将页面中的下拉列表建模为强制性的。但是,当点击“创建”时,不会出现“丢失”之类的错误;它抛出一个垃圾场。转储跟踪:Valuecannotbenull.Parametername:itemsDescription:Anunhandledexceptionoccurredduringtheexecutionofthecurrentwebrequest.Pleasereviewthestacktraceformoreinformationabouttheerrorandwhereitorigi

C#6 : nameof() current property in getter/setter

有没有办法在getter/setter中获取当前属性的名称?像这样:publicstringMyProperty{get{returnbase.Get(nameof(ThisProperty));}set{base.Set(nameof(ThisProperty),value);}}nameof(ThisProperty)应该解析为“MyProperty”。 最佳答案 nameof无法做到这一点,但有更好的方法(自C#5起可用)。您可以使propertyName参数可选,并将CallerMemberName属性应用于它:protec