internal static string BuildGetRequest <T>(string reference, IEnumerable <string> fieldsToReturn) { if (String.IsNullOrEmpty(reference)) { throw new ArgumentNullException("reference", "The reference value for the object to get cannot be null or empty."); } if (fieldsToReturn != null && fieldsToReturn.Any()) { if (fieldsToReturn.Contains("ALL", StringComparer.OrdinalIgnoreCase)) { fieldsToReturn = typeof(T).GetTypeInfo().GetProperties().Where(x => !x.IsAttributeDefined <NotReadableAttribute>()).Select(x => x.Name); } else if (fieldsToReturn.Contains("BASIC", StringComparer.OrdinalIgnoreCase)) { fieldsToReturn = typeof(T).GetTypeInfo().GetProperties().Where(x => !x.IsAttributeDefined <NotReadableAttribute>()).Where(x => x.IsAttributeDefined <BasicAttribute>()).Select(x => x.Name); } } else { fieldsToReturn = typeof(T).GetTypeInfo().GetProperties().Where(x => !x.IsAttributeDefined <NotReadableAttribute>()).Where(x => x.IsAttributeDefined <BasicAttribute>()).Select(x => x.Name); } string Fields = String.Join(",", RefObject.RemoveRefProperty(fieldsToReturn)); //%2B is a plus sign, which indicates the basic fields in addition to the requested fields will be returned return($"{reference}?_return_fields%2B={Fields}"); }
/// <summary> /// Builds a full URL search request including the object type, the query, and the fields to return. /// </summary> /// <param name="resourceType">An actual infoblox class type.</param> /// <param name="searchType">The type of search to be performed.</param> /// <param name="searchField">The field to search on.</param> /// <param name="recordValue">The value to search for.</param> /// <returns></returns> internal static string BuildGetSearchRequest(Type resourceType, SearchType searchType, string searchField, string recordValue, IEnumerable <string> fieldsToReturn) { if (resourceType == null) { throw new ArgumentNullException("resourceType", "The resource type to get cannot be null."); } if (String.IsNullOrEmpty(searchField)) { throw new ArgumentNullException("searchField", "The field to search on cannot be null or empty."); } if (InfobloxSDKExtensionMethods.IsInfobloxType(resourceType)) { if (fieldsToReturn != null && fieldsToReturn.Any()) { if (fieldsToReturn.Contains("ALL", StringComparer.OrdinalIgnoreCase)) { fieldsToReturn = resourceType.GetTypeInfo().GetProperties().Where(x => !x.IsAttributeDefined <NotReadableAttribute>()).Select(x => x.Name); } else if (fieldsToReturn.Contains("BASIC", StringComparer.OrdinalIgnoreCase)) { fieldsToReturn = resourceType.GetTypeInfo().GetProperties().Where(x => !x.IsAttributeDefined <NotReadableAttribute>()).Where(x => x.IsAttributeDefined <BasicAttribute>()).Select(x => x.Name); } } else { fieldsToReturn = resourceType.GetTypeInfo().GetProperties().Where(x => !x.IsAttributeDefined <NotReadableAttribute>()).Where(x => x.IsAttributeDefined <BasicAttribute>()).Select(x => x.Name); } string Fields = String.Join(",", RefObject.RemoveRefProperty(fieldsToReturn)); MemberInfo[] Info = typeof(SearchType).GetTypeInfo().GetMember(searchType.ToString()); if (Info != null && Info.Length > 0) { string searchOperator = Info[0].GetCustomAttribute <DescriptionAttribute>().Description; if (searchType.IsSearchTypeAllowed(resourceType, searchField)) { return($"{resourceType.GetNameAttribute()}?{searchField.ToLower()}{searchOperator}{recordValue}&_return_fields%2B={Fields}"); } else { throw new Exception($"The search type {searchType.ToString()} is not allowed on field {searchField}"); } } else { throw new ArgumentException("Reflection evaluation on the search type object failed and no member info could be read."); } } else { throw new ArgumentException("The resource type must be an infoblox class."); } }