Exemplo n.º 1
0
        }                                   // todo

        public TsClassProperty(string name, TsTypeBase propertyType, TsAccessModifier accessModifier, bool hasGetter, bool hasSetter)
        {
            Name           = name;
            PropertyType   = propertyType;
            AccessModifier = accessModifier;
            HasGetter      = hasGetter;
            HasSetter      = hasSetter;
        }
Exemplo n.º 2
0
        private static void AddReferencesForTsType(Stack <TsTypeBase> stack, TsTypeBase tsType)
        {
            switch (tsType)
            {
            case TsArray tsArray:
                stack.Push(tsArray.ElementType);
                return;

            case TsClass tsClass:
                if (tsClass.BaseType != null)
                {
                    stack.Push(tsClass.BaseType);
                }
                foreach (var propertyType in tsClass.Properties.Select(x => x.PropertyType))
                {
                    stack.Push(propertyType);
                }
                return;

            case TsInterface tsInterface:
                if (tsInterface.BaseType != null)
                {
                    stack.Push(tsInterface.BaseType);
                }
                foreach (var propertyType in tsInterface.Properties.Select(x => x.PropertyType))
                {
                    stack.Push(propertyType);
                }
                return;

            case TsGenericTypeReference tsGenericTypeReference:
                foreach (var genericArgument in tsGenericTypeReference.GenericArguments)
                {
                    stack.Push(genericArgument);
                }
                stack.Push(tsGenericTypeReference.Type);
                return;

            case TsEnum _:
            case TsGenericArgument _:
            case TsBoolean _:
            case TsDate _:
            case TsNumber _:
            case TsString _:
                return;

            default:
                throw new ArgumentException($"Type ({tsType.Name}) is missing");
            }
        }
Exemplo n.º 3
0
        private static string GetGenericContent(TsTypeBase reference)
        {
            switch (reference)
            {
            case TsGenericArgument genericArgument:    // TResult
                return(genericArgument.Name);

            case TsGenericTypeReference tsGenericTypeReference:     // ClassX<int, ClassY<string>>
                return(tsGenericTypeReference.Type.Name + "<" + string.Join(", ",
                                                                            tsGenericTypeReference.GenericArguments.Select(GetGenericContent)) + ">");

            default:
                return(reference.Name);
            }
        }
Exemplo n.º 4
0
        private static IList <TsTypeDefinitionBase> GetTypeDefinitionReferences(TsTypeBase tsType)
        {
            var set   = new HashSet <TsTypeDefinitionBase>();
            var stack = new Stack <TsTypeBase>();

            AddReferencesForTsType(stack, tsType);
            while (!stack.IsNullOrEmpty()) // Use while loop instead of recursion for performance reasons
            {
                var current = stack.Pop();
                if (set.Contains(current))
                {
                    // stop circular refs
                    continue;
                }
                AddReferencesForTsType(stack, current);
                if (current is TsTypeDefinitionBase tsTypeDefinition)
                {
                    set.Add(tsTypeDefinition);
                }
            }
            return(set.ToList());
        }
Exemplo n.º 5
0
 public TsInterfaceProperty(string name, TsTypeBase propertyType)
 {
     Name         = name;
     PropertyType = propertyType;
 }
Exemplo n.º 6
0
 public TsCollection GetCollectionType(Type type, TsTypeBase elementType)
 {
     // Only supports arrays of today. Might want to have set in future
     return(new TsArray(type, elementType));
 }
Exemplo n.º 7
0
 public TsClassProperty CreateClassProperty(PropertyInfo property, TsTypeBase propertyType)
 {
     return(new TsClassProperty(property.Name, propertyType, TsAccessModifier.Public, hasGetter: false, hasSetter: false)); // todo
 }
Exemplo n.º 8
0
 public TsInterfaceProperty CreateInterfaceProperty(PropertyInfo property, TsTypeBase propertyType)
 {
     return(new TsInterfaceProperty(property.Name, propertyType));
 }