本文整理汇总了C#中System.Resources.ResourceSet.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceSet.GetString方法的具体用法?C# ResourceSet.GetString怎么用?C# ResourceSet.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Resources.ResourceSet
的用法示例。
在下文中一共展示了ResourceSet.GetString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetResourceSet
private ResourceSet GetResourceSet(CultureInfo culture, bool custom) {
ResourceSet resource;
String resourceKey = GetResourceKey(culture, custom);
lock(_resourceLock) {
// if the resource data for this culture has not yet been loaded, load it
if(!ResourceData.TryGetValue(resourceKey, out resource)) {
// set the filename according to the cuture
String filename;
if(null == culture) {
filename = "resources.custom.txt";
} else if(culture.Equals(CultureInfo.InvariantCulture)) {
filename = "resources.txt";
} else {
filename = "resources.";
if(custom) {
filename += "custom.";
}
filename += culture.Name.ToLowerInvariant() + ".txt";
}
filename = Path.Combine(_resourcePath, filename);
// load the resource set and add it into the resource table
resource = new ResourceSet(new PlainTextResourceReader(filename));
// Note (arnec): We call GetString to force the lazy loading of the resource stream, thereby making
// GetString(), at least theoretically, thread-safe for subsequent calls.
resource.GetString("", true);
ResourceData.Add(resourceKey, resource);
}
}
return resource;
}
示例2: ReadToken
static string ReadToken(EmbeddedResource resources, string token)
{
using (var resourceStream = resources.GetResourceStream())
using (var resourceSet = new ResourceSet(resourceStream))
return resourceSet.GetString(token, true);
}
示例3: GetConfigurationFromResourceFile
/// <summary>
/// Get the value corresponding to specified key from specified resource file
/// </summary>
/// <param name="fileName">Name of the resource file</param>
/// <param name="keyName">Name of the key</param>
/// <param name="resourceFileLocation">Resource file location</param>
/// <returns>
/// Value of the key
/// </returns>
public static string GetConfigurationFromResourceFile(string fileName, string keyName, Enumerators.ResourceFileLocation resourceFileLocation)
{
string resourceValue = string.Empty;
ResXResourceReader resxReader = null;
try
{
resxReader = new ResXResourceReader(HttpContext.Current.Server.MapPath(@"~/" + resourceFileLocation + ConstantStrings.ForwardSlash + fileName + ConstantStrings.ResourceFileExtension));
ResourceSet resourceSet = new ResourceSet(resxReader);
resourceValue = resourceSet.GetString(keyName);
}
catch (Exception exception)
{
Logger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, ConstantStrings.LogTableName);
}
finally
{
resxReader.Close();
}
return resourceValue;
}
示例4: GetLoadStringFromCall
private static string GetLoadStringFromCall (MethodReference mr)
{
MethodDefinition md = mr.Resolve ();
if ((md == null) || !IsResource (md))
return null;
string resourceName = GetResourceNameFromResourceGetter (md);
if (resourceName == null)
return null;
AssemblyDefinition ad = md.GetAssembly ();
string resourceClassName = md.DeclaringType.FullName + ".resources";
EmbeddedResource resource = GetEmbeddedResource (ad, resourceClassName);
if (resource == null)
return null;
using (MemoryStream ms = new MemoryStream (resource.GetResourceData ()))
using (ResourceSet resourceSet = new ResourceSet (ms)) {
return resourceSet.GetString (resourceName);
}
}
示例5: ResourceSetMatches
/// <summary>
/// Checks whether the provided resource set contains an entry matching the provided key.
/// </summary>
/// <param name="resources"></param>
/// <param name="key"></param>
/// <returns></returns>
public static bool ResourceSetMatches(ResourceSet resources, string key)
{
if (resources == null)
return false;
string output = resources.GetString(key);
return (output != null && output != String.Empty);
}
示例6: GetResourceSetFromAssembly
/// <summary>
/// Retrieves the resource set containing the specified key from the provided assembly.
/// </summary>
/// <param name="assembly">The assembly containing the target resource set.</param>
/// <param name="key">The key of the target entry.</param>
/// <returns>The resource set from the provided assembly containing the provided key.</returns>
public static ResourceSet GetResourceSetFromAssembly(Assembly assembly, string key)
{
string[] resourceNames = assembly.GetManifestResourceNames();
ResourceSet resources = null;
foreach (string resourceName in resourceNames)
{
string text = String.Empty;
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
resources = new ResourceSet(stream);
stream.Close();
}
text = resources.GetString(key);
if (ResourceSetMatches(resources, key))
{
return resources;
}
}
return resources;
}