示例#1
0
        protected virtual TsInterface Rewrite(CsClass csClass)
        {
            var properties = csClass.Members
                             .Where(x => !x.IsStatic)
                             .OfType <CsProperty>()
                             .Select(Rewrite)
                             .ToArray();

            var fields = csClass.Members
                         .OfType <CsField>()
                         .Select(Rewrite)
                         .ToArray();

            var baseTypes = new List <Type>();

            if (csClass.CsType.OriginalType.BaseType != typeof(object))
            {
                baseTypes.Add(csClass.CsType.OriginalType.BaseType);
            }

            baseTypes.AddRange(GetInterfaces(csClass.CsType.OriginalType, false));

            return(new TsInterface
            {
                CsType = csClass.CsType,
                Name = csClass.Name,
                ExportKind = TsExportKind.Named,
                TypeParameters = csClass.TypeParameters,
                Base = baseTypes.Select(x => TsType.From(new CsType(x))).ToArray(),
                Properties = properties.Concat(fields).ToArray()
            });
        }
示例#2
0
        protected virtual TsTypeMember?Rewrite(CsTypeMember csTypeMember)
        {
            switch (csTypeMember)
            {
            case CsProperty csProperty:
                var forceNullable = csProperty.Attributes.Any(a => a.Name.Contains("CanBeNull")) ||
                                    csProperty.IsNullable;
                return(new TsPropertySignature
                {
                    Name = csProperty.Name,
                    Type = TsType.From(csProperty.Type,
                                       forceNullable)
                });

            case CsField csField:
                if (csField.Value == null)
                {
                    return(null);
                }

                return(new TsPropertySignature
                {
                    Name = csField.Name,
                    Type = TsType.FromLiteral(csField.Value)
                });

            default:
                throw new ArgumentOutOfRangeException(nameof(csTypeMember),
                                                      csTypeMember.GetType().Name, null);
            }
        }
示例#3
0
        protected virtual TsInterface Rewrite(CsClass csClass)
        {
            var properties = csClass.Members
                             .Where(x => !x.IsStatic)
                             .OfType <CsProperty>()
                             .Select(Rewrite)
                             .ToArray();

            var fields = csClass.Members
                         .OfType <CsField>()
                         .Select(Rewrite)
                         .ToArray();

            return(new TsInterface
            {
                CsType = csClass.CsType,
                Name = csClass.Name,
                ExportKind = TsExportKind.Named,
                TypeParameters = csClass.TypeParameters,
                Base = csClass.CsType.OriginalType.BaseType == typeof(object)
                                  ? Array.Empty <TsType>()
                                  : new[]
                {
                    TsType.From(new CsType(csClass.CsType.OriginalType
                                           .BaseType))
                },
                Properties = properties.Concat(fields).ToArray()
            });
        }
示例#4
0
 private static TsTypeMember[] GetProperties(CsClass csClass)
 {
     return(csClass.Members
            .OfType <CsProperty>()
            .Select(p => new TsPropertySignature
     {
         Name = p.Name,
         Type = TsType.From(p.Type),
         Optional = false
     })
            .ToArray());
 }
示例#5
0
 private static TsFunction RewriteMethod(CsMethod method)
 {
     return(new TsFunction
     {
         Name = method.Name,
         ExportKind = TsExportKind.Named,
         ReturnType = TsType.From(method.ReturnType),
         Parameters = method.Parameters
                      .Select(x => new TsFunctionParameter
         {
             Name = x.Name, Type = TsType.From(x.Type)
         })
                      .ToArray(),
         Body = "// some body"
     });
 }
示例#6
0
 protected virtual TsInterface Rewrite(CsInterface csInterface)
 {
     return(new TsInterface
     {
         CsType = csInterface.CsType,
         Name = csInterface.Name,
         ExportKind = TsExportKind.Named,
         TypeParameters = csInterface.TypeParameters,
         Base = GetInterfaces(csInterface.CsType.OriginalType, false)
                .Select(x => TsType.From(new CsType(x)))
                .ToArray(),
         Properties = csInterface.Members
                      .Where(x => !x.IsStatic)
                      .OfType <CsProperty>()
                      .Select(Rewrite)
                      .ToArray()
     });
 }