/// <summary> /// registering public methods of object /// </summary> /// <param name="target"></param> /// <param name="targetName"></param> public void RegisterMethods(object target, string targetName = default) { if (target == default) { return; } var methods = target.GetType().GetMethods(); Type asyncAttrType = typeof(System.Runtime.CompilerServices.AsyncStateMachineAttribute); foreach (var m in methods) { if (!m.IsPublic || m.IsSpecialName || (m.DeclaringType == typeof(Object))) { continue; } var rm = new RpcMethod { Target = target, TargetName = targetName, MethodName = m.Name, Description = GetDesc(m), IsAsync = m.GetCustomAttributes(asyncAttrType, false).Length > 0, Parameters = m.GetParameters() }; rpcMethods.Add(rm); } }
/// <summary> /// ctor initialize basic access methods. /// </summary> public Router() { var rm = new RpcMethod { TargetName = "rpc", Target = this, MethodName = "GetMethods", Parameters = null, Description = "Описание всех доступных методов" }; rpcMethods.Add(rm); }
public RpcMetodInfo(RpcMethod rpcMethod) { if (rpcMethod is null) { throw new System.ArgumentNullException(nameof(rpcMethod)); } ObjName = rpcMethod.TargetName; MethodName = rpcMethod.MethodName; Description = rpcMethod.Description; IsAsync = rpcMethod.IsAsync; if (rpcMethod.ParametersLength > 0) { Parameters = new List <string>(rpcMethod.ParametersLength); foreach (var p in rpcMethod.Parameters) { Parameters.Add(GetParamInfo(p)); } } }