【发布时间】:2021-03-26 10:19:33
【问题描述】:
我在 TypeScript 中有一个类,它的属性用 camelCase 编写。 该类的实例需要在处理 Web 服务的 http 请求正文中使用。 问题是,WebService 的后端是用 C# 编写的,它试图使用 UpperCamelCase 表示法访问属性。
在 http 请求中发送类时,如何将类的属性从 camelCase 转换为 UpperCamelCase?
例子:
class Test1:
httpClient: CustomHttpClient;
public attributeOne
public attributeTwo
constructor(att1,att2):{
this.attributeOne = att1;
this.attributeTwo = att2;
this.httpClient = new CustomHttpClient();
}
sendRequest(){
const test = new Test1();
this.httpClient.post(url, test , null);
}
WebService 将尝试像Wise 一样访问正文:
test.AttributeOne
test.AttributeTwo;
因此导致错误,因为不存在此类属性。
出于 linting 等原因,我不想将 TS 中的属性更改为 UpperCamelCase。
我如何做到这一点?
【问题讨论】:
标签: c# typescript https data-conversion camelcasing