Example #1
0
        /// <summary>
        /// Gets the stored information for a class and property.
        /// Not only the class is examined, but also all superclasses and implemented interfaces.
        /// </summary>
        /// <param name="targetClass">The object about which information will be retrieved</param>
        /// <param name="property">The property in the class</param>
        /// <param name="subject">The type of information required</param>
        /// <param name="defaultValue">Default value if the information is not found</param>
        /// <returns>The information stored for this class, property and type, the default value if not found</returns>
        public static object GetAttributeDefault(Type targetClass, string property, string subject, object defaultValue)
        {
            // try to find appropriate value in super class
            Type targetType = targetClass;

            while (targetType != null)
            {
                string        target = targetType.FullName;
                MetaInfoEntry table  = MetaInfo.GetEntry(target);

                if (table != null)
                {
                    if (table.Contains(property, subject))
                    {
                        return(table.GetValue(property, subject));
                    }
                }

                targetType = targetType.BaseType;
            }

            // try to find an interface implemented by the target type
            foreach (Type implementedInterface in targetClass.GetInterfaces())
            {
                object attribute = MetaInfo.GetAttributeDefault(implementedInterface, property, subject, null);
                if (attribute != null)
                {
                    return(attribute);
                }
            }

            return(defaultValue);
        }
Example #2
0
        /// <summary>
        /// Gets the stored information for a string
        /// </summary>
        /// <param name="target">The string about which information will be retrieved</param>
        /// <param name="subject">The type of information required</param>
        /// <param name="defaultValue">Default value if the information is not found</param>
        /// <returns>The information stored for this class, property and type, the default value if not found</returns>
        public static object GetAttributeDefault(string target, string subject, object defaultValue)
        {
            MetaInfoEntry table = MetaInfo.GetEntry(target);

            if (table != null)
            {
                if (table.Contains(null, subject))
                {
                    return(table.GetValue(null, subject));
                }
            }

            return(defaultValue);
        }