/// <summary> /// Creates a Typescript type union /// </summary> /// <param name="name">The name used for the type</param> /// <param name="directory">The <see cref="TsDir" /> where the resulting file should be placed.</param> /// <param name="filters">The filters used to find the types used in the union.</param> /// <returns></returns> public UnionTypeDefinition UnionType(string name, TsDir directory = null, params Func <Type, bool>[] filters) { var typesForUnion = new List <TypedFile>(); foreach (var type in _allTypes.Where(t => filters.Any(f => f(t)))) { TypedFile typeForUnion; if (InterfaceFiles.ContainsKey(type)) { typeForUnion = Interface(type); } else if (ClassFiles.ContainsKey(type)) { typeForUnion = Class(type); } else if (type.IsInterface) { typeForUnion = Interface(type); } else { typeForUnion = Class(type); } typesForUnion.Add(typeForUnion); } return(UnionType(name, directory, typesForUnion.ToArray())); }
/// <summary> /// Adds a <see cref="InterfaceFile" /> to be used to generate an interface (classes can be used here if you want to /// generate a typescript interface from a c# class) /// </summary> /// <param name="type"></param> /// <param name="forceInterfaceForProperties"></param> /// <returns>The created <see cref="InterfaceFile" /> so you can make changes like adjusting property names or values.</returns> public InterfaceFile Interface(Type type, bool forceInterfaceForProperties = false) { var t = type.UnderlyingType(); if (InterfaceFiles.ContainsKey(t)) { return(InterfaceFiles[t]); } InterfaceFiles[t] = new InterfaceFile(this, t, RootDir, forceInterfaceForProperties); return(InterfaceFiles[t]); }
public TypedFile Type(Type type) { var t = type.UnderlyingType(); if (t.IsEnum) { return(Enum(t)); } if (t.IsInterface || InterfaceFiles.ContainsKey(t)) { return(Interface(t)); } return(Class(t)); }