public static NativeDelegateWrapper Create(Type delegateType, IntPtr icallAddr, IntPtr context, out bool created)
{
created = false;
if (delegateType == null)
throw new ArgumentNullException("delegateType");
if (!typeof (Delegate).IsAssignableFrom(delegateType))
throw new ArgumentException("Must be a delegate type", "delegateType");
Type wrapperType;
lock (locker)
{
var key = new KeyValuePair<Type, IntPtr>(delegateType, icallAddr);
if (!wrapperCache.TryGetValue(key, out wrapperType))
{
wrapperType = EmitWrapper(delegateType);
wrapperCache.Add(key, wrapperType);
created = true;
}
}
return (NativeDelegateWrapper) Activator.CreateInstance(wrapperType, new object[] {context});
}