Esempio n. 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);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets all metainfo concerning a given class and creates an empty block if not found
        /// </summary>
        /// <param name="target">The class name</param>
        /// <returns>All metainfo about a class</returns>
        private static MetaInfoEntry GetEntryForced(string target)
        {
            MetaInfoEntry entry = MetaInfo.GetEntry(target);

            if (entry == null)
            {
                entry = new MetaInfoEntry(target);
                _targets.Add(entry);
            }

            return(entry);
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets a list of all properties in a class, for which a value has been stored.
        /// All superclasses and implemented interfaces of the class are examined too.
        /// </summary>
        /// <param name="targetClass">The class</param>
        /// <returns>List of properties</returns>
        public static string[] GetProperties(Type targetClass)
        {
            // try to find appropriate value in super class
            ArrayList subjects   = new ArrayList();
            Type      targetType = targetClass;

            while (targetType != null)
            {
                string        fullName = targetType.FullName;
                MetaInfoEntry entry    = MetaInfo.GetEntry(fullName);
                if (entry != null)
                {
                    foreach (MetaInfoClass property in entry.Properties)
                    {
                        if (!subjects.Contains(property.Name))
                        {
                            subjects.Add(property.Name);
                        }
                    }
                }

                targetType = targetType.BaseType;
            }

            // try to find interfaces implemented by the target type
            foreach (Type implementedInterface in targetClass.GetInterfaces())
            {
                string[] interfaceProperties = MetaInfo.GetProperties(implementedInterface);
                foreach (string interfaceProperty in interfaceProperties)
                {
                    if (!subjects.Contains(interfaceProperty))
                    {
                        subjects.Add(interfaceProperty);
                    }
                }
            }

            return((string[])subjects.ToArray(typeof(string)));
        }