如:public class Product
{
   public decimal Price{get;set;}
   public string Name{get;set;}
}
场景:
如果我是管理员用户,则可以访问到Price属性,如果是其他用户就屏蔽并禁止访问Price属性,如何做到呢?

解决方案 »

  1.   

    弄到权限这里而不是在属性这里打交道。实在要弄就弄个自定义属性。
    [attrib..]
    public class Product
    {
       public decimal Price{get;set;}
       public string Name{get;set;}
    }
    参考属性。http://topic.csdn.net/t/20040502/15/3028122.html
      

  2.   

    不是逻辑意义上的去禁止方式是这样哈,
    假如我是管理用户:
    Product p1 = Class1.GetProductById(2);
    decimal s1 = p1.Price;假如我是一般用户:
    Product p1 = Class1.GetProductById(2);
    decimal s1 = p1.Price;(当我企图访问p1的Price时候,就屏蔽掉这个属性,也就是说,对我来说,我这时候根本就看不到Product对象有Price这个属性)
      

  3.   

    我的意思也是用Attribute,但我从来没有用过这个,不知道怎么弄