Ejemplo n.º 1
0
        private void SetModelPropertiesValues <TModel>(string contents, TModel modelInstance)
        {
            Type modelType = modelInstance.GetType();

            PropertyInfo[] modelProperties = modelType.GetProperties();

            string pattern;

            foreach (PropertyInfo propertyInfo in modelProperties)
            {
                if ((pattern = propertyInfo.GetPropertyPattern()) == null)
                {
                    continue;
                }

                switch (propertyInfo.PropertyType)
                {
                case var type when type == typeof(string):
                    propertyInfo.SetValue(modelInstance, RegexParseHelper.GetSingleMatchString(contents, pattern));
                    break;

                case var type when type == typeof(int):
                    propertyInfo.SetValue(modelInstance, RegexParseHelper.GetSingleMatchInt(contents, pattern));
                    break;

                default:
                    throw new ArgumentException($"Type {propertyInfo.PropertyType.Name} of the value {propertyInfo.Name} is not supported. " +
                                                "See the list of supported types of properties for more information.");
                }
            }
        }
Ejemplo n.º 2
0
        protected override object GetPropertyValue(Type type, string itemContents, string pattern)
        {
            switch (type)
            {
            case var t when type == typeof(string):
                return(RegexParseHelper.GetSingleMatchString(itemContents, pattern));

            case var t when type == typeof(int):
                return(RegexParseHelper.GetSingleMatchInt(itemContents, pattern));

            default:
                throw new ArgumentException($"Type {type.Name} is not supported. " +
                                            "See the list of supported types of properties for more information.");
            }
        }