public virtual object Clone()
        {
            EntityPersistence entityClone = MemberwiseClone() as EntityPersistence;

            PropertyInfo[] properties = this.GetType().GetProperties();

            foreach (PropertyInfo property in properties)
            {
                if (EntityReflection.Instance.GetAttribute(property, typeof(NotClonablePropertyAttribute)) != null)
                {
                    continue;
                }

                if (property.PropertyType.IsSubclassOf(typeof(EntityPersistence)))
                {
                    PropertyInvisibleAttribute propertyInvisibleAttribute = EntityReflection.Instance.GetAttribute(property, typeof(PropertyInvisibleAttribute)) as PropertyInvisibleAttribute;

                    if (propertyInvisibleAttribute == null)
                    {
                        EntityPersistence entityPropertyValue = property.GetValue(this, null) as EntityPersistence;

                        if (entityPropertyValue != null)
                        {
                            property.SetValue(entityClone, entityPropertyValue.Clone(), null);
                        }
                    }
                }
                else
                if (property.PropertyType.Name == "IList")
                {
                    IList entityPropertyValueList = property.GetValue(this, null) as IList;

                    if (entityPropertyValueList != null)
                    {
                        List <EntityPersistence> listTarget = new List <EntityPersistence>(entityPropertyValueList.Count);

                        property.SetValue(entityClone, listTarget, null);

                        foreach (EntityPersistence objeto in entityPropertyValueList)
                        {
                            listTarget.Add((objeto as EntityPersistence).Clone() as EntityPersistence);
                        }
                    }
                }
            }

            return(entityClone);
        }
Example #2
0
        public virtual void CreateNewEntity()
        {
            entity = EntityReflection.Instance.GetNewEntity(typeof(T)) as T;

            entityClone = entity.Clone() as EntityPersistence;
        }