yonan2236
yonan2236

Reputation: 13649

What's this part of code called?

What's the first line of the following code called?

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual IController Controller
{
    get { return controller; }
    set { controller = value; }
}

Upvotes: 2

Views: 623

Answers (2)

BoltClock
BoltClock

Reputation: 723739

It's called an attribute. Attributes are used to describe properties, methods, etc. They serve to provide metadata, among other things.

In this case, the DesignerSerializationVisibility.Hidden attribute means that the Controller property isn't visible to the design-time serializer.

Upvotes: 10

edgarmtze
edgarmtze

Reputation: 25048

Positional parameters are parameters of the constructor of the attribute. They are mandatory and a value must be passed every time the attribute is placed on any program entity. On the other hand Named parameters are actually optional and are not parameters of the attribute's constructor.

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false,
 Inherited = false)]
public class HelpAttribute : Attribute
{
    public HelpAttribute(String Description_in)
    {
        this.description = Description_in;
        this.verion = "No Version is defined for this class";
    }
    protected String description;
    public String Description
    {
        get 
        {
            return this.description;
        }
    }
    protected String version;
    public String Version
    {
        get 
        {
            return this.version;
        }
        //if we ever want our attribute user to set this property, 

        //we must specify set method for it 

        set 
        {
            this.verion = value;
        }
    }
}
[Help("This is Class1")]
public class Class1
{
}

[Help("This is Class2", Version = "1.0")]
public class Class2
{
}

[Help("This is Class3", Version = "2.0", 
 Description = "This is do-nothing class")]
public class Class3
{
}

more...

Upvotes: 1

Related Questions