using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Reflection; namespace IrcStates { public static class Extensions { public static Delegate CreateDelegate(this MethodInfo methodInfo, object target) { if (methodInfo == null) return null; var types = methodInfo.GetParameters().Select(p => p.ParameterType); Func getType; if (methodInfo.ReturnType == typeof(void)) { getType = Expression.GetActionType; } else { getType = Expression.GetFuncType; types = types.Concat(new[] {methodInfo.ReturnType}); } return methodInfo.IsStatic ? Delegate.CreateDelegate(getType(types.ToArray()), methodInfo) : Delegate.CreateDelegate(getType(types.ToArray()), target, methodInfo); } public static void Update(this Dictionary dict, Dictionary other) { if (dict == null || other == null || !other.Any()) return; foreach (var (key, value) in other) dict[key] = value; } } }