/// <summary>
        /// Expert user tool that copies user data that has a positive
        /// CopyCount from the source object to a destination object.
        /// Generally speaking you don't need to use Copy().
        /// Simply rely on things like the copy constructors to do the right thing.
        /// </summary>
        /// <param name="source">A source object for the data.</param>
        /// <param name="destination">A destination object for the data.</param>
        public static void Copy(Runtime.CommonObject source, Runtime.CommonObject destination)
        {
            IntPtr const_source    = source.ConstPointer();
            IntPtr ptr_destination = destination.NonConstPointer();

            UnsafeNativeMethods.ON_Object_CopyUserData(const_source, ptr_destination);
        }
 /// <summary>
 /// Moves the user data.
 /// <para>See <see cref="MoveUserDataFrom"/> for more information.</para>
 /// </summary>
 /// <param name="objectToGetUserData">Object data source.</param>
 /// <param name="id">Target.</param>
 /// <param name="append">If the data should be appended or replaced.</param>
 public static void MoveUserDataTo(Runtime.CommonObject objectToGetUserData, Guid id, bool append)
 {
     if (id != Guid.Empty)
     {
         IntPtr const_ptr_onobject = objectToGetUserData.ConstPointer();
         UnsafeNativeMethods.ON_UserDataHolder_MoveUserDataTo(id, const_ptr_onobject, append);
     }
 }
        /// <summary>
        /// Moves the user data from objectWithUserData to a temporary data storage
        /// identifierd by the return Guid.  When MoveUserDataFrom returns, the
        /// objectWithUserData will not have any user data.
        /// </summary>
        /// <param name="objectWithUserData">Object with user data attached.</param>
        /// <returns>
        /// Guid identifier for storage of UserData that is held in a temporary list
        /// by this class. This function should be used in conjunction with MoveUserDataTo
        /// to transfer the user data to a different object.
        /// Returns Guid.Empty if there was no user data to transfer.
        /// </returns>
        public static Guid MoveUserDataFrom(Runtime.CommonObject objectWithUserData)
        {
            Guid   id = Guid.NewGuid();
            IntPtr const_ptr_onobject = objectWithUserData.ConstPointer();

            if (UnsafeNativeMethods.ON_UserDataHolder_MoveUserDataFrom(id, const_ptr_onobject))
            {
                return(id);
            }
            return(Guid.Empty);
        }
示例#4
0
        /// <summary>
        /// If the user-data 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>
        /// <since>5.0</since>
        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("user-data 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);
        }