• 一个特性的例子


    代码
    [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,
    }
  • 相关阅读:
    HDU ACM 1020 Encoding
    HDU ACM 1019 Least Common Multiple
    HDU ACM 1009 FatMouse' Trade
    HDU ACM 1032 The 3n + 1 problem
    HD ACM 1061 Rightmost Digit
    UVa 401 Palindromes
    UVa 489 Hangman Judge
    HDU ACM 1071 The area
    5/25
    受涼6/8
  • 原文地址:https://www.cnblogs.com/wantingqiang/p/1726959.html
Copyright © 2020-2023  润新知