c#的Attribute有些类似java中的annotation,可以方便地在类成员中做修饰/限制作用. Demo: class ss { public stat BsonDocument Iterator(object obj){ MyAttr currAttr = null;// 自定义注解类 Type type = obj.GetType();// obj为传入的对象参数 //获取类名 String className = type.Name; //获取所有公有属性 PropertyInf
public class PP { public string a { get; set; } public string b { get; set; } public string c { get; set; } } class Program { static void Main(string[] args) { Hashtable ht = new Hashtable(); ht.Add("a", "utf8"); ht.Add("b",
装饰器+描述符 实现给一个类添加属性且对添加的时,对属性进行类型审核: def zsq(**kwargs): def fun(obj): for i,j in kwargs.items(): setattr(obj,i,mxf(i,j)) return obj return fun class mxf(): def __init__(self,na,ty): self.na = na self.ty = ty def __get__(self, instance, owner): return
部分参考自:http://www.geekfan.net/7862/ 新式类与经典类 2和3不一样,3都是新式类. 新式类和经典类的区别: class A: #classic class """this is class A""" pass __slots__=('x','y') def test(self): # classic class test """this is A.test()""&