Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public sealed class RenderTools
- {
- private readonly IDictionary<Type, Func<object, Freezable>> _toolFactories = new Dictionary<Type, Func<object, Freezable>>();
- private readonly IDictionary<object, Freezable> _toolCache = new Dictionary<object, Freezable>();
- public void RegisterTool<TKey, TResult>(Func<TKey, TResult> toolFactory)
- where TResult : Freezable
- {
- this._toolFactories[typeof(TKey)] = new Func<object, Freezable>(
- p =>
- {
- var tool = toolFactory((TKey)p);
- tool.Freeze();
- return tool;
- });
- }
- public TResult GetTool<TResult>(object toolKey)
- where TResult : Freezable
- {
- Freezable result;
- if (!this._toolCache.TryGetValue(toolKey, out result))
- {
- result = this._toolFactories[toolKey.GetType()](toolKey);
- this._toolCache.Add(toolKey, result);
- }
- return (TResult)result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement