-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathProgram.cs
28 lines (23 loc) · 887 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Resources;
namespace PostSharp.Samples.ValidateResourceString
{
internal class Program
{
private const string resourceName = "PostSharp.Samples.ValidateResourceString.MyResource";
private static readonly ResourceManager resourceManager = new ResourceManager(resourceName,
typeof(Program).Assembly);
private static void Main(string[] args)
{
// These two method calls are valid.
Console.WriteLine(GetResourceString("String1"));
Console.WriteLine(GetResourceString("String2"));
// There is a warning for the following line because Strong3 is not a valid string name.
Console.WriteLine(GetResourceString("Strong3"));
}
private static string GetResourceString([ValidateResourceString(resourceName)] string key)
{
return resourceManager.GetString(key) ?? "*** Error ***";
}
}
}