Method TryCreateRef
- Namespace
- PaintDotNet.ComponentModel
- Assembly
- PaintDotNet.ComponentModel.dll
TryCreateRef(Type, out IObjectRef?)
Checks to see if the given interface is supported by this object, and if so creates that wrapper and provides it to you. This adds 1 to the reference count of the underlying object. To decrement the reference count, dispose the wrapper provided by this method or permit it to be garbage collected. When the reference count reaches 0, the object will be disposed.
public bool? TryCreateRef(Type interfaceType, out IObjectRef? newObjectRef)
Parameters
interfaceType
TypeThe interface Type to query for. This must derive from IObjectRef.
newObjectRef
IObjectRefOn successful return, this holds the new object ref.
Returns
- bool?
true if the interface is supported, in which case
newObjectRef
will be the new ref. It will be castable tointerfaceType
, and should be disposed (by calling Dispose()) when the caller is finished using it. Not disposing it is also safe, as the GC will handle it, but performance may be impacted.
false if the interface is not supported, in which casenewObjectRef
will be null.
null if the existing ref is disposed.
It is always safe to call this method.
Remarks
The wrapper that is returned refers to the same underlying object (COM or managed). This method is provided so that you can scope or protect references. This method must always return a new object; reference counted managed implementations are not allowed.