Example #1
0
        private static IntPtr OnCreateInstance(Guid managedTypeId)
        {
            IntPtr rc = IntPtr.Zero;
            Type   t  = null;

            for (int i = 0; i < g_types.Count; i++)
            {
                if (g_types[i].GUID == managedTypeId)
                {
                    t = g_types[i];
                    break;
                }
            }
            if (t != null)
            {
                try
                {
                    UserData ud = Activator.CreateInstance(t) as UserData;
                    if (ud != null)
                    {
                        rc = ud.NonConstPointer(true);
                        if (ud.m_serial_number > 0)
                        {
                            g_attached_custom_user_datas[ud.m_serial_number] = ud;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Runtime.HostUtils.ExceptionReport(ex);
                }
            }
            return(rc);
        }
        /// <summary>
        /// Remove the userdata from this list
        /// </summary>
        /// <param name="userdata"></param>
        /// <returns>true if the user data was successfully removed</returns>
        public bool Remove(UserData userdata)
        {
            IntPtr const_ptr_onobject = m_parent.ConstPointer();
            IntPtr ptr_userdata       = userdata.NonConstPointer(false);
            bool   rc = UnsafeNativeMethods.ON_Object_DetachUserData(const_ptr_onobject, ptr_userdata);

            if (rc)
            {
                UserData.RemoveFromRuntimeList(userdata);
            }
            return(rc);
        }
Example #3
0
        /// <summary>
        /// If the userdata is already in a different UserDataList, it
        /// will be removed from that list and added to this list.
        /// </summary>
        /// <param name="userdata">Data element.</param>
        /// <returns>Whether this operation succeeded.</returns>
        public bool Add(UserData userdata)
        {
            if (!(userdata is SharedUserDictionary))
            {
                Type t = userdata.GetType();
                System.Reflection.ConstructorInfo constructor = t.GetConstructor(System.Type.EmptyTypes);
                if (!t.IsPublic || constructor == null)
                {
                    throw new ArgumentException("userdata must be a public class and have a parameterless constructor");
                }
            }
            IntPtr     pOnObject      = m_parent.ConstPointer();
            IntPtr     pUserData      = userdata.NonConstPointer(true);
            const bool detachIfNeeded = true;
            bool       rc             = UnsafeNativeMethods.ON_Object_AttachUserData(pOnObject, pUserData, detachIfNeeded);

            if (rc)
            {
                UserData.StoreInRuntimeList(userdata);
            }
            return(rc);
        }
 /// <summary>
 /// Remove the userdata from this list
 /// </summary>
 /// <param name="userdata"></param>
 /// <returns>true if the user data was successfully removed</returns>
 public bool Remove(UserData userdata)
 {
   IntPtr const_ptr_onobject = m_parent.ConstPointer();
   IntPtr ptr_userdata = userdata.NonConstPointer(false);
   bool rc = UnsafeNativeMethods.ON_Object_DetachUserData(const_ptr_onobject, ptr_userdata);
   if( rc )
     UserData.RemoveFromRuntimeList(userdata);
   return rc;
 }
 /// <summary>
 /// If the userdata is already in a different UserDataList, it
 /// will be removed from that list and added to this list.
 /// </summary>
 /// <param name="userdata">Data element.</param>
 /// <returns>Whether this operation succeeded.</returns>
 public bool Add(UserData userdata)
 {
   if (!(userdata is SharedUserDictionary))
   {
     Type t = userdata.GetType();
     System.Reflection.ConstructorInfo constructor = t.GetConstructor(Type.EmptyTypes);
     if (!t.IsPublic || constructor == null)
       throw new ArgumentException("userdata must be a public class and have a parameterless constructor");
   }
   IntPtr const_ptr_onobject = m_parent.ConstPointer();
   IntPtr ptr_userdata = userdata.NonConstPointer(true);
   const bool detach_if_needed = true;
   bool rc = UnsafeNativeMethods.ON_Object_AttachUserData(const_ptr_onobject, ptr_userdata, detach_if_needed);
   if (rc)
     UserData.StoreInRuntimeList(userdata);
   return rc;
 }