Example #1
0
 public static object GetObjectForVariant(Variant variant)
 {
     IntPtr ptr = UnsafeMethods.ConvertVariantByrefToPtr(ref variant);
     return System.Runtime.InteropServices.Marshal.GetObjectForNativeVariant(ptr);
 }
Example #2
0
 public static IntPtr ConvertVariantByrefToPtr(ref Variant value) { return s_convertVariantByrefToPtr(ref value); }
Example #3
0
        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);
            }
        }
Example #4
0
        // 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));
        }
Example #5
0
 public static unsafe IntPtr ConvertVariantByrefToPtr(ref Variant value)
 {
     return((IntPtr)System.Runtime.CompilerServices.Unsafe.AsPointer(ref value));
 }
Example #6
0
 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);
 }