예제 #1
0
        public void ValidateUrls(object item, IBaseUrlProvider baseUrlProvider)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (baseUrlProvider == null)
            {
                throw new ArgumentNullException("baseUrlProvider");
            }
            UrlPropertyModel propertyModel = GetPropertyModel(item.GetType());

            foreach (PropertyInfo urlProperty in propertyModel.UrlProperties)
            {
                CheckForRelativeUrls(item, urlProperty, baseUrlProvider);
            }
            foreach (PropertyInfo classProperty in propertyModel.ClassProperties)
            {
                object value = classProperty.GetValue(item, null);
                if (value == null)
                {
                    continue;
                }
                ValidateUrls(value, baseUrlProvider);
            }
            foreach (PropertyInfo enumerableProperty in propertyModel.EnumerableProperties)
            {
                IEnumerable enumerable = enumerableProperty.GetValue(item, null) as IEnumerable;
                if (enumerable == null)
                {
                    continue;
                }
                foreach (object obj in enumerable)
                {
                    ValidateUrls(obj, baseUrlProvider);
                }
            }
        }
예제 #2
0
        public virtual UrlPropertyModel GetPropertyModel(Type type)
        {
            UrlPropertyModel urlPropertyModel = new UrlPropertyModel();

            PropertyInfo[] properties = type.GetProperties();
            for (int i = 0; i < (int)properties.Length; i++)
            {
                PropertyInfo propertyInfo = properties[i];
                if (propertyInfo.GetCustomAttributes(typeof(UrlAttribute), true).Any <object>() && propertyInfo.PropertyType == typeof(string) && propertyInfo.CanRead && propertyInfo.CanWrite)
                {
                    urlPropertyModel.UrlProperties.Add(propertyInfo);
                }
                else if (typeof(IEnumerable).IsAssignableFrom(propertyInfo.PropertyType) && propertyInfo.CanRead)
                {
                    urlPropertyModel.EnumerableProperties.Add(propertyInfo);
                }
                else if (propertyInfo.PropertyType.GetTypeInfo().IsClass&& propertyInfo.PropertyType != typeof(string) && propertyInfo.CanRead)
                {
                    urlPropertyModel.ClassProperties.Add(propertyInfo);
                }
            }
            return(urlPropertyModel);
        }