Esempio n. 1
0
        /// <summary>
        /// Adds classes referenced by the class to the model
        /// </summary>
        /// <param name="classModel"></param>
        private void AddReferences(TsClass classModel, Dictionary <Type, TypeConvertor> typeConvertors)
        {
            foreach (var property in classModel.Properties.Where(model => !model.IsIgnored))
            {
                var propertyTypeFamily = TsType.GetTypeFamily(property.PropertyType.Type);
                if (propertyTypeFamily == TsTypeFamily.Collection)
                {
                    var collectionItemType = TsType.GetEnumerableType(property.PropertyType.Type);
                    while (collectionItemType != null)
                    {
                        var typeFamily = TsType.GetTypeFamily(collectionItemType);

                        switch (typeFamily)
                        {
                        case TsTypeFamily.Class:
                            this.Add(collectionItemType);
                            collectionItemType = null;
                            break;

                        case TsTypeFamily.Enum:
                            this.AddEnum(new TsEnum(collectionItemType));
                            collectionItemType = null;
                            break;

                        case TsTypeFamily.Collection:
                            var previousCollectionItemType = collectionItemType;
                            collectionItemType = TsType.GetEnumerableType(collectionItemType);
                            if (collectionItemType == previousCollectionItemType)
                            {
                                collectionItemType = null;
                            }
                            break;

                        default:
                            collectionItemType = null;
                            break;
                        }
                    }
                }
                else if (propertyTypeFamily == TsTypeFamily.Class)
                {
                    if (typeConvertors == null || !typeConvertors.ContainsKey(property.PropertyType.Type))
                    {
                        this.Add(property.PropertyType.Type);
                    }
                    else
                    {
                        this.Add(property.PropertyType.Type, false, typeConvertors);
                    }
                }
            }
            foreach (var genericArgument in classModel.GenericArguments)
            {
                var propertyTypeFamily = TsType.GetTypeFamily(genericArgument.Type);
                if (propertyTypeFamily == TsTypeFamily.Collection)
                {
                    var collectionItemType = TsType.GetEnumerableType(genericArgument.Type);
                    if (collectionItemType != null)
                    {
                        var typeFamily = TsType.GetTypeFamily(collectionItemType);

                        switch (typeFamily)
                        {
                        case TsTypeFamily.Class:
                            this.Add(collectionItemType);
                            break;

                        case TsTypeFamily.Enum:
                            this.AddEnum(new TsEnum(collectionItemType));
                            break;
                        }
                    }
                }
                else if (propertyTypeFamily == TsTypeFamily.Class)
                {
                    this.Add(genericArgument.Type);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds classes referenced by the class to the model
        /// </summary>
        /// <param name="classModel"></param>
        private void AddReferences(TsClass classModel)
        {
            foreach (var property in classModel.Properties.Where(model => !model.IsIgnored))
            {
                var propertyTypeFamily = TsType.GetTypeFamily(property.PropertyType.Type);
                if (propertyTypeFamily == TsTypeFamily.Collection)
                {
                    var collectionItemType = TsType.GetEnumerableType(property.PropertyType.Type);
                    while (collectionItemType != null)
                    {
                        var typeFamily = TsType.GetTypeFamily(collectionItemType);

                        switch (typeFamily)
                        {
                        case TsTypeFamily.Class:
                            this.Add(collectionItemType);
                            collectionItemType = null;
                            break;

                        case TsTypeFamily.Enum:
                            this.AddEnum(new TsEnum(collectionItemType));
                            collectionItemType = null;
                            break;

                        case TsTypeFamily.Collection:
                            collectionItemType = TsType.GetEnumerableType(collectionItemType);
                            break;

                        default:
                            collectionItemType = null;
                            break;
                        }
                    }
                }
                else if (propertyTypeFamily == TsTypeFamily.Class)
                {
                    this.Add(property.PropertyType.Type);
                }
            }
            foreach (var genericArgument in classModel.GenericArguments)
            {
                var propertyTypeFamily = TsType.GetTypeFamily(genericArgument.Type);
                if (propertyTypeFamily == TsTypeFamily.Collection)
                {
                    var collectionItemType = TsType.GetEnumerableType(genericArgument.Type);
                    if (collectionItemType != null)
                    {
                        var typeFamily = TsType.GetTypeFamily(collectionItemType);

                        switch (typeFamily)
                        {
                        case TsTypeFamily.Class:
                            this.Add(collectionItemType);
                            break;

                        case TsTypeFamily.Enum:
                            this.AddEnum(new TsEnum(collectionItemType));
                            break;
                        }
                    }
                }
                else if (propertyTypeFamily == TsTypeFamily.Class)
                {
                    this.Add(genericArgument.Type);
                }
            }
        }