internal static object DynamicInvokeBoxedValuetypeReturn(out DynamicInvokeParamLookupType paramLookupType, object boxedValuetype, int index, RuntimeTypeHandle type, DynamicInvokeParamType paramType) { object finalObjectToReturn = boxedValuetype; EETypePtr eeType = type.ToEETypePtr(); bool nullable = RuntimeImports.RhIsNullable(eeType); if (finalObjectToReturn == null || nullable || paramType == DynamicInvokeParamType.Ref) { finalObjectToReturn = RuntimeImports.RhNewObject(eeType); if (boxedValuetype != null) { DynamicInvokeUnboxIntoActualNullable(finalObjectToReturn, boxedValuetype, eeType); } } if (nullable) { if (paramType == DynamicInvokeParamType.Ref) { if (s_nullableCopyBackObjects == null) { s_nullableCopyBackObjects = new object[s_parameters.Length]; } s_nullableCopyBackObjects[index] = finalObjectToReturn; s_parameters[index] = null; } } else { System.Diagnostics.Debug.Assert(finalObjectToReturn != null); if (paramType == DynamicInvokeParamType.Ref) { s_parameters[index] = finalObjectToReturn; } } paramLookupType = DynamicInvokeParamLookupType.ValuetypeObjectReturned; return(finalObjectToReturn); }
internal static object DynamicInvokeParamHelperCore(RuntimeTypeHandle type, out DynamicInvokeParamLookupType paramLookupType, out int index, DynamicInvokeParamType paramType) { index = s_curIndex++; int parametersLength = s_parameters != null ? s_parameters.Length : 0; if (index >= parametersLength) throw new System.Reflection.TargetParameterCountException(); object incomingParam = s_parameters[index]; // Handle default parameters if ((incomingParam == System.Reflection.Missing.Value) && paramType == DynamicInvokeParamType.In) { incomingParam = GetDefaultValue(type, index); // The default value is captured into the parameters array s_parameters[index] = incomingParam; } RuntimeTypeHandle widenAndCompareType = type; bool nullable = RuntimeImports.RhIsNullable(type.ToEETypePtr()); if (nullable) { widenAndCompareType = new RuntimeTypeHandle(RuntimeImports.RhGetNullableType(type.ToEETypePtr())); } if (widenAndCompareType.ToEETypePtr().IsPrimitive || type.ToEETypePtr().IsEnum) { // Nullable requires exact matching if (incomingParam != null) { if ((nullable || paramType == DynamicInvokeParamType.Ref) && incomingParam != null) { if (widenAndCompareType.ToEETypePtr() != incomingParam.EETypePtr) { throw CreateChangeTypeArgumentException(incomingParam.EETypePtr, type.ToEETypePtr()); } } else { if (widenAndCompareType.ToEETypePtr().CorElementType != incomingParam.EETypePtr.CorElementType) { System.Diagnostics.Debug.Assert(paramType == DynamicInvokeParamType.In); incomingParam = InvokeUtils.CheckArgument(incomingParam, widenAndCompareType.ToEETypePtr(), InvokeUtils.CheckArgumentSemantics.DynamicInvoke); } } } return DynamicInvokeBoxedValuetypeReturn(out paramLookupType, incomingParam, index, type, paramType); } else if (type.ToEETypePtr().IsValueType) { incomingParam = InvokeUtils.CheckArgument(incomingParam, type.ToEETypePtr(), InvokeUtils.CheckArgumentSemantics.DynamicInvoke); System.Diagnostics.Debug.Assert(s_parameters[index] == null || Object.ReferenceEquals(incomingParam, s_parameters[index])); return DynamicInvokeBoxedValuetypeReturn(out paramLookupType, incomingParam, index, type, paramType); } else { incomingParam = InvokeUtils.CheckArgument(incomingParam, widenAndCompareType.ToEETypePtr(), InvokeUtils.CheckArgumentSemantics.DynamicInvoke); System.Diagnostics.Debug.Assert(Object.ReferenceEquals(incomingParam, s_parameters[index])); paramLookupType = DynamicInvokeParamLookupType.IndexIntoObjectArrayReturned; return s_parameters; } }
internal static object DynamicInvokeBoxedValuetypeReturn(out DynamicInvokeParamLookupType paramLookupType, object boxedValuetype, int index, RuntimeTypeHandle type, DynamicInvokeParamType paramType) { object finalObjectToReturn = boxedValuetype; EETypePtr eeType = type.ToEETypePtr(); bool nullable = RuntimeImports.RhIsNullable(eeType); if (finalObjectToReturn == null || nullable || paramType == DynamicInvokeParamType.Ref) { finalObjectToReturn = RuntimeImports.RhNewObject(eeType); if (boxedValuetype != null) { DynamicInvokeUnboxIntoActualNullable(finalObjectToReturn, boxedValuetype, eeType); } } if (nullable) { if (paramType == DynamicInvokeParamType.Ref) { if (s_nullableCopyBackObjects == null) { s_nullableCopyBackObjects = new object[s_parameters.Length]; } s_nullableCopyBackObjects[index] = finalObjectToReturn; s_parameters[index] = null; } } else { System.Diagnostics.Debug.Assert(finalObjectToReturn != null); if (paramType == DynamicInvokeParamType.Ref) s_parameters[index] = finalObjectToReturn; } paramLookupType = DynamicInvokeParamLookupType.ValuetypeObjectReturned; return finalObjectToReturn; }
public static object DynamicInvokeParamHelperCore(RuntimeTypeHandle type, out DynamicInvokeParamLookupType paramLookupType, out int index, DynamicInvokeParamType paramType) { index = s_curIndex++; int parametersLength = s_parameters != null ? s_parameters.Length : 0; if (index >= parametersLength) { throw new System.Reflection.TargetParameterCountException(); } object incomingParam = s_parameters[index]; // Handle default parameters if ((incomingParam == System.Reflection.Missing.Value) && paramType == DynamicInvokeParamType.In) { incomingParam = GetDefaultValue(type, index); // The default value is captured into the parameters array s_parameters[index] = incomingParam; } RuntimeTypeHandle widenAndCompareType = type; bool nullable = RuntimeImports.RhIsNullable(type.ToEETypePtr()); if (nullable) { widenAndCompareType = new RuntimeTypeHandle(RuntimeImports.RhGetNullableType(type.ToEETypePtr())); } if (widenAndCompareType.ToEETypePtr().IsPrimitive || type.ToEETypePtr().IsEnum) { // Nullable requires exact matching if (incomingParam != null) { if ((nullable || paramType == DynamicInvokeParamType.Ref) && incomingParam != null) { if (widenAndCompareType.ToEETypePtr() != incomingParam.EETypePtr) { throw CreateChangeTypeArgumentException(incomingParam.EETypePtr, type.ToEETypePtr()); } } else { if (widenAndCompareType.ToEETypePtr().CorElementType != incomingParam.EETypePtr.CorElementType) { System.Diagnostics.Debug.Assert(paramType == DynamicInvokeParamType.In); incomingParam = InvokeUtils.CheckArgument(incomingParam, widenAndCompareType.ToEETypePtr(), InvokeUtils.CheckArgumentSemantics.DynamicInvoke); } } } return(DynamicInvokeBoxedValuetypeReturn(out paramLookupType, incomingParam, index, type, paramType)); } else if (type.ToEETypePtr().IsValueType) { incomingParam = InvokeUtils.CheckArgument(incomingParam, type.ToEETypePtr(), InvokeUtils.CheckArgumentSemantics.DynamicInvoke); System.Diagnostics.Debug.Assert(s_parameters[index] == null || Object.ReferenceEquals(incomingParam, s_parameters[index])); return(DynamicInvokeBoxedValuetypeReturn(out paramLookupType, incomingParam, index, type, paramType)); } else { incomingParam = InvokeUtils.CheckArgument(incomingParam, widenAndCompareType.ToEETypePtr(), InvokeUtils.CheckArgumentSemantics.DynamicInvoke); System.Diagnostics.Debug.Assert(Object.ReferenceEquals(incomingParam, s_parameters[index])); paramLookupType = DynamicInvokeParamLookupType.IndexIntoObjectArrayReturned; return(s_parameters); } }