Example #1
0
        public virtual object Clone()
        {
            var result = MemberwiseClone() as Property;

            if (Attributes != null)
            {
                result.Attributes = Attributes.Select(x => x.Clone()).OfType <PropertyAttribute>().ToList();
            }
            if (DictionaryValues != null)
            {
                result.DictionaryValues = DictionaryValues.Select(x => x.Clone()).OfType <PropertyDictionaryValue>().ToList();
            }
            if (DisplayNames != null)
            {
                result.DisplayNames = DisplayNames.Select(x => x.Clone()).OfType <PropertyDisplayName>().ToList();
            }
            if (ValidationRules != null)
            {
                result.ValidationRules = ValidationRules.Select(x => x.Clone()).OfType <PropertyValidationRule>().ToList();
            }
            if (Values != null)
            {
                result.Values = Values.Select(x => x.Clone()).OfType <PropertyValue>().ToList();
            }
            return(result);
        }
Example #2
0
        public virtual Property ToModel(Property property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            property.Id           = Id;
            property.CreatedBy    = CreatedBy;
            property.CreatedDate  = CreatedDate;
            property.ModifiedBy   = ModifiedBy;
            property.ModifiedDate = ModifiedDate;

            property.CatalogId  = CatalogId;
            property.CategoryId = CategoryId;


            property.Name          = Name;
            property.Required      = IsRequired;
            property.Multivalue    = IsMultiValue;
            property.Multilanguage = IsLocaleDependant;
            property.Dictionary    = IsEnum;
            property.ValueType     = (PropertyValueType)PropertyValueType;
            property.Type          = EnumUtility.SafeParse(TargetType, PropertyType.Catalog);

            property.DictionaryValues = DictionaryValues.Select(x => x.ToModel(AbstractTypeFactory <PropertyDictionaryValue> .TryCreateInstance())).ToList();
            property.Attributes       = PropertyAttributes.Select(x => x.ToModel(AbstractTypeFactory <PropertyAttribute> .TryCreateInstance())).ToList();
            property.DisplayNames     = DisplayNames.Select(x => x.ToModel(AbstractTypeFactory <PropertyDisplayName> .TryCreateInstance())).ToList();
            property.ValidationRules  = ValidationRules.Select(x => x.ToModel(AbstractTypeFactory <PropertyValidationRule> .TryCreateInstance())).ToList();
            foreach (var rule in property.ValidationRules)
            {
                rule.Property = property;
            }

            return(property);
        }