C# TypeLite:如何转换IEnumerable<;T>;任何[]

C# TypeLite:如何转换IEnumerable<;T>;任何[],c#,typescript,dto,typelite,C#,Typescript,Dto,Typelite,假设我有以下C类: (我在类名后面加了一个“I”,并将类属性小写,这样就可以了。) Typelite目前正在将IEnumerable转换为它,这显然是我不想要的。I被追加,T是泛型类型 interface IResults { values: IT[]; } 我已经看了下面的问题,是用Converter还是用Formatter。 我也看了typelite文档,但它们没有示例,所以我觉得卡住了。 任何帮助都将不胜感激 我确实做到了这一点,但这绝对是一次黑客攻击。好笑,我没早点想到 &l

假设我有以下C类:

(我在类名后面加了一个“I”,并将类属性小写,这样就可以了。)

Typelite目前正在将IEnumerable转换为它,这显然是我不想要的。I被追加,T是泛型类型

interface IResults {
    values: IT[];
}
我已经看了下面的问题,是用Converter还是用Formatter。 我也看了typelite文档,但它们没有示例,所以我觉得卡住了。


任何帮助都将不胜感激

我确实做到了这一点,但这绝对是一次黑客攻击。好笑,我没早点想到

<#= ts.Generate(TsGeneratorOutput.Properties).Replace("IT[]", "any[]" ) #>

TypeLite有很多扩展点,但不幸的是,文档没有涵盖所有扩展点。为此,您可以使用自己的
TsMemberTypeFormatter

.WithMemberTypeFormatter((tsProperty, memberTypeName) => {
    var asCollection = tsProperty.PropertyType as TypeLite.TsModels.TsCollection;
    var isCollection = asCollection != null;

    if(tsProperty.GenericArguments.Count == 1 && 
       tsProperty.GenericArguments[0] is TypeLite.TsModels.TsClass && 
       ((TypeLite.TsModels.TsClass)tsProperty.GenericArguments[0]).Name =="T") {
           memberTypeName = "any";
    }

    return memberTypeName + (isCollection ? string.Concat(Enumerable.Repeat("[]", asCollection.Dimension)) : "");
})

太好了,谢谢你,卢卡斯!一般来说,TypeLite配置感觉有点冗长,但这是可行的。
<#= ts.Generate(TsGeneratorOutput.Properties).Replace("IT[]", "any[]" ) #>
.WithMemberTypeFormatter((tsProperty, memberTypeName) => {
    var asCollection = tsProperty.PropertyType as TypeLite.TsModels.TsCollection;
    var isCollection = asCollection != null;

    if(tsProperty.GenericArguments.Count == 1 && 
       tsProperty.GenericArguments[0] is TypeLite.TsModels.TsClass && 
       ((TypeLite.TsModels.TsClass)tsProperty.GenericArguments[0]).Name =="T") {
           memberTypeName = "any";
    }

    return memberTypeName + (isCollection ? string.Concat(Enumerable.Repeat("[]", asCollection.Dimension)) : "");
})