Exemple #1
0
            public ReadOnlyCollection <IPropertyBase> GetAllProperties(bool includeInheritance)
            {
                if (!includeInheritance)
                {
                    return(base.GetAllProperties(false));
                }

                var inheritanceTree = InheritanceTreeCache.Get(this);
                var distinctByName  = new IdentityProjectionEqualityComparer
                                      <IPropertyBase, string>(property => property.Name);
                var inheritanceList =
                    inheritanceTree.GetFlatList(InheritanceListMode.WholeTree).Select(node => node.Interface);
                var result = (from item in inheritanceList
                              select item.AllProperties).SelectMany(list => list).Distinct(distinctByName);

                return(new ReadOnlyCollection <IPropertyBase>(result.ToList()));
            }
Exemple #2
0
    public string[] InheritanceList(IPersistentType persistentType)
    {
        List <string> result = null;

        if (persistentType is ITypedEntitySet)
        {
            ITypedEntitySet typedEntitySet = (ITypedEntitySet)persistentType;
            result = new List <string> {
                BuildXtensiveType(OrmType.EntitySet, EscapeNameWithNamespace(typedEntitySet.ItemType, persistentType))
            };
            return(result.ToArray());
        }

        IInterface      @interface            = persistentType as IInterface;
        string          entityBaseBaseTypeStr = null;
        InheritanceTree inheritanceTree       = null;

        if (@interface != null)
        {
            inheritanceTree = InheritanceTreeCache.Get(@interface);
            if (!inheritanceTree.TreeRebuilded)
            {
                inheritanceTree.RebuildTree(false);
            }

            IInterface entityBaseBaseType = null;
            if (@interface is IEntityBase)
            {
                IEntityBase entityBase = (IEntityBase)@interface;
                entityBaseBaseType    = entityBase.BaseType;
                entityBaseBaseTypeStr = entityBase.BaseType == null
                                            ? null
                                            : EscapeNameWithNamespace(entityBase.BaseType, persistentType);
            }

            ReadOnlyCollection <InheritanceNode> flatList           = inheritanceTree.GetFlatList(InheritanceListMode.CurrentLevel);
            IEnumerable <IInterface>             allInheritanceList = flatList.Select(node => node.Interface).Where(item => item != entityBaseBaseType);

            result = allInheritanceList.Select(item => EscapeNameWithNamespace(item, persistentType)).ToList();
        }

        string commonBaseType = persistentType.TypeKind == PersistentTypeKind.Structure
                                    ? BuildXtensiveType(OrmType.Structure)
                                    : BuildXtensiveType(OrmType.Entity);

        bool noInheritance = (result == null || result.Count == 0 && persistentType.TypeKind != PersistentTypeKind.Interface) && string.IsNullOrEmpty(entityBaseBaseTypeStr);

        if (noInheritance)
        {
            result = new List <string>();
            if (!this.ActiveDTOStage)
            {
                result.Add(commonBaseType);
            }
        }
        else
        {
            if (persistentType.TypeKind.In(PersistentTypeKind.Entity, PersistentTypeKind.Structure))
            {
                if (@interface.InheritingByInterfaces.Count == 0 && string.IsNullOrEmpty(entityBaseBaseTypeStr) && !this.ActiveDTOStage)
                {
                    result.Insert(0, commonBaseType);
                }
            }
            else if (persistentType.TypeKind == PersistentTypeKind.Interface)
            {
                bool inheritesCommonIEntity = @interface.InheritsIEntity == InheritsIEntityMode.AlwaysInherit;
                if (!inheritesCommonIEntity)
                {
                    inheritesCommonIEntity = @interface.InheritedInterfaces.Count == 0;
                }

                if (inheritesCommonIEntity && !this.ActiveDTOStage)
                {
                    string commonIEntityType = BuildXtensiveType(OrmType.IEntity);
                    result.Insert(0, commonIEntityType);
                }
            }
        }

        if (!string.IsNullOrEmpty(entityBaseBaseTypeStr))
        {
            result.Insert(0, entityBaseBaseTypeStr);
        }

        return(result.ToArray());
    }