/// <summary> /// Generates dynamic parameters for the properties of an object /// </summary> /// <param name="objectType">The type of object to get the properties of</param> /// <param name="parameterSetName">The name of the parameter set these parameters will be part of</param> /// <param name="required">Specifies if these parameters are mandatory</param> /// <returns></returns> internal static IEnumerable <RuntimeDefinedParameter> ObjectTypeProperties(InfoBloxObjectsEnum objectType, IEnumerable <string> parameterSets) { PropertyInfo[] PropInfo = objectType.GetObjectType().GetTypeInfo().GetProperties().Where(x => x.GetCustomAttribute <ReadOnlyAttribute>() == null && x.Name != "_ref").ToArray(); List <RuntimeDefinedParameter> ParamList = new List <RuntimeDefinedParameter>(); foreach (PropertyInfo Property in PropInfo) { RuntimeDefinedParameter Param = new RuntimeDefinedParameter() { Name = Char.ToUpper(Property.Name.First()) + Property.Name.Substring(1), ParameterType = Property.PropertyType }; bool Mandatory = Property.GetCustomAttribute <RequiredAttribute>() != null; if (parameterSets != null && parameterSets.Any()) { foreach (string Set in parameterSets) { ParameterAttribute attr = new ParameterAttribute() { Mandatory = Mandatory, HelpMessage = $"The {Property.Name} property of the object.", ParameterSetName = Set }; Param.Attributes.Add(attr); } } else { Param.Attributes.Add(new ParameterAttribute() { Mandatory = Mandatory, HelpMessage = $"The {Property.Name} property of the object." }); } ParamList.Add(Param); } return(ParamList); }
internal static RuntimeDefinedParameter FieldsToReturn(InfoBloxObjectsEnum objectType, IEnumerable <string> parameterSets, bool required = false) { IEnumerable <string> FieldsToReturn = objectType.GetObjectType().GetTypeInfo().GetProperties().Where(x => !x.IsAttributeDefined <NotReadableAttribute>() && x.Name != "_ref").Select(x => x.Name); FieldsToReturn = RefObject.RemoveRefProperty(FieldsToReturn); List <string> Temp = FieldsToReturn.ToList(); Temp.AddRange(new string[] { "ALL", "BASIC" }); FieldsToReturn = Temp; RuntimeDefinedParameter Param = new RuntimeDefinedParameter() { Name = "FieldsToReturn", ParameterType = typeof(string[]) }; if (parameterSets != null && parameterSets.Any()) { foreach (string Set in parameterSets) { Param.Attributes.Add(new ParameterAttribute() { ParameterSetName = Set, Mandatory = required, HelpMessage = "Specify the fields to return." }); } } else { Param.Attributes.Add(new ParameterAttribute() { Mandatory = required, HelpMessage = "Specify the fields to return." }); } Param.Attributes.Add(new ValidateSetAttribute(FieldsToReturn.ToArray())); return(Param); }
/// <summary> /// Generates a search field which is a list of properties that can be /// searched on for an object /// </summary> /// <param name="ibxObject">The object whose properties will be enumerated to determine which can be searched on</param> /// <param name="required">Specifies if these parameters are mandatory</param> /// <returns></returns> internal static RuntimeDefinedParameter SearchField(InfoBloxObjectsEnum ibxObject, bool required = false) { //*** Build the list of properties that can be searched for an object RuntimeDefinedParameter Param = new RuntimeDefinedParameter() { Name = "SearchField", ParameterType = typeof(String) }; foreach (string Set in _PARAMETER_SETS) { Param.Attributes.Add(new ParameterAttribute() { ParameterSetName = Set, Mandatory = required, HelpMessage = "Select the field to search on." }); } Param.Attributes.Add(new ValidateSetAttribute(((IEnumerable <string>) typeof(SearchableAttribute).GetMethod("GetSearchableProperties").MakeGenericMethod(ibxObject.GetObjectType()).Invoke(typeof(SearchableAttribute), null)).ToArray())); return(Param); }
/// <summary> /// Generates dynamic parameters for the properties of an object. This defaults /// to the __AllParameterSets. /// </summary> /// <param name="objectType">The type of object to get the properties of</param> /// <param name="required">Specifies if these parameters are mandatory</param> /// <returns></returns> internal static IEnumerable <RuntimeDefinedParameter> ObjectTypeProperties(InfoBloxObjectsEnum objectType) { return(ObjectTypeProperties(objectType, new string[] { ParameterAttribute.AllParameterSets })); }
public static bool CanGlobalSearch(this InfoBloxObjectsEnum ibxObject) { return(((MemberInfo)(typeof(InfoBloxObjectsEnum).GetTypeInfo().GetMember(ibxObject.ToString())[0])).GetCustomAttribute <ObjectInfoAttribute>().SupportsGlobalSearch); }
public static string GetName(this InfoBloxObjectsEnum ibxObject) { return(((MemberInfo)(typeof(InfoBloxObjectsEnum).GetTypeInfo().GetMember(ibxObject.ToString())[0])).GetCustomAttribute <ObjectInfoAttribute>().Name); }