예제 #1
0
        /// <summary>
        /// Clone object to new object
        /// </summary>
        /// <returns></returns>
        public virtual object Clone()
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            bf.Serialize(ms, this);
            ms.Position = 0;
            object obj = bf.Deserialize(ms);

            ms.Close();

            NZBaseObject baseObject = obj as NZBaseObject;

            if (baseObject != null)
            {
                baseObject.m_owner = this.Owner;
            }

            return(obj);
        }
예제 #2
0
        /// <summary>
        /// When overridden in a derived class, sets the value of the component to a different value.
        /// </summary>
        /// <param name="component">The component with the property value that is to be set. </param><param name="value">The new value. </param>
        public override void SetValue(object component, object value)
        {
            try {
                PropertyInfo pi = component.GetType().GetProperty(this.Name);

                object       objValue   = pi.GetValue(component, null);
                NZBaseObject baseObject = objValue as NZBaseObject;
                if (baseObject == null)
                {
                    throw new InvalidDataException("Invalid NZBaseObject type.");
                }

                if (baseObject.CanConvertToStrongType(value))
                {
                    Type         valueType = objValue.GetType();
                    PropertyInfo piValue   = valueType.GetProperty("Value", BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance);
                    piValue.SetValue(objValue, value, null);
                }
            } catch (Exception err) {
                Console.WriteLine(err.Message);
                throw;
            }
        }