Example #1
0
        /// <summary>Creates a cloned object with the id set to 0.</summary>
        /// <returns>A new ContentDetail with the same Name and Value.</returns>
        public virtual ContentDetail Clone()
        {
            ContentDetail cloned = new ContentDetail();

            cloned.ID            = 0;
            cloned.Name          = this.Name;
            cloned.Meta          = this.Meta;
            cloned.BoolValue     = this.BoolValue;
            cloned.DateTimeValue = this.DateTimeValue;
            cloned.DoubleValue   = this.DoubleValue;
            cloned.IntValue      = this.IntValue;
            cloned.LinkedItem    = this.LinkedItem;

            if (ObjectValue == null)
            {
                cloned.ObjectValue = null;
            }
            else
            {
                if (ObjectValue is ICloneable)
                {
                    cloned.objectValue = (ObjectValue as ICloneable).Clone();
                }
                else if (ObjectValue.GetType().IsValueType)
                {
                    cloned.objectValue = ObjectValue;
                }
                else if (ObjectValue.GetType().IsSerializable)
                {
                    cloned.objectValue = ObjectCopier.Clone(ObjectValue);
                }
                else
                {
                    throw new InvalidDataException("Detail cannot be cloned: " + Name + " - " + ObjectValue.GetType().FullName);
                }
            }

            cloned.StringValue  = this.StringValue;
            cloned.ValueTypeKey = this.ValueTypeKey;
            return(cloned);
        }