Type.GetProperties() missing in Xamarin PCL

后端 未结 3 1181
难免孤独
难免孤独 2021-01-01 15:54

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.

相关标签:
3条回答
  • 2021-01-01 16:16

    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)
    
    0 讨论(0)
  • 2021-01-01 16:21

    You can also try

    using System.Reflection; 
    
    Type t = typeof(YOURTYPE);
    var properties = t.GetTypeInfo().DeclaredProperties
    
    0 讨论(0)
  • 2021-01-01 16:28

    I have just run into this, pretty sure the answer is to use:

    Type.GetRuntimeProperties
    
    0 讨论(0)
提交回复
热议问题