public override object GetValue(object component) { // To expand and display embedded instances, such as Props for SMS SCI classes. var val = ((ManagementBaseObjectW)component)[_property.Name]; if (val is ManagementBaseObject[]) { ManagementBaseObject[] props = (ManagementBaseObject[])val; ManagementBaseObjectW[] propvalues = new ManagementBaseObjectW[props.Length]; for (int i = 0; i < props.Length; i++) { propvalues[i] = new ManagementBaseObjectW(props[i]); } return(propvalues); } if (val is ManagementBaseObject) { ManagementBaseObject props = (ManagementBaseObject)val; ManagementBaseObjectW propvalue = new ManagementBaseObjectW(props); return(propvalue); } return(val); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is ManagementBaseObjectW) { ManagementBaseObjectW mObjectW = (ManagementBaseObjectW)value; // If PropertyName contains Name, return the value of the property foreach (PropertyData p in mObjectW.Properties) { if (p.Name.Contains("Name")) { return(p.Value.ToString()); } } // No match on Name. If PropertyName contains ID, return the value of the property foreach (PropertyData p in mObjectW.Properties) { if (p.Name.Contains("ID")) { return(p.Value.ToString()); } } // No match on Name or ID. If Property is key, return the value of the property foreach (PropertyData p in mObjectW.Properties) { foreach (QualifierData q in p.Qualifiers) { if (q.Name.Equals("key", StringComparison.InvariantCultureIgnoreCase)) { if (String.IsNullOrEmpty(p.Value.ToString())) { return(String.Empty); } else { return(p.Value.ToString()); } } } } // No matches. Return an empty string. return(String.Empty); } return(base.ConvertTo(context, culture, value, destinationType)); }
public ManagementBaseObjectPropertyDescriptor(ManagementBaseObjectW actualObject, PropertyData property) : base(property.Name, null) { _wrapperObject = actualObject; _property = property; if (_property.Origin == "___SYSTEM") { category = "System Properties"; } else { category = "Properties"; } }
public Type GetDotNetType() { if ((_property.Type == CimType.Object) && (_property.Value is ManagementBaseObject)) { if (_property.Value is ManagementClass) { return(typeof(ManagementClass)); } if (_property.Value is ManagementObject) { return(typeof(ManagementObject)); } return(typeof(ManagementBaseObject)); } return(ManagementBaseObjectW.GetTypeFor(_property.Type, _property.IsArray)); }