Created
October 15, 2012 20:44
-
-
Save hazzik/3895319 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Localization | |
{ | |
private readonly Func<string> message; | |
private Localization(string message) | |
: this(() => message) | |
{ | |
} | |
private Localization(Func<string> message) | |
{ | |
this.message = message; | |
} | |
public static implicit operator Localization(string message) | |
{ | |
return new Localization(message); | |
} | |
public static implicit operator Localization(Func<string> message) | |
{ | |
return new Localization(message); | |
} | |
internal Func<string> Message | |
{ | |
get | |
{ | |
return message; | |
} | |
} | |
public static Localization FromResource(Type resourceType, string resourceName) | |
{ | |
var propertyInfo = resourceType.GetProperty(resourceName); | |
var @delegate = (Func<string>)Delegate.CreateDelegate(typeof(Func<string>), propertyInfo.GetGetMethod()); | |
return new Localization(@delegate); | |
} | |
public static Localization FromResource<TResource>(string resourceName) | |
{ | |
return FromResource(typeof(TResource), resourceName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment