小编Phi*_*son的帖子

从接口方法和类方法中获取属性

什么是在方法重载时从类方法和接口方法获取属性值的最佳方法?

例如,我想知道在下面的示例中,带有一个参数的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 …
Run Code Online (Sandbox Code Playgroud)

c# reflection custom-attributes

10
推荐指数
2
解决办法
6770
查看次数

标签 统计

c# ×1

custom-attributes ×1

reflection ×1