ServiceMeta ServiceToMeta(Type type, int pos) { var test = type.GetCustomAttributes(); var serviceAttr = type.GetCustomAttributes() .FirstOrDefault(attr => attr.GetType().BaseType?.Name == "ServiceAttribute" || attr.GetType().Name == "ServiceAttribute"); var divisionalAttr = type.GetCustomAttributes() .FirstOrDefault(attr => attr.GetType().Name == "DivisionalAttribute"); var divisional = true; if (serviceAttr == null) { return(null); } if (divisionalAttr != null) { divisional = (bool)divisionalAttr.GetType().GetProperty("Divisional").GetValue(divisionalAttr, null); } var typeName = type.Name; var svcMeta = new ServiceMeta() { Id = (uint)pos + 1, Name = TypeNameToName(typeName, serviceAttr.GetType()), Type = ServiceTypeToEnum(serviceAttr.GetType()), Scope = ServiceNameToEnum(serviceAttr), Divisional = divisional, Multicast = serviceAttr.GetType().Name.Equals("SyncAttribute") && (bool)serviceAttr.GetType().GetProperty("Multicast").GetValue(serviceAttr, null), }; svcMeta.Methods = type.GetMethods().Select((m, p) => MethodToMeta(svcMeta, m, p)).Where(meta => meta != null).ToList(); return(svcMeta); }
MethodMeta MethodToMeta(ServiceMeta svcMeta, MethodInfo methodInfo, int pos) { return(new MethodMeta() { Name = methodInfo.Name, Id = (uint)pos + 1, Parameters = methodInfo.GetParameters().Select((paraInfo, i) => new ParameterMeta() { Name = paraInfo.Name, Type = paraInfo.ParameterType, Position = (uint)i, }).ToList(), ReturnType = methodInfo.ReturnType, ServiceMeta = svcMeta, }); }
MethodMeta MethodToMeta(ServiceMeta svcMeta, MethodInfo methodInfo, int pos) { return new MethodMeta() { Name = methodInfo.Name, Id = (uint)pos + 1, Parameters = methodInfo.GetParameters().Select((paraInfo, i) => new ParameterMeta() { Name = paraInfo.Name, Type = paraInfo.ParameterType, Position = (uint)i, }).ToList(), ReturnType = methodInfo.ReturnType, ServiceMeta = svcMeta, }; }
ServiceMeta ServiceToMeta(Type type, int pos) { var test = type.GetCustomAttributes(); var serviceAttr = type.GetCustomAttributes() .FirstOrDefault(attr => attr.GetType().BaseType?.Name == "ServiceAttribute" || attr.GetType().Name == "ServiceAttribute"); var divisionalAttr = type.GetCustomAttributes() .FirstOrDefault(attr => attr.GetType().Name == "DivisionalAttribute"); var divisional = true; if (serviceAttr == null) { return null; } if (divisionalAttr != null) { divisional = (bool) divisionalAttr.GetType().GetProperty("Divisional").GetValue(divisionalAttr, null); } var typeName = type.Name; var svcMeta = new ServiceMeta() { Id = (uint)pos+1, Name = TypeNameToName(typeName, serviceAttr.GetType()), Type = ServiceTypeToEnum(serviceAttr.GetType()), Scope = ServiceNameToEnum(serviceAttr), Divisional = divisional, Multicast = serviceAttr.GetType().Name.Equals("SyncAttribute") && (bool)serviceAttr.GetType().GetProperty("Multicast").GetValue(serviceAttr, null), }; svcMeta.Methods = type.GetMethods().Select((m, p) => MethodToMeta(svcMeta, m, p)).Where(meta => meta != null).ToList(); return svcMeta; }