public static T ReadFromINi <T>(this ACBrIniSection section) where T : class { var ret = (T)Activator.CreateInstance(typeof(T)); section.ReadFromINi(typeof(T), ret); return(ret); }
public static void ReadFromINi(this ACBrIniSection section, Type tipo, object item) { if (!tipo.IsClass) { return; } foreach (var property in tipo.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (property.HasAttribute <IniIgnoreAttribute>()) { continue; } if (!(property.CanRead && property.CanWrite)) { continue; } if (!IniValueWrapper.CanWrapUnwrap(property.PropertyType)) { continue; } var keyName = property.HasAttribute <IniKeyAttribute>() ? property.GetAttribute <IniKeyAttribute>().Value : property.Name; if (!section.ContainsKey(keyName)) { continue; } var str = section[keyName]; if (string.IsNullOrWhiteSpace(str)) { continue; } var value = IniValueWrapper.UnWrap(property.PropertyType, str, null); property.SetValue(item, value, null); } }
public static void WriteToIni(this ACBrIniSection section, Type tipo, object obj) { if (!tipo.IsClass) { return; } foreach (var property in tipo.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)) { if (property.HasAttribute <IniIgnoreAttribute>()) { continue; } if (!(property.CanRead && property.CanWrite)) { continue; } if (!IniValueWrapper.CanWrapUnwrap(property.PropertyType)) { continue; } var value = property.GetValue(obj, null); if (value == null) { continue; } var str = IniValueWrapper.Wrap(property.PropertyType, value); var keyName = property.HasAttribute <IniKeyAttribute>() ? property.GetAttribute <IniKeyAttribute>().Value : property.Name; if (!string.IsNullOrEmpty(str)) { section.Add(keyName, str); } } }
public static void WriteToIni <T>(this ACBrIniSection section, T obj) where T : class { section.WriteToIni(typeof(T), obj); }
public static void ReadFromINi <T>(this ACBrIniSection section, T item) where T : class { section.ReadFromINi(typeof(T), item); }