开发者

reading properties in assembly via reflection

I have a self-generated code in one assembly which in some of the lines includes properties, I was wondering how can I retrieve开发者_如何学JAVA them? Especially when that class is a view object and does not contain any parameters so we can do it by data adapter and finding for example insert or update parameter. Thanks in advance


Getting properties of type:

Type someType = typeof(MyClass);
PropertyInfo[] properties = someType.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy );

Getting types:

Assembly someAssembly = typeof(MyClass).Assembly;
Type[] typesInSomeAssembly = someAssembly.GetTypes();

Getting and setting value from property info:

MyClass cls = new MyClass();
PropertyInfo propText = cls.GetType().GetProperty("Text");
object valueOfTextProperty = propText.GetValue(cls, null);
propText.SetValue(cls, "New text", null);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜