Exemple #1
0
        /// <summary>
        /// Retrieve properties from an entity.
        /// It is going higher in the inheritance.
        /// It is not going through entity references.
        /// </summary>
        /// <param name="entity">An entity.</param>
        /// <returns>A list of PropertyInfo.</returns>
        public static List <PropertyInfo> GetProperties(this EntityInfo entity)
        {
            var result = new List <PropertyInfo>();

            if (!entity.IsValid())
            {
                return(result);
            }

            var propertyComparer  = new PropertyInfoComparer();
            var referenceComparer = new ReferenceInfoComparer();

            if (entity.BaseEntity.IsValid())
            {
                foreach (var property in entity.BaseEntity.GetProperties())
                {
                    if (property.IsValid() &&
                        !result.Any(item =>
                                    propertyComparer.Equals(
                                        item,
                                        property)))
                    {
                        result.Add(property);
                    }
                }
            }

            if (entity.Properties != null)
            {
                foreach (var property in entity.Properties)
                {
                    if (property.IsValid() &&
                        !result.Any(item =>
                                    propertyComparer.Equals(
                                        item,
                                        property)))
                    {
                        result.Add(property);
                    }
                }
            }

            if (entity.References != null)
            {
                foreach (var reference in entity.References)
                {
                    if (reference.IsValid() &&
                        !result.Any(item =>
                                    referenceComparer.Equals(
                                        item,
                                        reference)))
                    {
                        result.Add(reference);
                    }
                }
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Retrieve all properties from an entity.
        /// It is going higher in the inheritance.
        /// It is going through entity references if it is not
        /// an abstract class and not a collection.
        /// </summary>
        /// <param name="entity">An entity.</param>
        /// <returns>A list of PropertyInfo.</returns>
        public static List <PropertyInfo> GetLinkedProperties(this EntityInfo entity)
        {
            var result = new List <PropertyInfo>();

            if (!entity.IsValid())
            {
                return(result);
            }

            var propertyComparer  = new PropertyInfoComparer();
            var referenceComparer = new ReferenceInfoComparer();

            if (entity.BaseEntity.IsValid())
            {
                foreach (var property in entity.BaseEntity.GetLinkedProperties())
                {
                    if (property.IsValid() &&
                        !result.Any(item =>
                                    propertyComparer.Equals(
                                        item,
                                        property)))
                    {
                        result.Add(property);
                    }
                }
            }

            if (entity.Properties != null)
            {
                foreach (var property in entity.Properties)
                {
                    if (property.IsValid() &&
                        !result.Any(item =>
                                    propertyComparer.Equals(
                                        item,
                                        property)))
                    {
                        result.Add(property);
                    }
                }
            }

            if (entity.References != null)
            {
                foreach (var reference in entity.References)
                {
                    if (reference.IsValid() &&
                        reference.Target.IsValid() &&
                        !reference.Target.IsAbstract &&
                        !reference.IsCollection)
                    {
                        if (reference.Target.IsEnum &&
                            !result.Any(item =>
                                        referenceComparer.Equals(
                                            item,
                                            reference)))
                        {
                            result.Add(reference);
                        }
                        else
                        {
                            foreach (var property in reference.Target.GetLinkedProperties())
                            {
                                if (property.IsValid() &&
                                    !result.Any(item =>
                                                propertyComparer.Equals(
                                                    item,
                                                    property)))
                                {
                                    result.Add(property);
                                }
                            }
                        }
                    }
                    else if (reference.IsValid() &&
                             !result.Any(item =>
                                         referenceComparer.Equals(
                                             item,
                                             reference)))
                    {
                        result.Add(reference);
                    }
                }
            }

            return(result);
        }