Exemplo n.º 1
0
        public static string GetPropertyValue(object value, PropertyInfo property, IniFileEntryAttribute attribute)
        {
            string convertedVal;

            if (property.PropertyType == typeof(float))
            {
                convertedVal = ((float)value).ToString("0.0#########", CultureInfo.GetCultureInfo(DEFAULT_CULTURE_CODE));
            }
            else if (property.PropertyType == typeof(bool) && attribute.InvertBoolean)
            {
                convertedVal = (!(bool)(value)).ToString(CultureInfo.GetCultureInfo(DEFAULT_CULTURE_CODE));
            }
            else
            {
                convertedVal = Convert.ToString(value, CultureInfo.GetCultureInfo(DEFAULT_CULTURE_CODE));
            }

            return(convertedVal);
        }
Exemplo n.º 2
0
        public static bool SetPropertyValue(string value, object obj, PropertyInfo property, IniFileEntryAttribute attribute)
        {
            if (property.PropertyType == typeof(bool))
            {
                bool boolValue;
                bool.TryParse(value, out boolValue);
                if (attribute.InvertBoolean)
                {
                    boolValue = !boolValue;
                }
                property.SetValue(obj, boolValue);
                return(true);
            }
            if (property.PropertyType == typeof(int))
            {
                int intValue;
                int.TryParse(value, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.GetCultureInfo(DEFAULT_CULTURE_CODE), out intValue);
                property.SetValue(obj, intValue);
                return(true);
            }
            if (property.PropertyType == typeof(float))
            {
                var tempValue = value.Replace("f", "");

                float floatValue;
                float.TryParse(tempValue, NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.GetCultureInfo(DEFAULT_CULTURE_CODE), out floatValue);
                property.SetValue(obj, floatValue);
                return(true);
            }
            if (property.PropertyType.IsSubclassOf(typeof(AggregateIniValue)))
            {
                var field = property.GetValue(obj) as AggregateIniValue;
                field?.InitializeFromINIValue(value);
                return(true);
            }

            return(false);
        }