3 Mart 2011 Perşembe

Resources.resx içinden veri okumak

Geçenlerde Visual Studio'nun code analysis özelliğini kullanarak uygulamamı kontrol edeyim dedim ve full analizde 1500 adet hata aldım. Bir tanesinde static string ataması yapmayın diyordu. Bunun manası bir label(başlık) nesnesine kod içinden atamak yapmak yerine, git bir resources dosyası yarat stringlerini buraya ekle demekmiş.
Buna istinaden  "Resources.resx" dosyasını oluşturdum, bundan değer okumak için yapmanız gereken de şöyle :

using System;
using System.Resources;

public static string ReadResourceValue(string alinmakIstenenDeger)string resourceValue = string.Empty;try{

string dosyaninBulunduguYer = System.AppDomain.CurrentDomain.BaseDirectory.ToString();ResourceManager resourceManager = new ResourceManager("KurumsalWebApp.Properties.Resources", typeof(KurumsalWebApp.Properties.Resources).Assembly);// ResourceManager.CreateFileBasedResourceManager(resourceFile, dosyaninBulunduguYer, null);resourceValue = resourceManager.GetString(alinmakIstenenDeger);
}
catch{
resourceValue =
}

}
string.Empty;return resourceValue;

Hiç yorum yok:

Yorum Gönder