mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-22 06:05:26 -06:00
Added helper method for creating TypeCreators.
This commit is contained in:
parent
056e8037a6
commit
631ebe508f
1 changed files with 20 additions and 0 deletions
|
|
@ -20,5 +20,25 @@ namespace Qml.Net
|
|||
}
|
||||
return Activator.CreateInstance(type);
|
||||
}
|
||||
|
||||
public static ITypeCreator FromDelegate(Func<Type, object> func)
|
||||
{
|
||||
return new DelegateTypeCreator(func);
|
||||
}
|
||||
|
||||
class DelegateTypeCreator : ITypeCreator
|
||||
{
|
||||
private readonly Func<Type, object> _func;
|
||||
|
||||
public DelegateTypeCreator(Func<Type, object> func)
|
||||
{
|
||||
_func = func;
|
||||
}
|
||||
|
||||
public object Create(Type type)
|
||||
{
|
||||
return _func(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue