Ejemplo n.º 1
0
        private void Build(IModelRoot modelRoot)
        {
            var inheritanceTrees = InheritanceTreeCache.Get(modelRoot.TopHierarchyTypes.ToArray());

            foreach (var tree in inheritanceTrees)
            {
                if (!tree.TreeRebuilded)
                {
                    tree.RebuildTree(true);
                }
            }
            var mergePaths = InheritanceTree.MergePaths(inheritanceTrees);
            var dependencyImplementationFlatList = InheritanceTree.GetDependencyImplementationFlatList(mergePaths);

            foreach (var @interface in dependencyImplementationFlatList)
            {
                IPropertiesBuilder propertiesBuilder = PropertiesBuilder.Build(@interface);
                lock (sync)
                {
                    propertiesBuilders.Add(@interface, propertiesBuilder);
                }
            }

            // process rest types (e.g. with no inheritance defined)
            foreach (var @interface in modelRoot.PersistentTypes.Except(dependencyImplementationFlatList))
            {
                IPropertiesBuilder propertiesBuilder = PropertiesBuilder.Build(@interface);
                lock (sync)
                {
                    propertiesBuilders.Add(@interface, propertiesBuilder);
                }
            }
        }
Ejemplo n.º 2
0
    public string[] CreateTypeAttributes(IPropertyBase property, IPropertiesBuilder propertiesBuilder)
    {
        if (this.ActiveDTOStage)
        {
            return(new string[0]);
        }

        IEnumerable <IOrmAttribute> typeAttributes = null;

        if (propertiesBuilder != null)
        {
            typeAttributes = propertiesBuilder.GetPropertyTypeAttributes(property);

            property = propertiesBuilder.GetProperty(property, InheritanceMember.Inherited);
        }

        if (typeAttributes == null)
        {
            typeAttributes = property.TypeAttributes;
        }

        ITypeAttributesBuilder attributesBuilder = TypeAttributesBuilder.Create(property, typeAttributes);

        return(CreateTypeAttributes(attributesBuilder, typeAttributes));
    }
Ejemplo n.º 3
0
    public string[] CreateTypeAttributes(IPersistentType persistentType, IPropertiesBuilder propertiesBuilder)
    {
        if (this.ActiveDTOStage)
        {
            return(new string[0]);
        }

        IEnumerable <IOrmAttribute> typeAttributes = null;

        if (propertiesBuilder != null)
        {
            typeAttributes = propertiesBuilder.MergedTypeAttributes;
        }

        if (typeAttributes == null)
        {
            typeAttributes = persistentType.TypeAttributes;
        }

        ITypeAttributesBuilder attributesBuilder = TypeAttributesBuilder.Create(persistentType, typeAttributes);

        string[] extraAttributes = persistentType.TypeKind == PersistentTypeKind.Interface ? new string[0] : new string[] { ATTRIBUTE_SERIALIZABLE };

        return(CreateTypeAttributes(attributesBuilder, typeAttributes.ToArray()).Concat(extraAttributes).ToArray());
    }
Ejemplo n.º 4
0
    public string ForSetter(IPropertyBase property, IPropertiesBuilder propertiesBuilder)
    {
        string result = string.Empty;

        if (this.ActiveDTOStage)
        {
            return(result);
        }

        switch (property.PropertyKind)
        {
        case PropertyKind.Scalar:
        {
            IOrmAttribute[] typeAttributes = propertiesBuilder.GetPropertyTypeAttributes(property);
            OrmKeyAttribute keyAttribute   = (OrmKeyAttribute)typeAttributes.Single(item => item is OrmKeyAttribute);

            result = keyAttribute.Enabled ? VISIBILITY_PRIVATE : string.Empty;
            break;
        }

        case PropertyKind.Navigation:
        {
            IOrmAttribute[] typeAttributes = propertiesBuilder.GetPropertyTypeAttributes(property);
            OrmKeyAttribute keyAttribute   = (OrmKeyAttribute)typeAttributes.Single(item => item is OrmKeyAttribute);

            INavigationProperty navigationProperty = (INavigationProperty)property;
            if (navigationProperty.Multiplicity == MultiplicityKind.Many || keyAttribute.Enabled)
            {
                result = VISIBILITY_PRIVATE;
            }

            break;
        }
        }

        // only when result is not directly 'private' because of business rules we can adjust it from settings
        if (string.IsNullOrEmpty(result))
        {
            PropertyAccessModifier higherModifier = property.PropertyAccess.GetHigherModifier();

            if (property.PropertyAccess.Setter != PropertyAccessModifier.Public && property.PropertyAccess.Setter != higherModifier)
            {
                result = GetPropertyAccessModifierString(property.PropertyAccess.Setter);
            }
        }

        return(result);
    }
Ejemplo n.º 5
0
    public bool VisibleSetter(IPropertyBase property, IPropertiesBuilder propertiesBuilder)
    {
        if (this.ActiveDTOStage)
        {
            return(true);
        }

        string setter = ForSetter(property, propertiesBuilder);

        if (setter == VISIBILITY_PRIVATE && property.Owner.TypeKind == PersistentTypeKind.Interface)
        {
            return(false);
        }

        return(true);
    }
Ejemplo n.º 6
0
        public bool IsInheritedProperty(IPersistentType persistentType, IPropertyBase property)
        {
            IPropertiesBuilder propertiesBuilder = Get(persistentType);

            return(propertiesBuilder != null && propertiesBuilder.GetInheritedProperties().Contains(property));
        }