Esempio n. 1
0
        public virtual UrlPropertyModel GetPropertyModel(Type type)
        {
            UrlPropertyModel result = new UrlPropertyModel();

            PropertyInfo[] propertyInfos = type.GetProperties();

            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                if (propertyInfo.GetCustomAttributes(typeof(UrlAttribute), true).Any() &&
                    propertyInfo.PropertyType == typeof(string) &&
                    propertyInfo.CanRead &&
                    propertyInfo.CanWrite)
                {
                    result.UrlProperties.Add(propertyInfo);
                }
                else if (typeof(IEnumerable).IsAssignableFrom(propertyInfo.PropertyType) && propertyInfo.CanRead)
                {
                    result.EnumerableProperties.Add(propertyInfo);
                }
                else if (propertyInfo.PropertyType.GetTypeInfo().IsClass&& propertyInfo.PropertyType != typeof(string) && propertyInfo.CanRead)
                {
                    result.ClassProperties.Add(propertyInfo);
                }
            }


            return(result);
        }
        public virtual UrlPropertyModel GetPropertyModel(Type type)
        {
            UrlPropertyModel result = new UrlPropertyModel();
            PropertyInfo[] propertyInfos = type.GetProperties();

            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                if (propertyInfo.GetCustomAttributes(typeof (UrlAttribute), true).Any() &&
                    propertyInfo.PropertyType == typeof(string) &&
                    propertyInfo.CanRead &&
                    propertyInfo.CanWrite)
                {
                    result.UrlProperties.Add(propertyInfo);
                }
                else if (typeof(IEnumerable).IsAssignableFrom(propertyInfo.PropertyType) && propertyInfo.CanRead)
                {
                    result.EnumerableProperties.Add(propertyInfo);

                }
                else if (propertyInfo.PropertyType.GetTypeInfo().IsClass && propertyInfo.PropertyType != typeof(string) && propertyInfo.CanRead)
                {
                    result.ClassProperties.Add(propertyInfo);
                }
            }

            return result;
        }
        public void ValidateUrls(object item, IBaseUrlProvider baseUrlProvider)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            if (baseUrlProvider == null)
            {
                throw new ArgumentNullException(nameof(baseUrlProvider));
            }


            UrlPropertyModel urlPropertyModel = GetPropertyModel(item.GetType());

            foreach (PropertyInfo urlProperty in urlPropertyModel.UrlProperties)
            {
                CheckForRelativeUrls(item, urlProperty, baseUrlProvider);
            }

            foreach (PropertyInfo classProperty in urlPropertyModel.ClassProperties)
            {
                object value = classProperty.GetValue(item, null);
                if (value != null)
                {
                    ValidateUrls(value, baseUrlProvider);
                }
            }

            foreach (PropertyInfo enumerableProperty in urlPropertyModel.EnumerableProperties)
            {
                IEnumerable value = enumerableProperty.GetValue(item, null) as IEnumerable;
                if (value != null)
                {
                    foreach (object obj in value)
                    {
                        ValidateUrls(obj, baseUrlProvider);
                    }
                }
            }
        }