2015-12-09 100 views
0

有沒有辦法重用方法CamelCasePropertyNamesContractResolver將屬性名稱轉換爲字符串?我可以使用CamelCasePropertyNamesContractResolver給CamelCase一個字符串嗎?

我使用CamelCasePropertyNamesContractResolver作爲我的JsonFormatter for WebApi,它工作得很好。在我的應用程序的另一個區域中,我動態地將一些.NET模型屬性轉換爲在JS中使用的字符串。然而,這些字符串是Pascal大小寫(因爲是我的.NET標準),因此JS不能直接用於已經格式化的JS對象屬性。

// JS Example 
var myJsonObject = getJsonObjectFromServer(); 
var myPropertyString = getPropertyNameFromServer(); 
var value = myJsonObject[myPropertyString]; 
// But value cannot be determined as casing of myPropertyString has changed 

我想避免必須創建我自己的ToCamelCase方法,它可能會創建一個不同的字符串。我還想繼續使用CamelCasePropertyNamesContractResolver(問題的根源),因爲現在應用程序非常龐大,並且需要大量的JS更新並使我的js非標準。

回答

相關問題