@@ -74,37 +74,36 @@ public unsafe DynamicInvokeInfo(MethodBase method, IntPtr invokeThunk)
74
74
{
75
75
Transform transform = default ;
76
76
77
- var argumentType = ( RuntimeType ) parameters [ i ] . ParameterType ;
77
+ Type argumentType = parameters [ i ] . ParameterType ;
78
78
if ( argumentType . IsByRef )
79
79
{
80
80
_needsCopyBack = true ;
81
81
transform |= Transform . ByRef ;
82
- argumentType = ( RuntimeType ) argumentType . GetElementType ( ) ! ;
82
+ argumentType = argumentType . GetElementType ( ) ! ;
83
83
}
84
84
Debug . Assert ( ! argumentType . IsByRef ) ;
85
85
86
- // This can return a null MethodTable for reference types.
87
- // The compiler makes sure it returns a non-null MT for everything else.
88
- MethodTable * eeArgumentType = argumentType . ToMethodTableMayBeNull ( ) ;
89
- if ( argumentType . IsValueType )
86
+ MethodTable * eeArgumentType = argumentType . TypeHandle . ToMethodTable ( ) ;
87
+
88
+ if ( eeArgumentType ->IsValueType )
90
89
{
91
- Debug . Assert ( eeArgumentType -> IsValueType ) ;
90
+ Debug . Assert ( argumentType . IsValueType ) ;
92
91
93
92
if ( eeArgumentType ->IsByRefLike )
94
93
_argumentCount = ArgumentCount_NotSupported_ByRefLike ;
95
94
96
95
if ( eeArgumentType ->IsNullable )
97
96
transform |= Transform . Nullable ;
98
97
}
99
- else if ( argumentType . IsPointer )
98
+ else if ( eeArgumentType -> IsPointer )
100
99
{
101
- Debug . Assert ( eeArgumentType -> IsPointer ) ;
100
+ Debug . Assert ( argumentType . IsPointer ) ;
102
101
103
102
transform |= Transform . Pointer ;
104
103
}
105
- else if ( argumentType . IsFunctionPointer )
104
+ else if ( eeArgumentType -> IsFunctionPointer )
106
105
{
107
- Debug . Assert ( eeArgumentType -> IsFunctionPointer ) ;
106
+ Debug . Assert ( argumentType . IsFunctionPointer ) ;
108
107
109
108
transform |= Transform . FunctionPointer ;
110
109
}
@@ -122,18 +121,19 @@ public unsafe DynamicInvokeInfo(MethodBase method, IntPtr invokeThunk)
122
121
{
123
122
Transform transform = default ;
124
123
125
- var returnType = ( RuntimeType ) methodInfo . ReturnType ;
124
+ Type returnType = methodInfo . ReturnType ;
126
125
if ( returnType . IsByRef )
127
126
{
128
127
transform |= Transform . ByRef ;
129
- returnType = ( RuntimeType ) returnType . GetElementType ( ) ! ;
128
+ returnType = returnType . GetElementType ( ) ! ;
130
129
}
131
130
Debug . Assert ( ! returnType . IsByRef ) ;
132
131
133
- MethodTable * eeReturnType = returnType . ToMethodTableMayBeNull ( ) ;
134
- if ( returnType . IsValueType )
132
+ MethodTable * eeReturnType = returnType . TypeHandle . ToMethodTable ( ) ;
133
+
134
+ if ( eeReturnType ->IsValueType )
135
135
{
136
- Debug . Assert ( eeReturnType -> IsValueType ) ;
136
+ Debug . Assert ( returnType . IsValueType ) ;
137
137
138
138
if ( returnType != typeof ( void ) )
139
139
{
@@ -152,17 +152,17 @@ public unsafe DynamicInvokeInfo(MethodBase method, IntPtr invokeThunk)
152
152
_argumentCount = ArgumentCount_NotSupported ; // ByRef to void return
153
153
}
154
154
}
155
- else if ( returnType . IsPointer )
155
+ else if ( eeReturnType -> IsPointer )
156
156
{
157
- Debug . Assert ( eeReturnType -> IsPointer ) ;
157
+ Debug . Assert ( returnType . IsPointer ) ;
158
158
159
159
transform |= Transform . Pointer ;
160
160
if ( ( transform & Transform . ByRef ) == 0 )
161
161
transform |= Transform . AllocateReturnBox ;
162
162
}
163
- else if ( returnType . IsFunctionPointer )
163
+ else if ( eeReturnType -> IsFunctionPointer )
164
164
{
165
- Debug . Assert ( eeReturnType -> IsFunctionPointer ) ;
165
+ Debug . Assert ( returnType . IsFunctionPointer ) ;
166
166
167
167
transform |= Transform . FunctionPointer ;
168
168
if ( ( transform & Transform . ByRef ) == 0 )
@@ -585,12 +585,6 @@ private unsafe ref byte InvokeDirectWithFewArguments(
585
585
return defaultValue ;
586
586
}
587
587
588
- private void ThrowForNeverValidNonNullArgument ( MethodTable * srcEEType , int index )
589
- {
590
- Debug . Assert ( index != 0 || _isStatic ) ;
591
- throw InvokeUtils . CreateChangeTypeArgumentException ( srcEEType , Method . GetParametersAsSpan ( ) [ index - ( _isStatic ? 0 : 1 ) ] . ParameterType , destinationIsByRef : false ) ;
592
- }
593
-
594
588
private unsafe void CheckArguments (
595
589
Span < object ? > copyOfParameters ,
596
590
void * byrefParameters ,
@@ -630,25 +624,16 @@ private unsafe void CheckArguments(
630
624
MethodTable * srcEEType = arg . GetMethodTable ( ) ;
631
625
MethodTable * dstEEType = argumentInfo . Type ;
632
626
633
- if ( srcEEType != dstEEType )
634
- {
635
- // Destination type can be null if we don't have a MethodTable for this type. This means one cannot
636
- // possibly pass a valid non-null object instance here.
637
- if ( dstEEType == null )
638
- {
639
- ThrowForNeverValidNonNullArgument ( srcEEType , i ) ;
640
- }
641
-
642
- if ( ! ( RuntimeImports . AreTypesAssignable ( srcEEType , dstEEType ) ||
643
- ( dstEEType ->IsInterface && arg is System . Runtime . InteropServices . IDynamicInterfaceCastable castable
627
+ if ( ! ( srcEEType == dstEEType ||
628
+ RuntimeImports . AreTypesAssignable ( srcEEType , dstEEType ) ||
629
+ ( dstEEType ->IsInterface && arg is System . Runtime . InteropServices . IDynamicInterfaceCastable castable
644
630
&& castable . IsInterfaceImplemented ( new RuntimeTypeHandle ( dstEEType ) , throwIfNotImplemented : false ) ) ) )
645
- {
646
- // ByRefs have to be exact match
647
- if ( ( argumentInfo . Transform & Transform . ByRef ) != 0 )
648
- throw InvokeUtils . CreateChangeTypeArgumentException ( srcEEType , argumentInfo . Type , destinationIsByRef : true ) ;
631
+ {
632
+ // ByRefs have to be exact match
633
+ if ( ( argumentInfo . Transform & Transform . ByRef ) != 0 )
634
+ throw InvokeUtils . CreateChangeTypeArgumentException ( srcEEType , argumentInfo . Type , destinationIsByRef : true ) ;
649
635
650
- arg = InvokeUtils . CheckArgumentConversions ( arg , argumentInfo . Type , InvokeUtils . CheckArgumentSemantics . DynamicInvoke , binderBundle ) ;
651
- }
636
+ arg = InvokeUtils . CheckArgumentConversions ( arg , argumentInfo . Type , InvokeUtils . CheckArgumentSemantics . DynamicInvoke , binderBundle ) ;
652
637
}
653
638
654
639
if ( ( argumentInfo . Transform & Transform . Reference ) == 0 )
@@ -707,25 +692,16 @@ private unsafe void CheckArguments(
707
692
MethodTable * srcEEType = arg . GetMethodTable ( ) ;
708
693
MethodTable * dstEEType = argumentInfo . Type ;
709
694
710
- if ( srcEEType != dstEEType )
711
- {
712
- // Destination type can be null if we don't have a MethodTable for this type. This means one cannot
713
- // possibly pass a valid non-null object instance here.
714
- if ( dstEEType == null )
715
- {
716
- ThrowForNeverValidNonNullArgument ( srcEEType , i ) ;
717
- }
718
-
719
- if ( ! ( RuntimeImports . AreTypesAssignable ( srcEEType , dstEEType ) ||
720
- ( dstEEType ->IsInterface && arg is System . Runtime . InteropServices . IDynamicInterfaceCastable castable
695
+ if ( ! ( srcEEType == dstEEType ||
696
+ RuntimeImports . AreTypesAssignable ( srcEEType , dstEEType ) ||
697
+ ( dstEEType ->IsInterface && arg is System . Runtime . InteropServices . IDynamicInterfaceCastable castable
721
698
&& castable . IsInterfaceImplemented ( new RuntimeTypeHandle ( dstEEType ) , throwIfNotImplemented : false ) ) ) )
722
- {
723
- // ByRefs have to be exact match
724
- if ( ( argumentInfo . Transform & Transform . ByRef ) != 0 )
725
- throw InvokeUtils . CreateChangeTypeArgumentException ( srcEEType , argumentInfo . Type , destinationIsByRef : true ) ;
699
+ {
700
+ // ByRefs have to be exact match
701
+ if ( ( argumentInfo . Transform & Transform . ByRef ) != 0 )
702
+ throw InvokeUtils . CreateChangeTypeArgumentException ( srcEEType , argumentInfo . Type , destinationIsByRef : true ) ;
726
703
727
- arg = InvokeUtils . CheckArgumentConversions ( arg , argumentInfo . Type , InvokeUtils . CheckArgumentSemantics . DynamicInvoke , binderBundle : null ) ;
728
- }
704
+ arg = InvokeUtils . CheckArgumentConversions ( arg , argumentInfo . Type , InvokeUtils . CheckArgumentSemantics . DynamicInvoke , binderBundle : null ) ;
729
705
}
730
706
731
707
if ( ( argumentInfo . Transform & Transform . Reference ) == 0 )
0 commit comments