/// <summary> /// Constructor for a gRPC client wrapper calling the code first gRPC <typeparamref name="TService"/>. /// </summary> /// <param name="serviceLookup">The service discovery <see cref="IServiceLookup"/> to use to find the service.</param> /// <exception cref="ArgumentException">When the <typeparamref name="TService"/> does not have the <see cref="DiscoverableGrpcServiceAttribute"/> applied /// or has multiple <see cref="DiscoverableGrpcServiceAttribute"/> applied within its inheritance hierarchy.</exception> public GrpcClient(IServiceLookup serviceLookup) { _serviceLookup = serviceLookup; Type serviceType = typeof(TService); IEnumerable <DiscoverableGrpcServiceAttribute> att = serviceType.GetCustomAttributes <DiscoverableGrpcServiceAttribute>(true); _serviceName = (att.Count()) switch { 0 => throw new ArgumentException($"The provided service {serviceType.FullName} is not discoverable. Add the 'DiscoverableGrpcService' attribute to the service interface."), 1 => att.First().ServiceName, _ => throw new ArgumentException($"The provided service {serviceType.FullName} has multiple 'DiscoverableGrpcService' attributes. Please ensure there is only one attribute applied to the service interface."), }; }
public static Entity LookupToEntity <Entity>(IServiceLookup source) where Entity : ILookup, new() { Entity lookup = BaseToEntity <Entity>(source); try { lookup.Name = source.name; } catch (Exception ex) { //Do nothing, some object might not have name } try { lookup.Description = source.description; } catch (Exception ex) { //Do nothing, some object might not have description } return(lookup); }