コード例 #1
0
        public TypeScriptType ReferenceFrom(TypeScriptUnit targetUnit, ITypeGenerator typeGenerator)
        {
            var typeReference = typeGenerator.ResolveType(type.GetGenericTypeDefinition()).ReferenceFrom(targetUnit, typeGenerator);
            var arguments     = new List <TypeScriptType>();

            foreach (var argument in type.GetGenericArguments())
            {
                var targetType = typeGenerator.ResolveType(argument).ReferenceFrom(targetUnit, typeGenerator);
                arguments.Add(targetType is INullabilityWrapperType nullabilityType ? nullabilityType.InnerType : targetType);
            }
            return(new TypeScriptGenericTypeReference(typeReference as TypeScriptTypeReference, arguments.ToArray()));
        }
コード例 #2
0
        public TypeScriptType ReferenceFrom(TypeScriptUnit targetUnit, ITypeGenerator typeGenerator, IAttributeProvider?attributeProvider)
        {
            var itemType   = typeGenerator.ResolveType(elementType).ReferenceFrom(targetUnit, typeGenerator, null);
            var resultType = TypeScriptGeneratorHelpers.BuildTargetNullableTypeByOptions(itemType, CanItemBeNull(attributeProvider), options);

            return(new TypeScriptArrayType(resultType));
        }
コード例 #3
0
        public TypeScriptType ReferenceFrom(TypeScriptUnit targetUnit, ITypeGenerator typeGenerator)
        {
            var itemTypeScriptType = typeGenerator.ResolveType(itemType).ReferenceFrom(targetUnit, typeGenerator);

            return(useGlobalNullable
                       ? (TypeScriptType) new TypeScriptNullableType(itemTypeScriptType)
                       : new TypeScriptOrNullType(itemTypeScriptType));
        }
コード例 #4
0
        public override void BuildDefinition(ITypeGenerator typeGenerator)
        {
            var types = Type.Assembly
                        .GetTypes()
                        .Where(x => x != Type && Type.IsAssignableFrom(x) && (useAbstractChildren || !x.IsAbstract))
                        .Select(x => typeGenerator.ResolveType(x).ReferenceFrom(Unit, typeGenerator))
                        .ToArray();

            Declaration.Definition = new TypeScriptUnionType(types);
        }
コード例 #5
0
        public override void BuildDefinition(ITypeGenerator typeGenerator)
        {
            var types = typeGenerator.TypesProvider
                        .GetAssemblyTypes(Type)
                        .Where(x => !x.Equals(Type) && Type.IsAssignableFrom(x) && (useAbstractChildren || !x.IsAbstract))
                        .Select(x => typeGenerator.ResolveType(x).ReferenceFrom(Unit, typeGenerator, null))
                        .ToArray();

            Declaration.Definition = new TypeScriptUnionType(types);
        }
コード例 #6
0
        public override void Initialize(ITypeGenerator typeGenerator)
        {
            Declaration = CreateComplexTypeScriptDeclarationWithoutDefinition(Type);
            Unit.Body.Add(new TypeScriptExportTypeStatement {
                Declaration = Declaration
            });

            if (Type.BaseType != typeof(object) && Type.BaseType != typeof(ValueType) && Type.BaseType != typeof(MarshalByRefObject) && Type.BaseType != null)
            {
                typeGenerator.ResolveType(Type.BaseType);
            }
        }
コード例 #7
0
        public TypeScriptType ReferenceFrom(TypeScriptUnit targetUnit, ITypeGenerator typeGenerator, IAttributeProvider?attributeProvider)
        {
            var typeReference = typeGenerator.ResolveType(type.GetGenericTypeDefinition()).ReferenceFrom(targetUnit, typeGenerator, null);
            var arguments     = new List <TypeScriptType>();
            var nullableIndex = 1;

            foreach (var argument in type.GetGenericArguments())
            {
                var targetType = typeGenerator.ResolveType(argument).ReferenceFrom(targetUnit, typeGenerator, null);
                if (options.NullabilityMode == NullabilityMode.NullableReference)
                {
                    var isNullable = TypeScriptGeneratorHelpers.NullableReferenceCanBeNull(attributeProvider, argument, nullableIndex);
                    nullableIndex += TypeScriptGeneratorHelpers.GetGenericArgumentsToSkip(argument);
                    arguments.Add(TypeScriptGeneratorHelpers.BuildTargetNullableTypeByOptions(targetType, !argument.IsValueType && isNullable, options));
                }
                else
                {
                    arguments.Add(targetType is INullabilityWrapperType nullabilityType ? nullabilityType.InnerType : targetType);
                }
            }
            return(new TypeScriptGenericTypeReference((TypeScriptTypeReference)typeReference, arguments.ToArray()));
        }
        public TypeScriptType ReferenceFrom(TypeScriptUnit targetUnit, ITypeGenerator typeGenerator)
        {
            var keyTypeScriptType   = typeGenerator.ResolveType(keyType).ReferenceFrom(targetUnit, typeGenerator);
            var valueTypeScriptType = typeGenerator.ResolveType(valueType).ReferenceFrom(targetUnit, typeGenerator);

            return(new TypeScriptTypeDefintion
            {
                Members =
                {
                    new TypeScriptTypePropertyGetterDeclaration
                    {
                        Argument = new TypeScriptArgumentDeclaration
                        {
                            Name = "key",
                            Type = keyTypeScriptType,
                        },
                        ResultType = valueTypeScriptType,
                        Optional = true,
                    }
                }
            });
        }
コード例 #9
0
        public override void Initialize(ITypeGenerator typeGenerator)
        {
            Declaration = CreateComplexTypeScriptDeclarationWithoutDefinition(Type);
            Unit.Body.Add(new TypeScriptExportTypeStatement {
                Declaration = Declaration
            });

            var baseType = Type.BaseType;

            if (baseType != null && !baseType.Equals(TypeInfo.From <object>()) && !baseType.Equals(TypeInfo.From <ValueType>()) && !baseType.Equals(TypeInfo.From <MarshalByRefObject>()))
            {
                typeGenerator.ResolveType(baseType);
            }
        }
コード例 #10
0
        private TypeScriptType GetValueType(TypeScriptUnit targetUnit, ITypeGenerator typeGenerator, IAttributeProvider?attributeProvider)
        {
            var value = typeGenerator.ResolveType(valueType).ReferenceFrom(targetUnit, typeGenerator, null);

            return(MaybeNull(valueType, value, attributeProvider, 1 + TypeScriptGeneratorHelpers.GetGenericArgumentsToSkip(keyType)));
        }
コード例 #11
0
        private TypeScriptType GetKeyType(TypeScriptUnit targetUnit, ITypeGenerator typeGenerator, IAttributeProvider?attributeProvider)
        {
            var key = typeGenerator.ResolveType(keyType).ReferenceFrom(targetUnit, typeGenerator, null);

            return(MaybeNull(keyType, key, attributeProvider, 1));
        }
        public TypeScriptType ReferenceFrom(TypeScriptUnit targetUnit, ITypeGenerator typeGenerator)
        {
            var itemType = typeGenerator.ResolveType(elementType).ReferenceFrom(targetUnit, typeGenerator);

            return(new TypeScriptArrayType(itemType));
        }
コード例 #13
0
 public static TypeScriptType BuildAndImportType(this ITypeGenerator typeGenerator, TypeScriptUnit typeScriptUnit, ITypeInfo type)
 {
     return(typeGenerator.ResolveType(type).ReferenceFrom(type, typeScriptUnit, typeGenerator));
 }