internal void Initialize(Type t) { InitializeApartmentDetails(); // Guard multiple invocation. if (iunknown != IntPtr.Zero) { return; } ObjectCreationDelegate ocd = ExtensibleClassFactory.GetObjectCreationCallback(t); if (ocd != null) { iunknown = ocd(IntPtr.Zero); if (iunknown == IntPtr.Zero) { throw new COMException(string.Format("ObjectCreationDelegate for type {0} failed to return a valid COM object", t)); } } else { int hr = CoCreateInstance(GetCLSID(t), IntPtr.Zero, 0x1 | 0x4 | 0x10, IID_IUnknown, out iunknown); Marshal.ThrowExceptionForHR(hr); } }
/// <summary> /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed. /// <example> /// objectcreationdelegate.BeginInvoke(aggregator, callback); /// </example> /// </summary> public static IAsyncResult BeginInvoke(this ObjectCreationDelegate objectcreationdelegate, IntPtr aggregator, AsyncCallback callback) { if (objectcreationdelegate == null) { throw new ArgumentNullException("objectcreationdelegate"); } return(objectcreationdelegate.BeginInvoke(aggregator, callback, null)); }
public static void RegisterObjectCreationCallback (ObjectCreationDelegate callback) { int i = 1; StackTrace trace = new StackTrace (false); while (i < trace.FrameCount) { StackFrame frame = trace.GetFrame (i); MethodBase m = frame.GetMethod (); if (m.MemberType == MemberTypes.Constructor && m.IsStatic) { hashtable.Add (m.DeclaringType, callback); return; } i++; } throw new System.InvalidOperationException ( "RegisterObjectCreationCallback must be called from .cctor of class derived from ComImport type."); }
public ObjectPooler(ObjectCreationDelegate creator, Transform poolTransform, int pooledAmount = 20, bool willGrow = true) { objectCreationMethod = creator; pooledObjects = new List <GameObject>(); this.pooledAmount = pooledAmount; this.willGrow = willGrow; for (int i = 0; i < pooledAmount; i++) { GameObject obj = objectCreationMethod(); obj.transform.SetParent(poolTransform); obj.SetActive(false); pooledObjects.Add(obj); } }
/// <summary>Registers a delegate that is called when an instance of a managed type, that extends from an unmanaged type, needs to allocate the aggregated unmanaged object.</summary> /// <param name="callback">A delegate that is called in place of CoCreateInstance. </param> public static void RegisterObjectCreationCallback(ObjectCreationDelegate callback) { int i = 1; StackTrace stackTrace = new StackTrace(false); while (i < stackTrace.FrameCount) { StackFrame frame = stackTrace.GetFrame(i); MethodBase method = frame.GetMethod(); if (method.MemberType == MemberTypes.Constructor && method.IsStatic) { ExtensibleClassFactory.hashtable.Add(method.DeclaringType, callback); return; } i++; } throw new InvalidOperationException("RegisterObjectCreationCallback must be called from .cctor of class derived from ComImport type."); }
internal void Initialize(Type t) { if (this.iunknown != IntPtr.Zero) { return; } ObjectCreationDelegate objectCreationCallback = ExtensibleClassFactory.GetObjectCreationCallback(t); if (objectCreationCallback != null) { this.iunknown = objectCreationCallback(IntPtr.Zero); if (this.iunknown == IntPtr.Zero) { throw new COMException(string.Format("ObjectCreationDelegate for type {0} failed to return a valid COM object", t)); } } else { int errorCode = __ComObject.CoCreateInstance(__ComObject.GetCLSID(t), IntPtr.Zero, 21u, __ComObject.IID_IUnknown, out this.iunknown); Marshal.ThrowExceptionForHR(errorCode); } }
internal static IntPtr CreateIUnknown(Type t) { System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(t.TypeHandle); IntPtr iunknown; ObjectCreationDelegate ocd = ExtensibleClassFactory.GetObjectCreationCallback(t); if (ocd != null) { iunknown = ocd(IntPtr.Zero); if (iunknown == IntPtr.Zero) { throw new COMException(string.Format("ObjectCreationDelegate for type {0} failed to return a valid COM object", t)); } } else { int hr = CoCreateInstance(GetCLSID(t), IntPtr.Zero, 0x1 | 0x4 | 0x10, IID_IUnknown, out iunknown); Marshal.ThrowExceptionForHR(hr); } return(iunknown); }
public static void RegisterObjectCreationCallback(ObjectCreationDelegate callback) { }
public static extern void RegisterObjectCreationCallback(ObjectCreationDelegate callback);
// Register an object creation callback delegate. public static void RegisterObjectCreationCallback (ObjectCreationDelegate callback) { // Not used in this implementation. }
public static void RegisterObjectCreationCallback(ObjectCreationDelegate callback) { throw new NotImplementedException(); }