SR.Strings的使用辦法

來源:互聯網
上載者:User
安裝String Resource Generator 1[1].2.5,運行SRGenerator.msi。然後給自己的工程中添加SR.strings檔案,通過VS.NET在現有的.RESX或SR.strings檔案設定Custom tool屬性為:StringResourceTool或SRCodeGen。 使用呢,比如:我們在SR.strings檔案中定義了一行: ItemNotFoundMessage(key) =  Item not found in cache"r"n"tKey: {0}那麼我們在應用程式中就可以這樣:this.primitivesResultsTextBox.Text += SR.ItemNotFoundMessage(selectItemForm.ItemKey) + ""r"n"; 其實,這個SR.ItemNotFoundMessage的定義在自動產生的SR.CS檔案中: public static string ItemNotFoundMessage (string key)
  {
   return Keys.GetString( Keys.ItemNotFoundMessage, key );
  } 這種傳入方式很利於我們統一應用中的錯誤描述的產生方式。比如我們可以定義錯誤描述在SR.strings檔案中:LBS_Request_CannotConnectServer = 無法串連到遠端LBS閘道伺服器:{0}那麼在實際調用時就可以這麼:catch(WebException ex)
{...    sb.Append("<result resid=""501"">"+ SR.LBS_Request_CannotConnectServer(_Url) +"</result>"n");...}  其他的SR.Strings定義方式還有:

Name

Value

Comments

Member on SR class

NotAuthorized

You are not authorized, go away

String NotAuthorized { get; }

ArgumentInvalid

Argument {0} is not valid

argumentName

String ArgumentInvalid(object argumentName);

ConnectionBad

Connection server: {0}, database {1} invalid

server,db

String ConnectionBad(object server, object db);

OtherStuff

This {0}, is undefined: {1}

String OtherStuff(object arg1, object arg2);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.