简体   繁体   English

在运行时添加或消除属性

[英]Adding or eliminating attribute at run time

I have a class with a bunch of properties. 我有一类带有很多属性的类。 Now I am going to add or eliminate some attributes to these properties at run time but i don't know how exactly i should do it. 现在,我将在运行时向这些属性添加或消除一些属性,但是我不知道该怎么做。

The Class 班级

Class myClass
{
    //Other codes
    public string DetailedAccountTitle
    {
        get { return detailedAccountTitle; }
        set { detailedAccountTitle = value; }
    }
    //Other codes
} 

Inside the caller 来电者内部

if ((bool)e.Value)
{
    //Add the attribute
}
else
{
    //Eliminate it
}

Now as you can see I am controlling an event inside the caller and i hope it adds the attribute if it gets true and eliminate it if it does not. 现在,您可以看到我正在控制调用者内部的事件,并且希望它在属性为true时添加该属性,而在属性为true时消除该属性。

I hope I understand your question correctly when you want to use attribute value set value when needed and when don't simply set to empty or null 我希望当您想在需要时使用属性值设置值时以及在不将其简单地设置为空或null时正确理解您的问题

myClass myclass = new myClass();

if ((bool)e.Value)
{
    myclass.DetailedAccountTitle = "Set Value";
}
else
{
    myclass.DetailedAccountTitle = String.Empty;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM