Esempio n. 1
0
        /// <summary>
        /// Get the (unextended) container type associated with a type
        /// </summary>
        /// <param name="t">The type</param>
        /// <returns>The associated unextended type</returns>
        public static Type UnextendedType(this Type t)
        {
            Type res = t;

            if (res.IsGenericType())
            {
                res = res.GetGenericArguments().First();
            }
            res = res.UnproxiedType();
            res = TypeExtender.BaseType(res);
            return(res);
        }
        protected override IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
        {
            IList <JsonProperty> properties = base.CreateProperties(type, memberSerialization);

            var baseType = TypeExtender.BaseType(type);

            if (type == baseType)
            {
                return(properties);
            }
            else
            {
                var baseTypeProps = baseType.GetProperties().Select(pi => pi.Name).ToList();
                return(properties.Where(p => baseTypeProps.Contains(p.PropertyName)).ToList());
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Get a list of (only) the properties of a container type which are required
        /// to generate a summary.
        /// </summary>
        /// <param name="containerType">The container type</param>
        /// <returns>List of PropertyInfos of the properties required to generate a summary</returns>
        public List <PropertyInfo> ContainerSummaryFields(Type containerType)
        {
            Type baseType          = TypeExtender.BaseType(containerType);
            var  excludedPropNames = new List <string>();

            if (baseType.GetCustomAttribute <SummaryTypeAttribute>() != null) // has a declared summary type
            {
                // Exclude all properties in the base type which aren't marked as in the summary
                excludedPropNames = baseType.GetPersistedProperties()
                                    .Where(pi => pi.GetCustomAttribute <SummaryAttribute>() == null &&
                                           pi.GetCustomAttribute <AddressComponentAttribute>() == null &&
                                           pi.GetCustomAttribute <KeyAttribute>() == null)
                                    .Select(pi => pi.Name)
                                    .ToList();
            }

            return(containerType.GetPersistedProperties()
                   .Where(pi => !excludedPropNames.Contains(pi.Name) && pi.GetCustomAttribute <NotSummarisedAttribute>() == null)
                   .ToList());
        }