예제 #1
0
        private ITypeBuildingContext GetTypeBuildingContext(string typeLocation, ITypeInfo typeInfo)
        {
            if (BuiltinTypeBuildingContext.Accept(typeInfo))
            {
                return(new BuiltinTypeBuildingContext(typeInfo));
            }

            if (ArrayTypeBuildingContext.Accept(typeInfo))
            {
                return(new ArrayTypeBuildingContext(typeInfo, Options));
            }

            if (DictionaryTypeBuildingContext.Accept(typeInfo))
            {
                return(new DictionaryTypeBuildingContext(typeInfo, Options));
            }

            if (typeInfo.IsEnum)
            {
                var targetUnit = typeUnitFactory.GetOrCreateTypeUnit(typeLocation);
                return(Options.EnumGenerationMode == EnumGenerationMode.FixedStringsAndDictionary
                           ? (ITypeBuildingContext) new FixedStringsAndDictionaryTypeBuildingContext(targetUnit, typeInfo)
                           : new TypeScriptEnumTypeBuildingContext(targetUnit, typeInfo));
            }

            if (typeInfo.IsGenericType && !typeInfo.IsGenericTypeDefinition && typeInfo.GetGenericTypeDefinition().Equals(TypeInfo.From(typeof(Nullable <>))))
            {
                var underlyingType = typeInfo.GetGenericArguments().Single();
                if (Options.EnableExplicitNullability)
                {
                    return(new NullableTypeBuildingContext(underlyingType, Options.UseGlobalNullable));
                }
                return(GetTypeBuildingContext(typeLocation, underlyingType));
            }

            if (typeInfo.IsGenericType && !typeInfo.IsGenericTypeDefinition)
            {
                return(new GenericTypeTypeBuildingContext(typeInfo, Options));
            }

            if (typeInfo.IsGenericParameter)
            {
                return(new GenericParameterTypeBuildingContext(typeInfo));
            }

            if (typeInfo.IsGenericTypeDefinition)
            {
                return(new CustomTypeTypeBuildingContext(typeUnitFactory.GetOrCreateTypeUnit(typeLocation), typeInfo));
            }

            return(new CustomTypeTypeBuildingContext(typeUnitFactory.GetOrCreateTypeUnit(typeLocation), typeInfo));
        }
        private ITypeBuildingContext GetTypeBuildingContext(string typeLocation, ITypeInfo typeInfo)
        {
            if (BuiltinTypeBuildingContext.Accept(typeInfo))
            {
                return(new BuiltinTypeBuildingContext(typeInfo));
            }

            if (ArrayTypeBuildingContext.Accept(typeInfo))
            {
                return(new ArrayTypeBuildingContext(typeInfo));
            }

            if (DictionaryTypeBuildingContext.Accept(typeInfo))
            {
                return(new DictionaryTypeBuildingContext(typeInfo));
            }

            if (TaskTypeBuildingContext.Accept(typeInfo))
            {
                return(new TaskTypeBuildingContext(typeInfo));
            }

            if (NullableTypeBuildingContext.Accept(typeInfo))
            {
                return(new NullableTypeBuildingContext(typeInfo));
            }

            if (typeInfo.IsEnum)
            {
                return(new TypeScriptEnumTypeBuildingContext(typeUnitFactory.GetOrCreateTypeUnit(typeLocation), typeInfo));
            }

            if (typeInfo.IsGenericType && !typeInfo.IsGenericTypeDefinition)
            {
                return(new GenericTypeTypeBuildingContext(typeInfo));
            }

            if (typeInfo.IsGenericParameter)
            {
                return(new GenericParameterTypeBuildingContext(typeInfo));
            }

            if (typeInfo.IsGenericTypeDefinition)
            {
                return(new CustomTypeTypeBuildingContext(typeUnitFactory.GetOrCreateTypeUnit(typeLocation), typeInfo));
            }

            return(new CustomTypeTypeBuildingContext(typeUnitFactory.GetOrCreateTypeUnit(typeLocation), typeInfo));
        }