我目前正在使用TypeLite从一组C#类构建.d.ts接口文件。我遇到了一个问题,其中一些类具有DataMember的属性,其中给定的值与属性名不同。在本例中,我希望TypeLite使用DataMember属性,而不是属性名称--不幸的是,我在文档中找不到任何地方表明这是可能的。
有什么想法吗?
发布于 2017-09-26 08:43:03
代码只检查内置的[TsProperty]属性以重命名属性:
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]属性才能重命名类。
https://stackoverflow.com/questions/46421371
复制相似问题