// Background: The function GetRuntimeFields gets constant fields only for the specified type, // not for its base types. So we have to walk recursively through base classes. // The docmentation says full trust for the immediate caller is required for property BaseClass. // TODO: Rewrite this stuff for medium trust. void CollectKeyDescriptors(Type type) { // Get fields of the specified type only. var fields = type.GetTypeInfo().DeclaredFields; foreach (FieldInfo field in fields) { var attributes = field.GetCustomAttributes(typeof(KeyInfoAttribute), false); foreach (var attribute in attributes) { KeyDescriptor descriptor = new KeyDescriptor((KeyInfoAttribute)attribute); descriptor.KeyValue = (string)field.GetValue(null); _keyDescriptors[descriptor.KeyValue] = descriptor; } } type = type.GetTypeInfo().BaseType; if (type != typeof(object) && type != typeof(PdfObject)) { CollectKeyDescriptors(type); } }
public DictionaryMeta(Type type) { FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); foreach (FieldInfo field in fields) { object[] attributes = field.GetCustomAttributes(typeof(KeyInfoAttribute), false); if (attributes.Length == 1) { KeyInfoAttribute attribute = (KeyInfoAttribute)attributes[0]; KeyDescriptor descriptor = new KeyDescriptor(attribute); descriptor.KeyValue = (string)field.GetValue(null); this.keyDescriptors[descriptor.KeyValue] = descriptor; } } }
// Background: The function GetRuntimeFields gets constant fields only for the specified type, // not for its base types. So we have to walk recursively through base classes. // The docmentation says full trust for the immediate caller is required for property BaseClass. // TODO: Rewrite this stuff for medium trust. void CollectKeyDescriptors(Type type) { // Get fields of the specified type only. var fields = type.GetTypeInfo().DeclaredFields; foreach (FieldInfo field in fields) { var attributes = field.GetCustomAttributes(typeof(KeyInfoAttribute), false); foreach (var attribute in attributes) { KeyDescriptor descriptor = new KeyDescriptor((KeyInfoAttribute)attribute); descriptor.KeyValue = (string)field.GetValue(null); _keyDescriptors[descriptor.KeyValue] = descriptor; } } type = type.GetTypeInfo().BaseType; if (type != typeof(object) && type != typeof(PdfObject)) CollectKeyDescriptors(type); }
public DictionaryMeta(Type type) { //#if (NETFX_CORE && DEBUG) || CORE // if (type == typeof(PdfPages.Keys)) // { // var x = typeof(PdfPages).GetRuntimeFields(); // var y = typeof(PdfPages).GetTypeInfo().DeclaredFields; // x.GetType(); // y.GetType(); // Debug-Break.Break(); // Test.It(); // } //#endif #if !NETFX_CORE && !UWP FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); foreach (FieldInfo field in fields) { object[] attributes = field.GetCustomAttributes(typeof(KeyInfoAttribute), false); if (attributes.Length == 1) { KeyInfoAttribute attribute = (KeyInfoAttribute)attributes[0]; KeyDescriptor descriptor = new KeyDescriptor(attribute); descriptor.KeyValue = (string)field.GetValue(null); _keyDescriptors[descriptor.KeyValue] = descriptor; } } #else // Rewritten for WinRT. CollectKeyDescriptors(type); //var fields = type.GetRuntimeFields(); // does not work //fields2.GetType(); //foreach (FieldInfo field in fields) //{ // var attributes = field.GetCustomAttributes(typeof(KeyInfoAttribute), false); // foreach (var attribute in attributes) // { // KeyDescriptor descriptor = new KeyDescriptor((KeyInfoAttribute)attribute); // descriptor.KeyValue = (string)field.GetValue(null); // _keyDescriptors[descriptor.KeyValue] = descriptor; // } //} #endif }