Example #1
0
        private void Build()
        {
            var souls =
                from type in typeof(ISoul).GetTypeInfo().Assembly.GetTypes()
                where type.GetTypeInfo().ImplementedInterfaces.Contains((typeof(ISoul)))
                select type;

            foreach (var message in souls)
            {
                var methods = message.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                foreach (var method in methods)
                {
                    if (_handlers.ContainsKey(method.Name))
                    {
                        throw new Exception($"Handlers can't have same name, method: {method.Name}");
                    }
                    _handlers.TryAdd(method.Name, DynamicDelegateStaticFactory.CreateMethodCaller(method));
                    var param = method.GetParameters();
                    _params.TryAdd(method.Name, param.Select(x => new ParameterDescriptor {
                        Name          = x.Name,
                        ParameterType = x.ParameterType
                    }).ToList());
                }
            }
        }
Example #2
0
        public void Initilize(Assembly assembly)
        {
            var methods = assembly.GetTypes()
                          .SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.Static))
                          .Where(m => m.GetCustomAttributes(typeof(HandleAttribute), false).Count() > 0)
                          .ToArray();

            foreach (var method in methods)
            {
                var attribute = method.GetCustomAttribute(typeof(HandleAttribute)) as HandleAttribute;
                _handlers.TryAdd(attribute.Id, DynamicDelegateStaticFactory.CreateMethodCaller(method));
            }
        }