protected PropertyValueFilter(string propertyName, object expectedPropertyValue, BehaviorOnNoMatch behaviorOnNoMatch) { PropertyName = propertyName; _behaviorOnNoMatch = behaviorOnNoMatch; OriginalExpectedPropertyValue = expectedPropertyValue; CimTypedExpectedPropertyValue = CimValueConverter.ConvertFromDotNetToCim(expectedPropertyValue); }
private static string ObjectToWqlLiteral(object o) { if (LanguagePrimitives.IsNull(o)) { return("null"); // based on an example at http://msdn.microsoft.com/library/aa394054(VS.85).aspx } o = CimValueConverter.ConvertFromDotNetToCim(o); PSObject pso = PSObject.AsPSObject(o); Type type = pso.BaseObject.GetType(); TypeCode typeCode = LanguagePrimitives.GetTypeCode(type); if (typeCode == TypeCode.String) { string s = o.ToString(); s = s.Replace("\\", "\\\\"); s = s.Replace("'", "\\'"); return("'" + s + "'"); } if (typeCode == TypeCode.Char) { return(ObjectToWqlLiteral(LanguagePrimitives.ConvertTo(o, typeof(string), CultureInfo.InvariantCulture))); } if (typeCode == TypeCode.DateTime) { var dateTime = (DateTime)LanguagePrimitives.ConvertTo(o, typeof(DateTime), CultureInfo.InvariantCulture); string result = ClrFacade.ToDmtfDateTime(dateTime); return("'" + result + "'"); } if (type == typeof(TimeSpan)) { // WMIv1 does not support using interval literals in a WQL query return(null); } if (LanguagePrimitives.IsNumeric(typeCode)) { return((string)LanguagePrimitives.ConvertTo(o, typeof(string), CultureInfo.InvariantCulture)); } if (LanguagePrimitives.IsBooleanType(type)) { if ((bool)LanguagePrimitives.ConvertTo(o, typeof(bool), CultureInfo.InvariantCulture)) { return("TRUE"); // based on http://msdn.microsoft.com/library/aa394054(VS.85).aspx } return("FALSE"); // based on http://msdn.microsoft.com/library/aa394054(VS.85).aspx } throw CimValueConverter.GetInvalidCastException( null, /* inner exception */ "InvalidCimQueryCast", o, CmdletizationResources.CimConversion_WqlQuery); }
internal static void SetCustomOption(CimOperationOptions operationOptions, string optionName, object optionValue) { if (optionValue != null) { object cim = CimValueConverter.ConvertFromDotNetToCim(optionValue); CimType cimType = CimConverter.GetCimType(CimValueConverter.GetCimType(optionValue.GetType())); operationOptions.SetCustomOption(optionName, cim, cimType, false); return; } else { return; } }
private IEnumerable <MethodParameter> GetMethodInputParametersCore(Func <MethodParameter, bool> filter) { IEnumerable <MethodParameter> enumerable = this._methodInvocationInfo.Parameters.Where <MethodParameter>(filter); List <MethodParameter> list = new List <MethodParameter>(); foreach (MethodParameter parameter in enumerable) { object obj2 = CimValueConverter.ConvertFromDotNetToCim(parameter.Value); Type cimType = CimValueConverter.GetCimType(parameter.ParameterType); MethodParameter item = new MethodParameter { Name = parameter.Name, ParameterType = cimType, Bindings = parameter.Bindings, Value = obj2, IsValuePresent = parameter.IsValuePresent }; list.Add(item); } return(list); }
private static string ObjectToWqlLiteral(object o) { if (!LanguagePrimitives.IsNull(o)) { o = CimValueConverter.ConvertFromDotNetToCim(o); PSObject pSObject = PSObject.AsPSObject(o); Type type = pSObject.BaseObject.GetType(); TypeCode typeCode = LanguagePrimitives.GetTypeCode(type); if (typeCode != TypeCode.String) { if (typeCode != TypeCode.Char) { if (typeCode != TypeCode.DateTime) { if (type != typeof(TimeSpan)) { if (!LanguagePrimitives.IsNumeric(typeCode)) { if (!LanguagePrimitives.IsBooleanType(type)) { throw CimValueConverter.GetInvalidCastException(null, "InvalidCimQueryCast", o, CmdletizationResources.CimConversion_WqlQuery); } else { if (!(bool)LanguagePrimitives.ConvertTo(o, typeof(bool), CultureInfo.InvariantCulture)) { return("FALSE"); } else { return("TRUE"); } } } else { return((string)LanguagePrimitives.ConvertTo(o, typeof(string), CultureInfo.InvariantCulture)); } } else { return(null); } } else { DateTime dateTime = (DateTime)LanguagePrimitives.ConvertTo(o, typeof(DateTime), CultureInfo.InvariantCulture); string dmtfDateTime = ManagementDateTimeConverter.ToDmtfDateTime(dateTime); return(string.Concat("'", dmtfDateTime, "'")); } } else { return(CimQuery.ObjectToWqlLiteral(LanguagePrimitives.ConvertTo(o, typeof(string), CultureInfo.InvariantCulture))); } } else { string str = o.ToString(); str = str.Replace("\\", "\\\\"); str = str.Replace("'", "\\'"); return(string.Concat("'", str, "'")); } } else { return("null"); } }