public static IEnumerable <DynamicIpcFunction> FromContext(IBaseIpcContext context) { var methods = context.GetType().GetMethods(); var interface_type = context.GetType().GetInterface("IBaseIpcContext"); foreach (var method in methods) { var attribute = (IpcFunctionAttribute)Attribute.GetCustomAttribute(method, typeof(IpcFunctionAttribute)); if (attribute == null && interface_type != null) { var interface_method = interface_type.GetMethod(method.Name); if (interface_method != null) { attribute = (IpcFunctionAttribute)Attribute.GetCustomAttribute(interface_method, typeof(IpcFunctionAttribute)); } } if (attribute == null) { continue; } if (string.IsNullOrWhiteSpace(attribute.Name)) { attribute = new IpcFunctionAttribute(method.Name); } yield return(FromAttribute(attribute, method.CreateDelegate(Expression.GetDelegateType( (from parameter in method.GetParameters() select parameter.ParameterType) .Concat(new[] { method.ReturnType }) .ToArray()), context))); } }
public static DynamicIpcFunction FromAttribute(IpcFunctionAttribute attrib, Delegate func) { return(new DynamicIpcFunction(attrib.Name, attrib.Identifiers.ToArray(), func)); }