我目前使用TypeLite来从一组C#类构建.d.ts接口文件。我遇到了一些问题,其中某些类具有DataMember属性,其中给定值与属性名称不同。在这种情况下,我希望TypeLite使用DataMember属性而不是属性名称 - 不幸的是,我无法在文档中的任何位置找到可能的地方。使用TypeLite生成DataMember名称的C#类
任何想法?
我目前使用TypeLite来从一组C#类构建.d.ts接口文件。我遇到了一些问题,其中某些类具有DataMember属性,其中给定值与属性名称不同。在这种情况下,我希望TypeLite使用DataMember属性而不是属性名称 - 不幸的是,我无法在文档中的任何位置找到可能的地方。使用TypeLite生成DataMember名称的C#类
任何想法?
为内置[TsProperty]
属性重命名性能的code仅检查:
var attribute = memberInfo.GetCustomAttribute<TsPropertyAttribute>(false);
if (attribute != null) {
if (!string.IsNullOrEmpty(attribute.Name)) {
this.Name = attribute.Name;
}
this.IsOptional = attribute.IsOptional;
}
你可以平凡修补这也包括[DataMember]
属性:
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;
}
也许你可以提交通过该修复提出请求。确保添加测试,并考虑两种属性都应用于属性的情况。
为保持一致性,您还必须修补以支持[DataContract]
属性,才能重命名类。
这听起来很适合我们的需求。我会放弃这一点,一定要回来,并标记修复,如果这没有把戏。谢谢 :) – Askanison4
有'[TsProperty(Name =“”)]'属性,是一个选项? – CodeCaster
并非真的 - 在现有文件中发生的变化太大。尽管它会保持向后兼容性。这可能是好的,但不是首选。谢谢:) – Askanison4