我有一些類Item
其中包含一個字段重構常量字符串
public const string Root = "/homepage";
不幸的是,事實證明這個字符串不是常量!
當我試圖重新定義爲說
public string Root = DoSomething("/homepage");
或財產
public string Root
{
get {
return DoSomething("/homepage");
}
}
我得到兩種不同類型的錯誤
A field initializer cannot reference the non-static field, method, or property 'Item.Root'
的,這一次打一頓,我認爲可能是一個更大的問題
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
我真的不確定如何解決這個問題,沒有一個嚴肅的重構練習。有什麼建議?
@IvanStoev你是對的,我錯過了第二個錯誤。謝謝! – dasblinkenlight
謝謝,至少現在我*知道*我是scr **編輯。 – inspite
@inspite您是否遇到了您自己的某個屬性問題,或者是您無法更改的問題? – dasblinkenlight