Tag: 属性

阻止VS将属性值放入.Designer.cs文件中

我有一个自定义控件,我已将其放在Visual Studio 2010中的表单和c#winforms上。 当我删除窗体上的控件时,属性将自动填充到From1.Designer.cs文件中。 我想阻止特定属性出现在文件中。 我已经将它标记为[Browsable(false)]但这还不足以阻止VS干扰我的财产。 是否有一个属性让VS忽略该属性?

为什么我的自动实现的属性在ASP.NET 2.0中工作?

我在ASP.NET Web应用程序的C#源文件中使用自动实现的属性语法: public int IdUser { get; set; } … this.IdUser = 1; 该项目的Target框架是.NET Framework 2.0 。 它编译并且似乎在仅安装了ASP.NET 2.0的IIS服务器上正常运行。 我使用Visual Studio 2010进行开发和编译。 我理解这个语法随.NET 3一起提供。 我在VS的某个地方错过了设置吗? 我是否可以在IIS / ASP.NET 2.0服务器上部署网站时遇到问题?

如何让XMLSerializer将命名空间添加到嵌套对象中的属性?

这就是我得到的: ipsum 这就是我想要的:(注意Type-attribute以ex为前缀) ipsum 这是我的代码: [XmlType(Namespace = “http://www.example.com/namespace”)] [XmlRoot(“ex”, Namespace = “http://www.example.com/namespace”)] public class TestSoapHeader : SoapHeader { private TestSoapHeaderTypeValuePair _a; public TestHeader() { MustUnderstand = true; } [XmlNamespaceDeclarations] public XmlSerializerNamespaces xmlsn { get { XmlSerializerNamespaces xsn = new XmlSerializerNamespaces(); xsn.Add(“ex”, “http://www.example.com/namespace”); return xsn; } set { } } public TestSoapHeaderTypeValuePair A { get { […]

将属性添加到现有类

我有一个私有类,我用它来实现某些属性。 因此,我没有能力修改实际的私有类,也不想使用inheritance来创建我自己的类来代替它。 有没有办法可以向该私有类添加属性? 谢谢!

自定义validation属性有多个实例问题

我在C#4中使用tha命名空间System.ComponentModel.DataAnnotations来实现我自己的validation属性,它看起来像这样 [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public sealed class MyCustomValidator : ValidationAttribute { private String Property1 { get; set; } private String Property2 { get; set; } public ValeTaxiSituacaoRequired(String property1, String property2) { Property1 = property1; Property2 = property2; } public override bool IsValid(object value) { //validation logic } } 我想使用这个属性如下 [MyCustomValidator(“Name”, “Job”)] [MyCustomValidator(“Name”, “Email”)] [MyCustomValidator(“Name”, […]

如何使用Roslyn检查属性是否使用自定义属性进行修饰?

我想使用Roslyn分析一个C#类,并打算在被访问属性应用了特定属性时执行某些操作。 我怎样才能在CSharpSyntaxWalker.VisitPropertyDeclaration方法覆盖中执行此操作? 例如,在下面的代码块中,我想知道Date属性是否具有Validation属性,如果是,则IsJDate是true还是false? [Validation(IsJDate=true)] public string Date {get; set;} 初始化: filesPath.ToList().ForEach(csFilePath => { SyntaxTree csSyntaxTree = CSharpSyntaxTree.ParseText(csFileSourceCode); // …. } _compiledCsCodes = CSharpCompilation.Create(“CSClassesAssembly”, csFiles.Select(cs => cs.CSSyntaxTree ), references); foreach (CsFile csFile in csFiles) { csFile.FileSemanticModel = _compiledCsCodes.GetSemanticModel(csFile.FullSyntaxTree); }

如何在部分类的另一半中定义的属性上使用属性?

我有一个自动生成的类来导入包含这样的(缩写)的Web服务: [System.Runtime.Serialization.DataMemberAttribute()] public System.DateTime StartDate { get { return this.StartDateField; } set { /* implementation prop changed */ } } 我想为这个成员添加一个MVC格式属性。 所以在另一个包含相同partial class定义的文件中,我想做类似以下的事情(这是非法的): [DisplayFormat(DataFormatString = “{0:dd-MM-yyyy}”, ApplyFormatInEditMode = true)] public DateTime StartDate; 部分方法在这里没有用,因为部分方法必须是私有的,具有void返回类型,必须是方法等等。 我该如何装饰这个会员?

可访问性错误C#不一致

我收到列表属性的错误。 它说这个列表比财产更容易访问..我不知道为什么我收到这个错误.. //List private List clientList = new List(); //Property public List ClientListAccessor { get { return clientList; } set { clientList = value; } } 在此先感谢您的帮助。

访问自动属性 ​​- c#

自动属性被添加到关于.net 3的语言中,无论如何,使用代码创建一个“私有”字段: public string foo {get;set;} 是否有可能实际获得对此私有字段的任何引用? 我想做点什么 public string foo {get{/*some code to check foo for nulls etc*/};set;} 不失去这个自动属性function并编写类似的东西 private string _foo = null; public string foo{get{_foo==null?_foo=”hello”; return _foo;}set{_foo=value;}}

ASP MVC:自定义validation属性

我正在尝试编写自己的自定义validation属性,但我遇到了一些问题。 我想写的属性是当用户登录时,密码将与确认密码进行比较。 namespace Data.Attributes { public class ComparePassword : ValidationAttribute { public string PasswordToCompareWith { get; set; } public override bool IsValid(object value) { if (PasswordToCompareWith == (string)value) { return true; } return false; } } 现在我的问题是当我试图在模型文件中设置这样的属性时: [Required] [ComparePassword(PasswordToCompareWith=ConfirmPassword)] public string Password { get; set; } [Required] public string ConfirmPassword { get; set; } } […]