static public void Dump ( this Type type, string[] blacklist = null, Data data = Data.NamesAndTypes, Members members = Members.FieldsAndProperties, ScopeModifiers scopeModifiers = ScopeModifiers.Instance, AccessModifiers accessModifiers = AccessModifiers.All ) { Dump(null, type, blacklist, data, members, scopeModifiers, accessModifiers); }
static public BindingFlags ToBindingFlags(this ScopeModifiers scopeModifiers) { BindingFlags flags = 0; if (scopeModifiers.HasFlag(ScopeModifiers.Instance)) { flags |= BindingFlags.Instance; } if (scopeModifiers.HasFlag(ScopeModifiers.Static)) { flags |= BindingFlags.Static; } return(flags); }
// Dump static public void Dump ( this object instance, Type type = null, string[] blacklist = null, Data data = Data.Values, Members members = Members.FieldsAndProperties, ScopeModifiers scopeModifiers = ScopeModifiers.Instance, AccessModifiers accessModifiers = AccessModifiers.All ) { // Cache if (type == null) { type = instance.GetType(); } BindingFlags bindingFlags = accessModifiers.ToBindingFlags() | scopeModifiers.ToBindingFlags(); StringBuilder builder = new StringBuilder(); // Fields if (members.HasFlag(Members.Fields)) { foreach (var fieldInfo in type.GetFields(bindingFlags)) { if (blacklist == null || !fieldInfo.Name.IsContainedIn(blacklist)) { if (data.HasFlag(Data.Names)) { builder.Append(fieldInfo.Name, "\t"); } if (data.HasFlag(Data.Types)) { builder.Append(fieldInfo.FieldType.Name, "\t"); } if (data.HasFlag(Data.Values)) { object value = fieldInfo.GetValue(instance); builder.Append((value != null ? value.ToString() : "null"), "\t"); } } } } // Properties if (members.HasFlag(Members.Properties)) { foreach (var propInfo in type.GetProperties(bindingFlags)) { if (blacklist == null || !propInfo.Name.IsContainedIn(blacklist)) { if (data.HasFlag(Data.Names)) { builder.Append(propInfo.Name, "\t"); } if (data.HasFlag(Data.Types)) { builder.Append(propInfo.PropertyType.Name, "\t"); } if (data.HasFlag(Data.Values)) { object value; try { value = propInfo.GetValue(instance); } catch { value = "[EXCEPTION]"; } builder.Append((value != null ? value.ToString() : "null"), "\t"); } } } } // Print Tools.Log(builder.ToString()); }