做最好的自己~~

Be My Personal Best!

导航

一个特性的例子

代码
[global::System.AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
sealed class MyControlAttribute : Attribute
{
    
// See the attribute guidelines at 
    
//  http://go.microsoft.com/fwlink/?LinkId=85236
    readonly string positionalString;

    
// This is a positional argument
    public MyControlAttribute(string positionalString)
    {
        
this.positionalString = positionalString;

        
// TODO: Implement code here
        throw new NotImplementedException();
    }

    
public string PositionalString
    {
        
get { return positionalString; }
    }

    
// This is a named argument
    public int NamedInt { getset; }


    
public ControlTypes ControlName
    { 
getset; }


    
public MyControlAttribute()
    {
        
    }
}

public class MyClass
{
    [MyControl(ControlName 
= ControlTypes.TextBox)]
    
public string MyProperty
    { 
getset; }
}


public enum ControlTypes
{
    TextBox,
    DropDownList,
    Label,
}

 

posted on 2010-05-04 09:31  阿万  阅读(361)  评论(0编辑  收藏  举报