public static object GetObjectForVariant(Variant variant) { IntPtr ptr = UnsafeMethods.ConvertVariantByrefToPtr(ref variant); return System.Runtime.InteropServices.Marshal.GetObjectForNativeVariant(ptr); }
public static IntPtr ConvertVariantByrefToPtr(ref Variant value) { return s_convertVariantByrefToPtr(ref value); }
internal Expression InitializeArgumentVariant(MemberExpression variant, Expression parameter) { //NOTE: we must remember our variant //the reason is that argument order does not map exactly to the order of variants for invoke //and when we are doing clean-up we must be sure we are cleaning the variant we have initialized. _variant = variant; if (IsByRef) { // temp = argument // paramVariants._elementN.SetAsByrefT(ref temp) Debug.Assert(TempVariable == null); Expression argExpr = _argBuilder.MarshalToRef(parameter); TempVariable = Expression.Variable(argExpr.Type, null); return(Expression.Block( Expression.Assign(TempVariable, argExpr), Expression.Call( variant, Variant.GetByrefSetter(_targetComType & ~VarEnum.VT_BYREF), TempVariable ) )); } Expression argument = _argBuilder.Marshal(parameter); // we are forced to special case ConvertibleArgBuilder since it does not have // a corresponding _targetComType. if (_argBuilder is ConvertibleArgBuilder) { return(Expression.Call( variant, typeof(Variant).GetMethod(nameof(Variant.SetAsIConvertible)), argument )); } if (Variant.IsPrimitiveType(_targetComType) || (_targetComType == VarEnum.VT_DISPATCH) || (_targetComType == VarEnum.VT_UNKNOWN) || (_targetComType == VarEnum.VT_VARIANT) || (_targetComType == VarEnum.VT_RECORD) || (_targetComType == VarEnum.VT_ARRAY)) { // paramVariants._elementN.AsT = (cast)argN return(Expression.Assign( Expression.Property( variant, Variant.GetAccessor(_targetComType) ), argument )); } switch (_targetComType) { case VarEnum.VT_EMPTY: return(null); case VarEnum.VT_NULL: // paramVariants._elementN.SetAsNull(); return(Expression.Call(variant, typeof(Variant).GetMethod(nameof(Variant.SetAsNULL)))); default: Debug.Assert(false, "Unexpected VarEnum"); return(null); } }
// This method is intended for use through reflection and should not be used directly public static object GetObjectForVariant(Variant variant) { IntPtr ptr = UnsafeMethods.ConvertVariantByrefToPtr(ref variant); return(Marshal.GetObjectForNativeVariant(ptr)); }
public static unsafe IntPtr ConvertVariantByrefToPtr(ref Variant value) { return((IntPtr)System.Runtime.CompilerServices.Unsafe.AsPointer(ref value)); }
public void SetAsByrefVariant(ref Variant value) { Debug.Assert(IsEmpty); // The setter can only be called once as VariantClear might be needed otherwise VariantType = (VarEnum.VT_VARIANT | VarEnum.VT_BYREF); _typeUnion._unionTypes._byref = UnsafeMethods.ConvertVariantByrefToPtr(ref value); }