/// <summary> /// Enumerates the services supported in a Ads Service. /// </summary> /// <typeparam name="T">The Ads service being tested /// (e.g. <see cref="AdWordsService"/>)</typeparam> /// <param name="onServiceFound">The callback to be called when a matching /// service is found.</param> public static void EnumerateServices <T>(EnumerateServiceCallback onServiceFound) where T : AdsService { Type serviceType = typeof(T); // All the supported service types are defined as nested classes within the // service type. Each of the nested type has multiple ServiceSignature entries, // one per supported service. This allows user to create a service like: // // var campaignService = user.GetService(AdWordsService.v201607.CampaignService); Type[] versionTypes = serviceType.GetNestedTypes(); foreach (Type versionType in versionTypes) { FieldInfo[] serviceFields = versionType.GetFields (BindingFlags.Static | BindingFlags.Public); foreach (FieldInfo fieldInfo in serviceFields) { if (fieldInfo.FieldType == typeof(ServiceSignature)) { ServiceSignature value = (ServiceSignature)fieldInfo.GetValue(null); onServiceFound(value); } } } }
/// <summary> /// Enumerates the services supported in a Ads Service. /// </summary> /// <typeparam name="ServiceType">The Ads service being tested /// (e.g. <see cref="Services"/>)</typeparam> /// <param name="onServiceFound">The callback to be called when a matching /// service is found.</param> public static void EnumerateServices <ServiceType>(EnumerateServiceCallback onServiceFound) { SystemType serviceType = typeof(ServiceType); // All the supported service types are defined as nested classes within the // service type. Each of the nested type has multiple ServiceTemplate entries, // one per supported service. This allows user to create a service like: // // var campaignService = user.GetService(Services.V0.ReportingService); SystemType[] versionTypes = serviceType.GetNestedTypes(); foreach (SystemType versionType in versionTypes) { FieldInfo[] serviceFields = versionType.GetFields (BindingFlags.Static | BindingFlags.Public); foreach (FieldInfo fieldInfo in serviceFields) { onServiceFound(fieldInfo.FieldType); } } }