static JsonDatabase() { _PlayerFields = new Dictionary <String, System.Reflection.PropertyInfo>(); _ItemFields = new Dictionary <String, System.Reflection.PropertyInfo>(); foreach (System.Reflection.PropertyInfo prop in typeof(DBPlayer).GetProperties().Where(p => p.CanWrite && p.CanRead)) { System.ComponentModel.BrowsableAttribute browsableAttribute = (System.ComponentModel.BrowsableAttribute)prop.GetCustomAttributes(typeof(System.ComponentModel.BrowsableAttribute), true).FirstOrDefault(); if (browsableAttribute != null && !browsableAttribute.Browsable) { continue; } String keyName = prop.Name; System.ComponentModel.DisplayNameAttribute displayNameAttribute = (System.ComponentModel.DisplayNameAttribute)prop.GetCustomAttributes(typeof(System.ComponentModel.DisplayNameAttribute), true).FirstOrDefault(); if (displayNameAttribute != null && !String.IsNullOrEmpty(displayNameAttribute.DisplayName)) { keyName = displayNameAttribute.DisplayName; } _PlayerFields[keyName] = prop; } foreach (System.Reflection.PropertyInfo prop in typeof(DBItem).GetProperties().Where(p => p.CanWrite && p.CanRead)) { System.ComponentModel.BrowsableAttribute browsableAttribute = (System.ComponentModel.BrowsableAttribute)prop.GetCustomAttributes(typeof(System.ComponentModel.BrowsableAttribute), true).FirstOrDefault(); if (browsableAttribute != null && !browsableAttribute.Browsable) { continue; } String keyName = prop.Name; System.ComponentModel.DisplayNameAttribute displayNameAttribute = (System.ComponentModel.DisplayNameAttribute)prop.GetCustomAttributes(typeof(System.ComponentModel.DisplayNameAttribute), true).FirstOrDefault(); if (displayNameAttribute != null && !String.IsNullOrEmpty(displayNameAttribute.DisplayName)) { keyName = displayNameAttribute.DisplayName; } _ItemFields[keyName] = prop; } }
/// <summary> /// Return true if any of the following conditions is satisfied: /// 1. Property is Delegate / Event /// 2. Can not read or write /// 3. Marked with XmlIgnore /// </summary> private bool IsSkipped(PropertyInfo pi, Type tp) { if (TypeInterrogator.IsDelegateType(tp) || TypeInterrogator.IsEventType(tp)) { return(true); } if (!pi.CanRead || !pi.CanWrite) // skip readonly properties. may revisit this { return(true); } System.ComponentModel.BrowsableAttribute brw = AttributeInterrogator.GetAttribute <System.ComponentModel.BrowsableAttribute>(pi); if (brw != null && !brw.Browsable) { return(true); } return(false); }