In Xamarin PCL, I'm trying to get the System.Reflection.PropertyInfo of a class I've written so that I can access its properties by their string name to get/set, and Type.GetTypeInfo() is missing, as well as Type.GetProperties. But System.Reflection.PropertyInfo is a valid class. How can I obtain the property info of a class? Do I have to write a wrapper for each platform? (It shows up just fine in the Android/iOS projects).
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I have just run into this, pretty sure the answer is to use:
Type.GetRuntimeProperties
回答2:
It's an extension, so you need to put
using System.Reflection;
at the top. Then it's available:
TypeInfo typeInfo = this.GetType().GetTypeInfo();
foreach (PropertyInfo propInfo in typeInfo.DeclaredProperties)
回答3:
You can also try
using System.Reflection;
Type t = typeof(YOURTYPE);
var properties = t.GetTypeInfo().DeclaredProperties