Exemplo n.º 1
0
        public static Item FromLine(IDelimitedRow stats)
        {
            Item result = GetStatOfType(stats[_typePosition]);

            for (var i = 0; i < StatProperty.AllOrdered.Count; i++)
            {
                var statText = stats[i];
                if (string.IsNullOrEmpty(statText))
                {
                    continue;
                }

                //Get the property info for this position
                var propInfo = StatProperty.AllOrdered[i].PropertyInfo;

                //Get the property type
                var type = propInfo.PropertyType;
                //Cast to the underlying type for nullables
                if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    type = type.GetGenericArguments()[0];
                }

                //Set the property on the result
                propInfo.SetValue(result, Convert.ChangeType(statText, type), null);
            }
            return(result);
        }
Exemplo n.º 2
0
        public static Item FromLine(IDelimitedRow stats)
        {
            Item result = GetStatOfType(stats[_typePosition]);

            for (var i = 0; i < StatProperty.AllOrdered.Count; i++)
            {
                var statText = stats[i];
                if (string.IsNullOrEmpty(statText)) continue;

                //Get the property info for this position
                var propInfo = StatProperty.AllOrdered[i].PropertyInfo;

                //Get the property type
                var type = propInfo.PropertyType;
                //Cast to the underlying type for nullables
                if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
                    type = type.GetGenericArguments()[0];

                //Set the property on the result
                propInfo.SetValue(result, Convert.ChangeType(statText, type), null);
            }
            return result;
        }