Ejemplo n.º 1
0
        /// <summary>
        /// Gets the handler collection for the specified object.  This collection
        /// contains all of the methods tagged with the [PropertyHandler] attribute.
        /// </summary>
        /// <param name="sourceObject">The source object for which to get the
        /// collection</param>
        /// <returns>The property handler collection</returns>
        public static ObjectProperyHandlerDictionary GetHandlerCollection(object sourceObject)
        {
            ObjectProperyHandlerDictionary objects = new ObjectProperyHandlerDictionary();

            // Get all of the methods of the type and look for ones that have the [DBQuery] attached.
            Type sourceType = sourceObject.GetType();
            MethodInfo[] methods = sourceType.GetMethods (
                BindingFlags.Public | BindingFlags.NonPublic |
                BindingFlags.Static | BindingFlags.Instance);
            foreach (MethodInfo method in methods)
            {
                // Try to get the method's [PropertyHandler] attribute.  If it
                // doesn't have one then ignore it.
                Attribute[] atts = method.GetCustomAttributes (
                    typeof (PropertyHandlerAttribute), false) as Attribute[];
                if (null == atts || 0 == atts.Length) continue;

                // Create a delegate for the method.
                PropertyHandler handler = (PropertyHandler) (method.IsStatic ?
                    PropertyHandler.CreateDelegate (typeof (PropertyHandler), method) :
                    PropertyHandler.CreateDelegate(typeof (PropertyHandler), sourceObject, method.Name));

                // Add the handler once for each property it handles.  Handlers may
                // handle more than one property thus the attribute array may have
                // multiple entries.
                foreach (Attribute att in atts)
                {
                    PropertyHandlerAttribute handlerAtt = (PropertyHandlerAttribute) att;

                    // Look up the handler dictionary for the object, if there isn't one
                    // yet then create on.
                    PropertyHandlerDictionary handlers = objects[handlerAtt.Object];
                    if (null == handlers)
                    {
                        handlers = new PropertyHandlerDictionary(handlerAtt.Object);
                        objects.Add(handlerAtt.Object, handlers);
                    }

                    handlers.Add(handlerAtt.Property, handler);
                }
            }

            return objects;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds a handler to the collection
 /// </summary>
 /// <param name="obj">The object that the handlers handle properties for</param>
 /// <param name="handlers">The handler collection</param>
 public void Add(string obj, PropertyHandlerDictionary handlers)
 {
     InnerHashtable.Add(obj.ToLower(), handlers);
 }