private void AnalyzeServiceAndInterfaces(Type serviceType) { var tree = new InterfaceTree(serviceType); for (var i = 0; i < tree.Services.Count; i++) { var service = tree.Services[i]; var interfaceDescription = new InterfaceDescription(service.ServiceType); Services.Add(interfaceDescription); foreach (var method in ReflectionTools.GetMethods(service.ServiceType)) { if (!ServiceContract.IsServiceOperation(method)) { interfaceDescription.Methods.Add(CreateNonServiceOperation(service.ServiceType, method)); continue; } if (TryCreateMessage(method, out var message, out var error)) { interfaceDescription.Operations.Add(new OperationDescription( service.ServiceName, ServiceContract.GetServiceOperationName(method), message)); }
public void GetServiceOperationNameByAttribute(string?name, string expected) { var attribute = new OperationContractAttribute(); if (name != null) { attribute.Name = name; } ServiceContract.GetServiceOperationName("Empty", attribute).ShouldBe(expected); }
public void GetServiceNameByAttribute(string?name, string? @namespace, string expected) { var attribute = new ServiceContractAttribute(); if (name != null) { attribute.Name = name; } if (@namespace != null) { attribute.Namespace = @namespace; } var(typeName, attributeNamespace, attributeName) = ServiceContract.GetServiceNonGenericName(typeof(IServiceContract), attribute); typeName.ShouldBe(nameof(IServiceContract)); attributeNamespace.ShouldBe(@namespace); attributeName.ShouldBe(name); }
private static string GetClassName(Type serviceType, string?suffix = null) { var result = new StringBuilder() .Append(serviceType.Assembly.GetName().Name) .Append('.') .Append(ReflectionTools.GetNamespace(serviceType)) .Append('.') .Append(ReflectionTools.GetNonGenericName(serviceType)); var serviceGenericEnding = ServiceContract.GetServiceGenericEnding(serviceType); for (var i = 0; i < serviceGenericEnding.Count; i++) { result .Append('-') .Append(serviceGenericEnding[i]); } result.Append(suffix); return(result.ToString()); }
private void AnalyzeServiceAndInterfaces(Type serviceType) { foreach (var interfaceType in ReflectionTools.ExpandInterface(serviceType)) { var interfaceDescription = new InterfaceDescription(interfaceType); string?serviceName = null; if (ServiceContract.IsServiceContractInterface(interfaceType)) { serviceName = ServiceContract.GetServiceName(interfaceType); Services.Add(interfaceDescription); } else { Interfaces.Add(interfaceDescription); } foreach (var method in ReflectionTools.GetMethods(interfaceType)) { string?error; if (serviceName == null || !ServiceContract.IsServiceOperation(method)) { error = "Method {0}.{1}.{2} is not service operation.".FormatWith( ReflectionTools.GetNamespace(interfaceType), interfaceType.Name, method.Name); interfaceDescription.Methods.Add(new MethodDescription(method, error)); continue; } if (TryCreateMessage(method, out var message, out error)) { interfaceDescription.Operations.Add(new OperationDescription( serviceName, ServiceContract.GetServiceOperationName(method), message)); }
public void GetServiceName(Type serviceType, string expected) { ServiceContract.GetServiceName(serviceType).ShouldBe(expected); }
public void IsServiceOperation(Type serviceType, string methodName, bool expected) { var method = serviceType.InstanceMethod(methodName); ServiceContract.IsServiceOperation(method).ShouldBe(expected); }
public void IsServiceContractInterface(Type serviceType, bool expected) { ServiceContract.IsServiceContractInterface(serviceType).ShouldBe(expected); }
public void IsNativeGrpcService(Type serviceType, bool expected) { ServiceContract.IsNativeGrpcService(serviceType).ShouldBe(expected); }
public void IsServiceInstanceType(Type type, bool expected) { ServiceContract.IsServiceInstanceType(type).ShouldBe(expected); }