Esempio n. 1
0
        /// <summary>
        /// Returns TRUE when the receiver and the other object have the same properties.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool IsEqual(IClone other)
        {
            //1. make sure that the 'other' object is pointing to a valid object
            if (null == other)
            {
                throw new COMException("Invalid objact.");
            }

            //2. verify the type of 'other'
            if (!(other is ClonableObjClass))
            {
                throw new COMException("Bad object type.");
            }

            ClonableObjClass otherClonable = (ClonableObjClass)other;

            //test that all ot the object's properties are the same.
            //please note the usage of IsEqual when using arcobjects components that
            //supports cloning
            if (otherClonable.Version == m_version &&
                otherClonable.Name == m_name &&
                otherClonable.ID == m_ID &&
                otherClonable.ManagedArray == m_arr &&
                ((IClone)otherClonable.SpatialReference).IsEqual((IClone)m_spatialRef) &&
                ((IClone)otherClonable.Point).IsEqual((IClone)m_point))
            {
                return(true);
            }

            return(false);
        }
    public void Test()
    {
      Console.WriteLine("Creating an instance of the clonable object.");
      ClonableObjClass cloneable = new ClonableObjClass();
      
      Console.WriteLine("Assigning properties");
      cloneable.SpatialReference = CreateGeographicSpatialReference();
      cloneable.Name = "test 1";
      cloneable.Point = new PointClass();
      cloneable.Point.PutCoords(35.02,31.4);

      cloneable.ManagedArray = new ArrayList();
      cloneable.ManagedArray.Add("One");
      cloneable.ManagedArray.Add("Two");
      cloneable.ManagedArray.Add("Three");

      Console.WriteLine("New object's properties");
      Console.WriteLine("-----------------------");
      Console.WriteLine("Name: " + cloneable.Name);
      Console.WriteLine("ID: " + cloneable.ID.ToString());
      Console.WriteLine("Version: " + cloneable.Version.ToString());
      Console.WriteLine("Array values: ");
      foreach (object obj in cloneable.ManagedArray)
      {
        Console.WriteLine((string)obj);
      }
      Console.WriteLine("Spatial Reference parameters:");
      Console.WriteLine("Name: " + cloneable.SpatialReference.Name);
      IGeographicCoordinateSystem gcs = (IGeographicCoordinateSystem)cloneable.SpatialReference;
      Console.WriteLine("Alias: " + gcs.Alias);
      Console.WriteLine("Datum: " + gcs.Datum.Name);
      Console.WriteLine("");


      Console.WriteLine("Cloning the object...");
      ClonableObjClass clonee = cloneable.Clone() as ClonableObjClass;
      Console.WriteLine("");
      Console.WriteLine("Cloned object's properties:");
      Console.WriteLine("---------------------------");
      Console.WriteLine("Name: " + clonee.Name);
      Console.WriteLine("ID: " + clonee.ID.ToString());
      Console.WriteLine("Version: " + clonee.Version.ToString());
      Console.WriteLine("Array values: ");
      foreach (object obj in clonee.ManagedArray)
      {
        Console.WriteLine((string)obj);
      }
      Console.WriteLine("Spatial Reference parameters:");
      Console.WriteLine("Name: " + clonee.SpatialReference.Name);
      gcs = (IGeographicCoordinateSystem)clonee.SpatialReference;
      Console.WriteLine("Alias: " + gcs.Alias);
      Console.WriteLine("Datum: " + gcs.Datum.Name);
      Console.WriteLine("");    
       
    }
Esempio n. 3
0
        /// <summary>
        /// Clones the receiver and assigns the result to clonee.
        /// <returns></returns>
        public IClone Clone()
        {
            //create a new instance of the object
            ClonableObjClass obj = new ClonableObjClass();

            //assign the properties of the new object with the current object's properties.
            //according to each 'Ref' property, the user need to decide whether to use deep cloning
            //or shallow cloning.
            obj.Assign(this);

            return((IClone)obj);
        }
Esempio n. 4
0
        /// <summary>
        /// Assigns the properties of src to the receiver.
        /// </summary>
        /// <param name="src"></param>
        public void Assign(IClone src)
        {
            //1. make sure that src is pointing to a valid object
            if (null == src)
            {
                throw new COMException("Invalid objact.");
            }

            //2. make sure that the type of src is of type 'ClonableObjClass'
            if (!(src is ClonableObjClass))
            {
                throw new COMException("Bad object type.");
            }

            //3. assign the properties of src to the current instance
            ClonableObjClass srcClonable = (ClonableObjClass)src;

            m_name    = srcClonable.Name;
            m_version = srcClonable.Version;
            m_ID      = new Guid(srcClonable.ID.ToString());

            //don't clone the spatial reference, since in this case we want both object to
            //reference the same spatial reference (for example like features in a featureclass
            //which share the same spatial reference)
            m_spatialRef = srcClonable.SpatialReference;

            //clone the point. Use deep cloning
            if (null == srcClonable.Point)
            {
                m_point = null;
            }
            else
            {
                IObjectCopy objectCopy = new ObjectCopyClass();
                object      obj        = objectCopy.Copy((object)srcClonable.Point);
                m_point = (IPoint)obj;
            }

            m_arr = (ArrayList)srcClonable.ManagedArray.Clone();
        }
    /// <summary>
    /// Clones the receiver and assigns the result to clonee.
    /// <returns></returns>
    public IClone Clone()
    {
      //create a new instance of the object
      ClonableObjClass obj = new ClonableObjClass();
      //assign the properties of the new object with the current object's properties.
      //according to each 'Ref' property, the user need to decide whether to use deep cloning
      //or shallow cloning. 
      obj.Assign(this);

      return (IClone)obj;
    }