【发布时间】:2011-09-16 20:26:04
【问题描述】:
当方法重载时,从类方法和接口方法获取属性值的最佳方法是什么?
例如,我想知道在下面的示例中,具有一个参数的 Get 方法具有两个属性,值为 5 和“any”,而另一种方法具有值为 7 和“private”的属性。
public class ScopeAttribute : System.Attribute
{
public string Allowed { get; set; }
}
public class SizeAttribute : System.Attribute
{
public int Max { get; set; }
}
public interface Interface1
{
[SizeAttribute( Max = 5 )]
string Get( string name );
[SizeAttribute( Max = 7 )]
string Get( string name, string area );
}
public class Class1 : Interface1
{
[ScopeAttribute( Allowed = "any" )]
public string Get( string name )
{
return string.Empty;
}
[ScopeAttribute( Allowed = "private" )]
public string Get( string name, string area )
{
return string.Empty;
}
}
【问题讨论】:
标签: c# reflection custom-attributes