Example #1
0
        private void InternalImplementToType(IEntityBase targetType, ImplementTypeOptions options)
        {
            EntityBase entityBase = (EntityBase)targetType;

            List <PropertyBase> addedProperties = new List <PropertyBase>();

            foreach (PropertyBase property in this.Properties)
            {
                if (!entityBase.ContainsProperty(property.PropertyKind, property.Name))
                {
                    PropertyBase copiedProperty =
                        (PropertyBase)property.Copy(new[] { PersistentTypeHasProperties.PersistentTypeDomainRoleId });
                    entityBase.Properties.Add(copiedProperty);
                    addedProperties.Add(copiedProperty);
                }
            }

            foreach (NavigationProperty navigationProperty in this.NavigationProperties)
            {
                if (!entityBase.ContainsProperty(PropertyKind.Navigation, navigationProperty.Name))
                {
                    NavigationProperty copiedNavigationProperty = (NavigationProperty)navigationProperty.Copy(new[]
                    {
                        PersistentTypeHasNavigationProperties.PersistentTypeOfNavigationPropertyDomainRoleId,
                    });
                    entityBase.NavigationProperties.Add(copiedNavigationProperty);
                    copiedNavigationProperty.PersistentTypeHasAssociations.SourcePersistentType = entityBase;
                    addedProperties.Add(copiedNavigationProperty);
                }
            }

            foreach (EntityIndex entityIndex in this.Indexes)
            {
                if (!entityBase.ContainsIndex(entityIndex))
                {
                    EntityIndex copiedIndex =
                        (EntityIndex)entityIndex.Copy(new[] { InterfaceHasIndexes.InterfaceOfIndexDomainRoleId });
                    entityBase.Indexes.Add(copiedIndex);
                }
            }

            if (Util.IsFlagSet(ImplementTypeOptions.CopyInheritedInterfaces, options))
            {
                foreach (Interface inheritedInterface in this.InheritedInterfaces)
                {
                    if (!entityBase.InheritedInterfaces.Contains(inheritedInterface))
                    {
                        entityBase.InheritedInterfaces.Add(inheritedInterface);
                    }
                }
            }

            if (!targetType.InheritedInterfaces.Contains(this))
            {
                entityBase.InheritedInterfaces.Add(this);
            }

            var duplicatedInfo = PersistentTypeValidation.FindDuplicatedPropertieInInheritanceTree(targetType, null);

            foreach (var addedProperty in addedProperties)
            {
                Func <IPropertyBase, bool> foundPropertyFunc =
                    item => item.PropertyKind == addedProperty.PropertyKind &&
                    Util.StringEqual(item.Name, addedProperty.Name, true);

                addedProperty.IsInherited =
                    duplicatedInfo.PropertiesWithDifferentType.Any(foundPropertyFunc) ||
                    duplicatedInfo.PropertiesWithSameType.Any(foundPropertyFunc);
            }
        }
Example #2
0
        private static void CustomWritePropertiesAsElements(SerializationContext context, PropertyBase element, XmlWriter writer)
        {
            if (!context.Result.Failed)
            {
                element.FieldAttribute.SerializeToXml(writer);
            }

            if (!context.Result.Failed)
            {
                element.Constraints.SerializeToXml(writer, "constraints");
            }

            if (!context.Result.Failed)
            {
                element.DataMember.SerializeToXml(writer, "dataMember");
            }

            if (!context.Result.Failed)
            {
                element.PropertyAccess.SerializeToXml(writer, "propertyAccess");
            }
        }
Example #3
0
        private static void CustomReadPropertiesFromElements(SerializationContext serializationContext, PropertyBase element, XmlReader reader)
        {
            while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
            {
                switch (reader.LocalName)
                {
                    case "field":	// field
                    {
                        if (reader.IsEmptyElement)
                        {	// No serialized value, must be default one.
                            SerializationUtilities.Skip(reader);  // Skip this tag.
                        }
                        else
                        {
                            OrmFieldAttribute fieldAttribute = new OrmFieldAttribute();
                            fieldAttribute.DeserializeFromXml(reader);
                            element.FieldAttribute = fieldAttribute;

                            SerializationUtilities.SkipToNextElement(reader);
                            reader.SkipToNextElementFix();
                        }
                        break;
                    }
                    case "constraints":	// field
                    {
                        if (reader.IsEmptyElement)
                        {	// No serialized value, must be default one.
                            SerializationUtilities.Skip(reader);  // Skip this tag.
                        }
                        else
                        {
                            OrmPropertyConstraints constraints = new OrmPropertyConstraints();
                            constraints.DeserializeFromXml(reader);
                            element.Constraints = constraints;

                            SerializationUtilities.SkipToNextElement(reader);
                            reader.SkipToNextElementFix();
                        }
                        break;
                    }
                    case "dataMember":	// field
                    {
                        if (reader.IsEmptyElement)
                        {	// No serialized value, must be default one.
                            SerializationUtilities.Skip(reader);  // Skip this tag.
                        }
                        else
                        {
                            DataMemberDescriptor dataMemberDescriptor = new DataMemberDescriptor();
                            dataMemberDescriptor.DeserializeFromXml(reader);
                            element.DataMember = dataMemberDescriptor;

                            SerializationUtilities.SkipToNextElement(reader);
                            reader.SkipToNextElementFix();
                        }
                        break;
                    }
                    case "propertyAccess":	// field
                    {
                        if (reader.IsEmptyElement)
                        {	// No serialized value, must be default one.
                            SerializationUtilities.Skip(reader);  // Skip this tag.
                        }
                        else
                        {
                            PropertyAccessModifiers modifiers = new PropertyAccessModifiers();
                            modifiers.DeserializeFromXml(reader, "propertyAccess");
                            element.PropertyAccess = modifiers;

                            SerializationUtilities.SkipToNextElement(reader);
                            reader.SkipToNextElementFix();
                        }
                        break;
                    }
                    default:
                        return;  // Don't know this element.
                }
            }
        }
Example #4
0
        private PropertyDescriptorCollection GetCustomProperties(Attribute[] attributes)
        {
            var attributeBuilder = this.CreateBuilder(attributes, base.GetProperties(attributes),
                                                      modelElement =>
            {
                PropertyBase navigationProperty = modelElement as PropertyBase;
                return(navigationProperty == null ? false : true);            //navigationProperty.IsInherited;
            });

//            PropertyKind? propertyKind = attributeBuilder.TestElement(element => (element is PropertyBase)
//                ? (element as PropertyBase).PropertyKind
//                : (PropertyKind?) null, null);

            PropertyBase property = attributeBuilder.TestElement(element => (element is PropertyBase)
                ? (element as PropertyBase)
                : null, null);

            PersistentTypeKind?ownerTypeKind = attributeBuilder.TestElement(element => (element is PropertyBase)
                ? (element as IPropertyBase).Owner.TypeKind
                : (PersistentTypeKind?)null, null);

            // ownerTypeKind.HasValue && ownerTypeKind.Value == PersistentTypeKind.Interface
            bool ownerIsInterface = ownerTypeKind.HasValue && ownerTypeKind.Value == PersistentTypeKind.Interface;

            if (property != null)
            {
                if (ownerIsInterface)
                {
                    //TODO: Uncomment in final!
                    attributeBuilder.ReplaceElementPropertyAtribute(PropertyBase.PropertyAccessDomainPropertyId,
                                                                    //descriptor => new ReadOnlyAttribute(true));
                                                                    descriptor => new BrowsableAttribute(false));
                }

                // set readonly(true) for scalar properties
                if (property.PropertyKind == PropertyKind.Scalar)
                {
                    if (property.IsInherited)
                    {
                        //TODO: Uncomment in final!
//                        attributeBuilder.ReplaceRolePlayerPropertyAtribute(ScalarPropertyHasType.DomainTypeDomainRoleId,
//                            descriptor => new BrowsableAttribute(false));
                        attributeBuilder.ReplaceElementPropertyAtribute(ScalarProperty.TypeDomainPropertyId,
                                                                        descriptor => new BrowsableAttribute(false));
                    }
                }

                // set readonly(true) for structure properties
                if (property.PropertyKind == PropertyKind.Structure)
                {
                    if (property.IsInherited)
                    {
                        attributeBuilder.ReplaceRolePlayerPropertyAtribute(
                            StructurePropertyHasType.StructureDomainRoleId,
                            descriptor => new BrowsableAttribute(false));
                    }
                }

                // set readonly(true) for navigation properties
                if (property.PropertyKind == PropertyKind.Navigation)
                {
                    if (property.IsInherited)
                    {
                        attributeBuilder.ReplaceRolePlayerPropertyAtribute(
                            NavigationPropertyHasAssociation.PersistentTypeHasAssociationsDomainRoleId,
                            descriptor => new BrowsableAttribute(false));
                    }
                }
            }
            return(attributeBuilder.Build());
        }