假设我有以下C#类:
[TsClass]
public class Results<T>
{
public IEnumerable<T> Values { get; set; }
}我希望类型专家生成以下界面:
interface IResults {
values: any[];
}(我在类名后面加上一个'I‘,并降低类属性,这很好。)
台风目前正在将IEnumerable转换为IT,这显然我不想要。I被追加,而T是泛型类型。
interface IResults {
values: IT[];
}我看过以下这样的问题,哪个指向WithConverter或WithFormatter。Typelite: Why is Dictionary mapped to KeyValuePair and not to any or [index:string]:any我也看过那些优秀的文档,但是它们没有例子,所以我觉得卡住了。http://type.litesolutions.net/doc
任何帮助都将不胜感激!
发布于 2015-11-07 17:51:08
我确实成功了,但这绝对是个黑客。有趣的是我没有更早想到这一点。
<#= ts.Generate(TsGeneratorOutput.Properties).Replace("IT[]", "any[]" ) #>发布于 2015-11-08 19:12:18
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)) : "");
})https://stackoverflow.com/questions/33585465
复制相似问题