Ejemplo n.º 1
0
 /// <summary>
 /// Wrapper classes will most likely implement new version of this method.
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="flags"></param>
 internal virtual void SetupInstance(IntPtr instance, NativeObjectFlags flags = NativeObjectFlags.None)
 {
     Flags          = flags;
     NativeInstance = instance;
     if (!flags.HasFlag(NativeObjectFlags.SkipInstanceCache))
     {
         InstanceCache.Add(this);
     }
     OnSetupInstance();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Wrapper classes will most likely implement new version of this method.
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="ownsInstance"></param>
 /// <param name="addToCache"></param>
 internal virtual void SetupInstance(IntPtr instance, bool ownsInstance, bool addToCache = true)
 {
     OwnsNativeInstance = ownsInstance;
     NativeInstance     = instance;
     if (addToCache)
     {
         InstanceCache.Add(this);
     }
     OnSetupInstance();
 }
Ejemplo n.º 3
0
        internal static T GetManagedInstanceGeneric <T>(IntPtr source, NativeObjectFlags flags = NativeObjectFlags.None) where T : NativeObject
        {
            if (source == IntPtr.Zero)
            {
                return(null);
            }

            return(InstanceCache.GetOrAdd(source, ptr =>
            {
                var getManaged = typeof(T).GetMethod("GetManagedInstance", BindingFlags.NonPublic | BindingFlags.Static);
                Debug.Assert(getManaged != null);
                return (T)getManaged.Invoke(null, new object[] { source, flags });
            }));
        }
Ejemplo n.º 4
0
 internal static void Dispose()
 {
     InstanceCache.Dispose();
 }
Ejemplo n.º 5
0
 // Derived types will put object initialization code here. At the time of writing such code sets up virtual
 // method callbacks and nothing more.
 internal virtual void PerformInstanceSetup(IntPtr instance, bool ownsInstance)
 {
     OwnsNativeInstance = ownsInstance;
     NativeInstance = instance;
     InstanceCache.Add(this);
 }