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); var 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("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("SetAsNull"))); default: Debug.Assert(false, "Unexpected VarEnum"); return(null); } }