public override List <string> Validate(object target, Service profile)
        {
            List <string> result = new List <string>();

            if (target == null || string.IsNullOrEmpty(target.ToString()))
            {
                return(result);
            }
            DDIValidateAttribute ddiattribute = base.GetDDIAttribute();

            if (ddiattribute == null)
            {
                throw new ArgumentException(string.Format("{0} is not a valid DDIAttribute", base.AttributeType));
            }
            List <string> list = ddiattribute.Validate(target, profile);

            if (list.Count <= 0)
            {
                return(new List <string>
                {
                    string.Format("{0} {1}", target, this.ErrorMessage)
                });
            }
            return(result);
        }
示例#2
0
        protected DDIValidateAttribute GetDDIAttribute()
        {
            DDIValidateAttribute result = null;

            if (this.AttributeType != null)
            {
                try
                {
                    result = (Activator.CreateInstance(this.AttributeType) as DDIValidateAttribute);
                }
                catch (ArgumentException)
                {
                }
                catch (NotSupportedException)
                {
                }
                catch (TargetInvocationException)
                {
                }
                catch (MethodAccessException)
                {
                }
                catch (MemberAccessException)
                {
                }
                catch (TypeLoadException)
                {
                }
            }
            return(result);
        }
示例#3
0
        public override List <string> Validate(object target, Service profile)
        {
            DDIValidateAttribute ddiattribute = base.GetDDIAttribute();

            if (ddiattribute == null)
            {
                throw new ArgumentException(string.Format("{0} is not a valid DDIAttribute", base.AttributeType));
            }
            List <string> list = new List <string>();

            if (target != null)
            {
                IEnumerable enumerable = target as IEnumerable;
                if (enumerable == null)
                {
                    throw new ArgumentException("DDICollectionDecoratorAttribute can only be applied to collection target");
                }
                IDDIValidationObjectConverter iddivalidationObjectConverter = null;
                if (this.ObjectConverter != null)
                {
                    iddivalidationObjectConverter = (Activator.CreateInstance(this.ObjectConverter) as IDDIValidationObjectConverter);
                }
                foreach (object obj in enumerable)
                {
                    if (this.ExpandInnerCollection && obj is IEnumerable)
                    {
                        using (IEnumerator enumerator2 = (obj as IEnumerable).GetEnumerator())
                        {
                            while (enumerator2.MoveNext())
                            {
                                object obj2    = enumerator2.Current;
                                object target2 = (iddivalidationObjectConverter == null) ? obj2 : iddivalidationObjectConverter.ConvertTo(obj2);
                                list.AddRange(ddiattribute.Validate(target2, profile));
                            }
                            continue;
                        }
                    }
                    object target3 = (iddivalidationObjectConverter == null) ? obj : iddivalidationObjectConverter.ConvertTo(obj);
                    list.AddRange(ddiattribute.Validate(target3, profile));
                }
            }
            return(list);
        }