/// <summary> /// Loads the <see cref="ManagementObject"/> into <typeparamref name="T"/> /// </summary> /// <typeparam name="T"></typeparam> /// <param name="wmiObject"></param> /// <returns></returns> internal static T LoadType <T>(ManagementObject wmiObject) { var o = Activator.CreateInstance <T>(); foreach (PropertyInfo p in o.GetType().GetProperties()) { WmiIgnoreAttribute ignore = p.GetCustomAttribute <WmiIgnoreAttribute>(); if (ignore != null) { continue; } WmiPropertyAttribute propAtt = p.GetCustomAttribute <WmiPropertyAttribute>(); string propertyName = p.Name; if (propAtt != null) { propertyName = propAtt.Name; } var value = wmiObject.Properties[propertyName].Value; SetPropertyValue(p, wmiObject, o); } return(o); }
/// <summary> /// Gets all properties from <typeparamref name="T"/> that are queryable. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> internal static string GetSearchableProperties <T>() { List <string> properties = new List <string>(); foreach (PropertyInfo propertyInfo in typeof(T).GetProperties()) { WmiIgnoreAttribute ignoreProp = propertyInfo.GetCustomAttribute <WmiIgnoreAttribute>(); if (ignoreProp == null) { WmiPropertyAttribute propAtt = propertyInfo.GetCustomAttribute <WmiPropertyAttribute>(); if (propAtt == null) { properties.Add(propertyInfo.Name.ToUpper()); } else { properties.Add(propAtt.Name.ToUpper()); } } } return(String.Join(",", properties)); }