Пример #1
0
 /// <summary>
 /// Called whenever property in this virtual object changes
 /// </summary>
 /// <param name="aObject">
 /// Object related to change <see cref="IVirtualObject"/>
 /// </param>
 /// <param name="aProperty">
 /// Property that changed <see cref="VirtualProperty"/>
 /// </param>
 public virtual void Changed(IVirtualObject aObject, VirtualProperty aProperty)
 {
     if (onChange != null)
     {
         onChange(aObject, aProperty);
     }
 }
Пример #2
0
 /// <summary>
 /// Creates object properties for this object type
 /// </summary>
 protected void CreateObjectProperties()
 {
     properties = new VirtualProperty [ObjectType.Count];
     for (int i = 0; i < ObjectType.Count; i++)
     {
         properties[i] = new VirtualProperty(this, ObjectType[i].Name, ObjectType[i].PropertyType);
     }
 }
Пример #3
0
 /// <summary>
 /// Copies all data to object
 /// </summary>
 /// <param name="a_From">
 /// Source object <see cref="IVirtualObject"/>
 /// </param>
 /// <param name="a_To">
 /// Destination object <see cref="IVirtualObject"/>
 /// </param>
 public static void CopyDataTo(IVirtualObject a_From, IVirtualObject a_To)
 {
     if ((a_From == null) && (a_To == null))
     {
         return;
     }
     for (int i = 0; i < a_From.ObjectType.Count; i++)
     {
         VirtualProperty vp = a_To[a_From[i].Name];
         if (vp != null)
         {
             if (TypeValidator.IsCompatible(vp.PropertyType, a_From[i].PropertyType) == true)
             {
                 vp.Value = a_From[i].Value;
             }
         }
         vp = null;
     }
 }
Пример #4
0
        /// <summary>
        /// Copies all data to object
        /// </summary>
        /// <param name="a_From">
        /// Source object <see cref="System.Object"/>
        /// </param>
        /// <param name="a_To">
        /// Destination object <see cref="IVirtualObject"/>
        /// </param>
        public static void CopyDataFrom(object a_From, IVirtualObject a_To)
        {
            if ((a_From == null) && (a_To == null))
            {
                return;
            }

            foreach (PropertyInfo prop in a_From.GetType().GetProperties())
            {
                VirtualProperty vp = a_To[prop.Name];
                if ((prop != null) && (vp != null))
                {
                    if (prop.CanRead == true)
                    {
                        vp.Value = prop.GetValue(a_From, null);
                    }
                }
                vp = null;
            }
        }
Пример #5
0
        /// <summary>
        /// Adds property to ObjectType
        /// </summary>
        /// <param name="a_Name">
        /// Name of new property <see cref="System.String"/>
        /// </param>
        /// <param name="a_Type">
        /// Type of property value <see cref="System.Type"/>
        /// </param>
        /// <remarks>
        /// It results in Exception if this ObjectType is locked
        /// </remarks>
        public void AddProperty(string a_Name, System.Type a_Type)
        {
            if (ObjectType == null)
            {
                throw new ExceptionCantAddPropertyToVirtualObjectType();
            }
            ObjectType.AddMember(a_Name, a_Type);
            VirtualProperty[] newprops = new VirtualProperty [ObjectType.Count];
            properties.CopyTo(newprops, 0);
            int i = newprops.Length - 1;

            newprops[i] = new VirtualProperty(this, ObjectType[i].Name, ObjectType[i].PropertyType);
            // Help GC to be more proactive
            for (int j = 0; j < properties.Length; j++)
            {
                properties[j] = null;
            }
            properties = null;
            properties = newprops;
            newprops   = null;
        }
Пример #6
0
        /// <summary>
        /// Copies all data to object
        /// </summary>
        /// <param name="a_From">
        /// Source object <see cref="IVirtualObject"/>
        /// </param>
        /// <param name="a_To">
        /// Destination object <see cref="System.Object"/>
        /// </param>
        public static void CopyDataTo(IVirtualObject a_From, object a_To)
        {
            if ((a_From == null) && (a_To == null))
            {
                return;
            }

            foreach (PropertyInfo prop in a_To.GetType().GetProperties())
            {
                VirtualProperty vp = a_From[prop.Name];
                if ((prop != null) && (vp != null))
                {
                    if (prop.CanWrite == true)
                    {
                        if (TypeValidator.IsCompatible(vp.PropertyType, prop.PropertyType) == true)
                        {
                            prop.SetValue(a_To, vp.Value, null);
                        }
                    }
                }
                vp = null;
            }
        }