private static IEnumerable <TsType> FindInternal(TsDeclaration tsDeclaration) { switch (tsDeclaration) { case TsClass tsClass: return(tsClass.Base); case TsEnum _: return(Array.Empty <TsType>()); case TsFunction tsFunction: return(tsFunction.Parameters.Select(x => x.Type) .Append(tsFunction.ReturnType)); case TsInterface tsInterface: return(tsInterface.Base .Concat(tsInterface.Properties .OfType <TsPropertySignature>() .Select(x => x.Type))); case TsNamespace tsNamespace: return(tsNamespace.Declarations.SelectMany(FindInternal)); default: throw new ArgumentOutOfRangeException(nameof(tsDeclaration), tsDeclaration, null); } }
private void Register(TsFile tsFile, TsDeclaration tsDeclaration) { switch (tsDeclaration) { case TsClass _: case TsInterface _: case TsEnum _: Add(new Export(tsDeclaration, tsFile)); break; case TsFunction _: break; case TsNamespace tsNamespace: foreach (var declaration in tsNamespace.Declarations) { Register(tsFile, declaration); } break; default: throw new ArgumentOutOfRangeException(nameof(tsDeclaration), tsDeclaration.GetType().Name, null); } }
public static CsType[] Find(TsDeclaration tsDeclaration) { return(FindInternal(tsDeclaration) .Where(x => x != null) .SelectMany(Unwrap) .OfType <TsTypeReference>() .Select(x => x.CsType) .Where(x => x != null) .Where(x => !x.OriginalType.IsGenericParameter) .ToArray()); }
public Export(TsDeclaration tsDeclaration, TsFile tsFile) { CsType = tsDeclaration.CsType; Name = tsDeclaration.Name; TsFile = tsFile; }