예제 #1
0
        public TType GetValue <TType>(string key, TType defaultValue = default)
        {
            if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
            {
                return(defaultValue);
            }

            TType ret;

            try
            {
                if (!ContainsKey(key))
                {
                    return(defaultValue);
                }

                ret = IniValueWrapper.UnWrap(this[key], defaultValue);
            }
            catch (Exception)
            {
                ret = defaultValue;
            }

            return(ret);
        }
예제 #2
0
파일: IniUtil.cs 프로젝트: atkins126/ACBr
        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);
            }
        }