예제 #1
0
        private void Initialize(IActor actor)
        {
            // First get all public methods.
            MethodInfo[] allMethods = actor.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic);

            foreach (MethodInfo m in allMethods)
            {
                // Check if its a method handler.
                MessageHandlerAttribute messageAttribute = Attribute.GetCustomAttribute(m, typeof(MessageHandlerAttribute)) as MessageHandlerAttribute;

                if (messageAttribute != null)
                {
                    string messageName = messageAttribute.Name;

                    if (messageName == string.Empty)
                    {
                        messageName = m.Name;
                    }

                    // Store it.
                    if (!methods.ContainsKey(messageName))
                    {
                        MessagePrototype newPrototype = MessagePrototype.Create(messageName, m);

                        methods.Add(messageName, m);
                        prototypes.Add(messageName, newPrototype);
                    }
                }
            }

            returnArray = new MessagePrototype[prototypes.Count];
            prototypes.Values.CopyTo(returnArray, 0);

            // Handle the dispatch
            realCall = new MessageDebugger.DebugMessageDelegate(this.CallMethod);
        }
예제 #2
0
        private void Initialize(IActor actor)
        {
            // First get all public methods.
            MethodInfo[] allMethods = actor.GetType().GetMethods( BindingFlags.Public | BindingFlags.NonPublic );

            foreach (MethodInfo m in allMethods)
            {
                // Check if its a method handler.
                MessageHandlerAttribute messageAttribute = Attribute.GetCustomAttribute( m,typeof(MessageHandlerAttribute)) as MessageHandlerAttribute;

                if (messageAttribute != null)
                {
                    string messageName = messageAttribute.Name;

                    if (messageName == string.Empty)
                    {
                        messageName = m.Name;
                    }

                    // Store it.
                    if (!methods.ContainsKey(messageName))
                    {
                        MessagePrototype newPrototype = MessagePrototype.Create( messageName,m );

                        methods.Add( messageName,m );
                        prototypes.Add( messageName,newPrototype );
                    }
                }
            }

            returnArray = new MessagePrototype[ prototypes.Count ];
            prototypes.Values.CopyTo( returnArray,0 );

            // Handle the dispatch
            realCall = new MessageDebugger.DebugMessageDelegate( this.CallMethod );
        }