Example #1
0
        public IList <ITypeInfo> GetParents(IType type, List <ITypeInfo> list = null)
        {
            IList <ITypeInfo> result;

            if (this.cacheParents.TryGetValue(type, out result))
            {
                list?.AddRange(result);
                return(result);
            }

            bool endPoint = list == null;

            if (endPoint)
            {
                activeTypes = new Stack <IType>();
                list        = new List <ITypeInfo>();
            }

            var typeDef = type.GetDefinition() ?? type;

            if (activeTypes.Contains(typeDef))
            {
                return(list);
            }

            activeTypes.Push(typeDef);

            var types        = type.GetAllBaseTypes();
            var thisTypelist = new List <ITypeInfo>();

            foreach (var t in types)
            {
                var bType = BridgeTypes.Get(t, true);

                if (bType?.TypeInfo != null && !bType.Type.Equals(typeDef))
                {
                    thisTypelist.Add(bType.TypeInfo);
                }

                if (t.TypeArguments.Count > 0)
                {
                    foreach (var typeArgument in t.TypeArguments)
                    {
                        bType = BridgeTypes.Get(typeArgument, true);
                        if (bType?.TypeInfo != null && !bType.Type.Equals(typeDef))
                        {
                            thisTypelist.Add(bType.TypeInfo);
                        }

                        this.GetParents(typeArgument, thisTypelist);
                    }
                }
            }
            list.AddRange(thisTypelist);
            activeTypes.Pop();
            list = list.Distinct().ToList();
            cacheParents[type] = list;

            return(list);
        }
Example #2
0
        private void CheckInterfacePeoperty(ITypeInfo type, DefaultResolvedProperty property)
        {
            if (!type.InstanceProperties.ContainsKey(property.Name))
            {
                foreach (IType baseClass in type.Type.GetAllBaseTypes())
                {
                    if (baseClass.Kind == TypeKind.Class)
                    {
                        BridgeType baseBridgeType = BridgeTypes.Get(baseClass);
                        ITypeInfo  baseTypeInfo   = baseBridgeType.TypeInfo;
                        if (baseTypeInfo != null)
                        {
                            if (baseTypeInfo.InstanceProperties.ContainsKey(property.Name))
                            {
                                var instanceConfig = baseTypeInfo.InstanceConfig;
                                int fieldIndex     = instanceConfig.Fields.FindIndex(i => i.Name == property.Name);
                                if (fieldIndex != -1)
                                {
                                    if (!instanceConfig.Properties.Exists(i => i.Name == property.Name))
                                    {
                                        TypeConfigItem item = instanceConfig.Fields[fieldIndex];
                                        instanceConfig.Properties.Add(item);
                                        instanceConfig.Fields.RemoveAt(fieldIndex);

                                        TypeDefinition     typeDefinition     = baseBridgeType.TypeDefinition;
                                        PropertyDefinition propertyDefinition = typeDefinition.Properties.First(i => i.Name == property.Name);
                                        Helpers.SetCacheOfAutoPropertyOfDefinition(propertyDefinition);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        public IList <ITypeInfo> GetParents(IType type, IList <ITypeInfo> list = null, bool includeSelf = false)
        {
            IList <ITypeInfo> result;

            if (this.cacheParents.TryGetValue(type, out result))
            {
                return(result);
            }

            if (list == null)
            {
                activeTypes = new Stack <IType>();
                list        = new List <ITypeInfo>();
            }

            var typeDef = type.GetDefinition() ?? type;

            if (activeTypes.Contains(typeDef))
            {
                return(list);
            }

            activeTypes.Push(typeDef);

            var types = type.GetAllBaseTypes();

            foreach (var t in types)
            {
                var bType = BridgeTypes.Get(t, true);

                if (bType != null && bType.TypeInfo != null && (includeSelf || bType.Type != typeDef))
                {
                    list.Add(bType.TypeInfo);
                }

                if (t.TypeArguments.Count > 0)
                {
                    foreach (var typeArgument in t.TypeArguments)
                    {
                        this.GetParents(typeArgument, list, true);
                    }
                }
            }

            activeTypes.Pop();
            list = includeSelf ? list : list.Distinct().ToList();
            if (!includeSelf)
            {
                cacheParents[type] = list;
            }

            return(list);
        }