public static VariantComparisonResults Compare(object x, object y, int lcid, VariantComparisonFlags flags) { object dy; try { dy = VariantConverter.ChangeType(y, x.GetType()); } catch { dy = y; } return((VariantComparisonResults)VariantNativeMethods.VarCmp(ref x, ref dy, lcid, (uint)flags)); }
public static object ChangeType(object value, VARENUM vt, CultureInfo cultureInfo) { object result = null; var hr = cultureInfo == null ? VariantNativeMethods.VariantChangeType(ref result, ref value, VariantConversionFlags.NO_FLAGS, vt) : VariantNativeMethods.VariantChangeTypeEx(ref result, ref value, cultureInfo.LCID, VariantConversionFlags.NO_FLAGS, vt); if (HResult.Failed(hr)) { throw Marshal.GetExceptionForHR(hr); } return(result); }