草庐IT

Property

全部标签

C# 验证 : IDataErrorInfo without hard-coded strings of property name?

实现IDataErrorInfo的最佳做法是什么?无论如何都可以在没有属性名称硬编码字符串的情况下实现它? 最佳答案 通用验证例程的基类您可以使用DataAnnotations如果您在IDataErrorInfo实现中做了一些futzing。例如,这是我经常使用的基本View模型(来自Windows窗体,但您可以推断):publicclassViewModelBase:IDataErrorInfo,INotifyPropertyChanged{publiceventPropertyChangedEventHandlerPropert

c# - OData 和 WebAPI : Navigation property not present on model

我正在尝试使用EntityFramework、WebAPI、OData和Angular客户端组合一个简单的玩具项目。一切正常,除了我在其中一个模型上放置的导航属性似乎不起作用。当我使用$expand调用我的API时,返回的实体没有它们的导航属性。我的类是Dog和Owner,看起来像这样:publicclassDog{//Properties[Key]publicGuidId{get;set;}publicStringName{get;set;}[Required]publicDogBreedBreed{get;set;}publicintAge{get;set;}publicintWe

c# - Json:如何使用 json.net 正确去除转义字符

我有以下格式的json响应。"[{\\\"JobID\\\":\\\"1\\\",\\\"BillGenerationDate\\\":\\\"4/29/20132:53:34PM\\\",\\\"BillID\\\":\\\"115743\\\",\\\"BillNo\\\":\\\"115743\\\",\\\"CustomerID\\\":\\\"4041705\\\",\\\"PayStatus\\\":\\\"0\\\",\\\"PaymentRequiredStatus\\\":\\\"True\\\",\\\"ProductName\\\":\\\"EpicFBOtest

c# - 阻止访问私有(private)成员变量?强制使用公共(public)属性(property)?

我使用的是.NET2.0,因此无法访问自动属性。所以我必须求助于以下编码私有(private)变量和公共(public)属性的方法privatestringm_hello=null;publicstringHello{get{returnm_hello;}set{m_hello=value;}}对于上述private/public成员的包含类的方法,是否有限制访问private变量的方法?我不喜欢我可以使用m_hello或Hello。谢谢。 最佳答案 正如其他人所建议的那样,这应该是一个答案...当面向.NET2.0时,您仍然可以在

c# - 验证错误 : The value 'on' is not valid for <<property name>>

在我的项目中,我有一个模型,您可以在这里看到我模型的一部分:publicclassCheckoutModel{publicboolOtherPlace{get;set;}[RequiredIf("OtherPlace",true,ErrorMessage="")]publicstringOtherPlaceFullName{get;set;}[RequiredIf("OtherPlace",true,ErrorMessage="")]publicintOtherPlaceProvinceId{get;set;}[RequiredIf("OtherPlace",true,ErrorMes

c# - 通过反射设置属性 Nullable<>

我尝试动态设置一个Nullable属性。我得到我的属性(property)ex:PropertyInfoproperty=class.GetProperty("PropertyName");//MypropertyisNullableatthistimeSothetypecouldbeastringorint我想像这样通过反射来设置我的属性property.SetValue(class,"1256",null);当我的属性是NullableGeneric时它不起作用。所以我试图找到一种方法来设置我的属性。了解我执行的可空属性的类型Nullable.GetUnderlyingType(p

c# - C# 中的接口(interface)与多重继承

我有一组A类和B类都有一些属性。和另一个具有自己属性的C类。每当我创建类C的实例时,我想使用objClassC访问所有三个类的所有属性。我如何在C#中实现这一点?我面临两个问题:-我不能同时继承类C中的类A、B(C#不支持多重继承)如果我使用接口(interface)而不是类A、B(在接口(interface)中我们不能包含字段) 最佳答案 为什么不在C类中包含A类和B类的实例。使用CompositionclassC{//classCpropertiespublicAobjA{get;set;}publicBobjeB{get;se

c# - 执行非查询 : Connection property has not been initialized.

下午,所以我已经在这个问题上研究了几个小时,但无法真正克服最后一个障碍。下面是我正在编写的这个程序的代码:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Diagnostics;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Configuration;namespaceTest{classProgram{staticvoidMain(){EventLogalog=newEventLog();

c# - "Inspecting the state of an object in the debuggee of type System.Reflection.MethodBase is not supported in this context"

我不知道这个错误是什么意思。我使用的是VisualStudioforMac7.5.0社区版。我在带有ASP.NETCore的EntityFramework中使用延迟加载。publicpartialclassAdminUser{publicAdminUser(){RoleAssign=newHashSet();}publicGuidUserId{get;set;}publicstringFirstName{get;set;}publicstringLastName{get;set;}publicstringEmail{get;set;}publicstringUserName{get;s

c# - ASP.NET MVC3 中的 Razor 和接口(interface)继承 : why can't this property be found?

我在ASP.NETMVC3应用程序中的一个RazorView有一个奇怪的问题。当我将其值写入调试器控制台时,该属性似乎确实存在,但我收到一条错误消息,告诉我无法找到该属性。我的View将一个名为FormEditViewModel的类作为其模型。FormEditViewModel有一个IForm类型的属性,一个继承自另一个接口(interface)IFormObject的接口(interface)。IFormObject定义了一个属性Name,因此任何实现IForm的东西都必须实现一个名为Name的属性。具体类型Form实现接口(interface)IForm并根据需要定义Name属性。