Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
0
        private TypeScriptType MaybeNull(ITypeInfo trueType, TypeScriptType type, IAttributeProvider?attributeProvider, int index)
        {
            if (options.NullabilityMode != NullabilityMode.NullableReference)
            {
                return(type);
            }

            var isNullable = TypeScriptGeneratorHelpers.NullableReferenceCanBeNull(attributeProvider, trueType, index);

            return(TypeScriptGeneratorHelpers.BuildTargetNullableTypeByOptions(type, isNullable, options));
        }
        public TypeScriptType ReferenceFrom(ITypeInfo type, TypeScriptUnit targetUnit, ITypeGenerator typeGenerator)
        {
            if (!type.Equals(Type))
            {
                throw new InvalidOperationException($"Expected type {Type} with different meta, but got different type: {type}");
            }

            return(TypeScriptGeneratorHelpers.BuildTargetNullableTypeByOptions(
                       ReferenceFromInternal(type, targetUnit, typeGenerator),
                       type.CanBeNull(typeGenerator.Options.NullabilityMode),
                       typeGenerator.Options));
        }
Ejemplo n.º 4
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()));
        }