Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
 public void SetValue <TType>(string key, TType value)
 {
     Add(key, IniValueWrapper.Wrap <TType>(value));
 }