使用TypeLite生成具有DataMember名称的C#类

使用TypeLite生成具有DataMember名称的C#类,c#,typescript,serialization,typelite,C#,Typescript,Serialization,Typelite,我目前正在使用从一组C#类构建.d.ts接口文件。我遇到了一个问题,其中一些类具有DataMember的属性,其中给定的值与属性名不同。在这种情况下,我希望TypeLite使用DataMember属性而不是属性名——不幸的是,我在文档中找不到任何地方说明这是可能的 有什么想法吗?只有检查内置的[TsProperty]属性才能重命名属性: var attribute = memberInfo.GetCustomAttribute<TsPropertyAttribute>(false);

我目前正在使用从一组C#类构建.d.ts接口文件。我遇到了一个问题,其中一些类具有DataMember的属性,其中给定的值与属性名不同。在这种情况下,我希望TypeLite使用DataMember属性而不是属性名——不幸的是,我在文档中找不到任何地方说明这是可能的

有什么想法吗?

只有检查内置的
[TsProperty]
属性才能重命名属性:

var attribute = memberInfo.GetCustomAttribute<TsPropertyAttribute>(false);
if (attribute != null) {
    if (!string.IsNullOrEmpty(attribute.Name)) {
        this.Name = attribute.Name;
    }

    this.IsOptional = attribute.IsOptional;
}
也许您可以提交一个包含该修复的拉取请求。请确保添加测试并考虑两个属性都应用于属性的情况。


为了保持一致性,您还必须对
[DataContract]
属性进行修补以支持重命名类。

[TsProperty(Name=”“)]
属性,这是一个选项吗?实际上不是-对现有文件的更改太大。尽管它将保持向后兼容性。也许可以,但不是首选方案。谢谢:)这听起来很适合我们的需要。我会试一试,如果成功的话,一定会回来标记修复。谢谢:)
var dataMemberAttribute = memberInfo.GetCustomAttribute<System.Runtime.Serialization.DataMemberAttribute>(false);
if (dataMemberAttribute!= null) {
    if (!string.IsNullOrEmpty(dataMemberAttribute.Name)) {
        this.Name = dataMemberAttribute.Name;
    }

    this.IsOptional = !dataMemberAttribute.IsRequired;
}