Skip to content

Instantly share code, notes, and snippets.

@hazzik
Created October 15, 2012 20:44
Show Gist options
  • Save hazzik/3895319 to your computer and use it in GitHub Desktop.
Save hazzik/3895319 to your computer and use it in GitHub Desktop.
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