protected StructuralProperty(StructuralProperty prop)
 {
     this.IsInherited  = true;
     this.Name         = prop.Name;
     this.NameOnServer = prop.NameOnServer;
     this.Custom       = prop.Custom;
     this.IsInherited  = prop.IsInherited;
     this.IsScalar     = prop.IsScalar;
     this.IsUnmapped   = prop.IsUnmapped;
     this._validators  = new ValidatorCollection(prop.Validators);
 }
        // called internally by property set logic
        internal IEnumerable <ValidationError> ValidateProperty(StructuralProperty prop, Object value)
        {
            IEnumerable <ValidationError> errors = null;
            var co = value as IComplexObject;

            if (co != null)
            {
                errors = co.ComplexAspect.Validate();
            }
            var vc         = new ValidationContext(this.StructuralObject, prop, value);
            var itemErrors = prop.Validators.Select(vr => ValidateCore(vr, vc)).Where(ve => ve != null);

            return(errors == null?itemErrors.ToList() : errors.Concat(itemErrors).ToList());
        }
        internal void CheckProperty(StructuralProperty prop, Object v1, Object v2, String name)
        {
            if (v1 == null && v2 == null)
            {
                return;
            }
            if (Object.Equals(v1, v2))
            {
                return;
            }
            var detail = String.Format("Client value: '{0}',  Server value: '{1}'",
                                       (v1 ?? "").ToString(), (v2 ?? "").ToString());

            MetadataStore.OnMetadataMismatch(prop.ParentType.Name, prop.Name, MetadataMismatchType.InconsistentCLRPropertyDefinition, detail);
        }
示例#4
0
        public EntityError Resolve(EntityManager em)
        {
            IsServerError = true;
            try {
                EntityType entityType = null;
                if (EntityTypeName != null)
                {
                    var stName = TypeNameInfo.FromClrTypeName(EntityTypeName).ToClient(em.MetadataStore).StructuralTypeName;
                    entityType = em.MetadataStore.GetEntityType(stName);
                    var ek = new EntityKey(entityType, KeyValues);
                    Entity = em.GetEntityByKey(ek);
                }


                if (entityType != null)
                {
                    if (PropertyName != null)
                    {
                        Property = entityType.Properties.FirstOrDefault(p => p.NameOnServer == PropertyName);
                        if (Property != null)
                        {
                            PropertyName = Property.Name;
                        }
                    }

                    var vc = new ValidationContext(this.Entity);
                    vc.Property = Property;
                    var veKey = (ErrorName ?? ErrorMessage) + (PropertyName ?? "");
                    var ve    = new ValidationError(null, vc, ErrorMessage, veKey);
                    ve.IsServerError = true;
                    this.Entity.EntityAspect.ValidationErrors.Add(ve);
                }
            } catch (Exception e) {
                ErrorMessage = (ErrorMessage ?? "") + ":  Unable to Resolve this error: " + e.Message;
            }
            return(this);
        }
 public T GetValue <T>(StructuralProperty prop)
 {
     return((T)GetRawValue(prop.Name));
 }
 public Object GetValue(StructuralProperty prop)
 {
     return(GetValue(prop.Name));
 }
        public IEnumerable <ValidationError> ValidateProperty(StructuralProperty prop)
        {
            var value = this.GetValue(prop);

            return(ValidateProperty(prop, value));
        }
 public ValidationContext(IStructuralObject so, StructuralProperty property, Object propertyValue)
     : this(so) {
     Property      = property;
     PropertyValue = propertyValue;
 }