public Type GenerateType(string endpoint) { Assembly assembly = Assembly.GetAssembly(GetType()); Type[] types = assembly.GetTypes(); Type correctType = null; foreach (var type in types) { ApiEndpointAttribute attribute = type.GetCustomAttributes(true) .OfType <ApiEndpointAttribute>() .FirstOrDefault(); if (attribute == null || attribute.EndpointUri != endpoint) { continue; } correctType = type; break; } if (correctType == null) { throw new ArgumentException("Could not find endpoint defined with this name"); } return(correctType); }
public FluentApi(IEndpointResolver endpointResolver) { _endpointResolver = endpointResolver; ApiEndpointAttribute attribute = typeof(T).GetCustomAttributes(true) .OfType <ApiEndpointAttribute>() .FirstOrDefault(); if (attribute == null) { throw new ArgumentException(string.Format("The Type {0} cannot be used in this way, it has no ApiEndpointAttribute", typeof(T))); } _endPointInfo.Uri = attribute.EndpointUri; }