public static WMISearchKey GetSearchKey(object p) { WMISearchKey res = null; foreach (PropertyInfo propertyInfo in p.GetType().GetProperties()) { WMIIgnore ignoreProp = propertyInfo.GetCustomAttribute <WMIIgnore>(); if (ignoreProp == null) { WMIProperty propAtt = propertyInfo.GetCustomAttribute <WMIProperty>(); if (propAtt != null) { if (propAtt.SearchKey) { res = new WMISearchKey { Name = propAtt.Name, Value = propertyInfo.GetValue(p) }; break; } } } } return(res); }
public static List <SearchKey> GetSearchKeys(object p) { List <SearchKey> res = new List <SearchKey>(); foreach (PropertyInfo propertyInfo in p.GetType().GetProperties()) { WMIIgnore ignoreProp = propertyInfo.GetCustomAttribute <WMIIgnore>(); if (ignoreProp == null) { WMISearchKey searchAttribute = propertyInfo.GetCustomAttribute <WMISearchKey>(); if (searchAttribute != null) { WMIProperty propAtt = propertyInfo.GetCustomAttribute <WMIProperty>(); if (propAtt != null) { res.Add(new SearchKey { Name = propAtt.Name, Value = propertyInfo.GetValue(p) }); } else { res.Add(new SearchKey { Name = propertyInfo.Name, Value = propertyInfo.GetValue(p) }); } } else { WMIProperty propAtt = propertyInfo.GetCustomAttribute <WMIProperty>(); if (propAtt != null) { if (propAtt.SearchKey) { res.Add(new SearchKey { Name = propAtt.Name, Value = propertyInfo.GetValue(p) }); } } } } } return(res); }