2010-09-22 2 views

Répondre

3

Vous pouvez utiliser un custom attribute:

public class FooAttribute : Attribute 
{ 
    public string Description { get; set; } 
} 

public class Bar 
{ 
    [Foo(Description = "Some description")] 
    public string BarProperty { get; set; } 
} 

public class Program 
{ 
    static void Main(string[] args) 
    { 
     var foos = (FooAttribute[])typeof(Bar) 
      .GetProperty("BarProperty") 
      .GetCustomAttributes(typeof(FooAttribute), true); 
     Console.WriteLine(foos[0].Description); 
    } 
} 
1

Il existe déjà un attribut pour elle:

System.ComponentModel.DescriptionAttribute 

bien que vous pouvez faire le vôtre si vous voulez.

Questions connexes