1+ using System . Collections . Generic ;
12using System . Reflection ;
23
34namespace Cpp2IL . Core . Model . Contexts ;
@@ -23,24 +24,76 @@ public InjectedMethodAnalysisContext(
2324 string name ,
2425 TypeAnalysisContext returnType ,
2526 MethodAttributes attributes ,
26- TypeAnalysisContext [ ] injectedParameterTypes ,
27- string [ ] ? injectedParameterNames = null ,
28- ParameterAttributes [ ] ? injectedParameterAttributes = null ,
29- MethodImplAttributes defaultImplAttributes = MethodImplAttributes . Managed ) : base ( null , parent )
27+ IEnumerable < TypeAnalysisContext > injectedParameterTypes ,
28+ IEnumerable < string > ? injectedParameterNames = null ,
29+ IEnumerable < ParameterAttributes > ? injectedParameterAttributes = null ,
30+ MethodImplAttributes implAttributes = MethodImplAttributes . Managed ) : this ( parent , name , returnType , attributes , GetParameters ( injectedParameterTypes , injectedParameterNames , injectedParameterAttributes ) , implAttributes )
31+ {
32+ }
33+
34+ public InjectedMethodAnalysisContext (
35+ TypeAnalysisContext parent ,
36+ string name ,
37+ TypeAnalysisContext returnType ,
38+ MethodAttributes attributes ,
39+ IEnumerable < ( TypeAnalysisContext Type , string ? Name , ParameterAttributes Attributes ) > parameters ,
40+ MethodImplAttributes implAttributes = MethodImplAttributes . Managed ) : base ( null , parent )
3041 {
3142 DefaultName = name ;
3243 DefaultReturnType = returnType ;
3344 DefaultAttributes = attributes ;
3445
35- for ( var i = 0 ; i < injectedParameterTypes . Length ; i ++ )
46+ var i = 0 ;
47+ foreach ( var ( parameterType , parameterName , parameterAttributes ) in parameters )
3648 {
37- var injectedParameterType = injectedParameterTypes [ i ] ;
38- var injectedParameterName = injectedParameterNames ? [ i ] ;
39- var injectedParameterAttribute = injectedParameterAttributes ? [ i ] ?? ParameterAttributes . None ;
40-
41- Parameters . Add ( new InjectedParameterAnalysisContext ( injectedParameterName , injectedParameterType , injectedParameterAttribute , i , this ) ) ;
49+ Parameters . Add ( new InjectedParameterAnalysisContext ( parameterName , parameterType , parameterAttributes , i , this ) ) ;
50+ i ++ ;
4251 }
4352
44- DefaultImplAttributes = defaultImplAttributes ;
53+ DefaultImplAttributes = implAttributes ;
54+ }
55+
56+ private static IEnumerable < ( TypeAnalysisContext Type , string ? Name , ParameterAttributes Attributes ) > GetParameters (
57+ IEnumerable < TypeAnalysisContext > parameterTypes ,
58+ IEnumerable < string > ? parameterNames = null ,
59+ IEnumerable < ParameterAttributes > ? parameterAttributes = null )
60+ {
61+ var typeEnumerator = parameterTypes . GetEnumerator ( ) ;
62+ var nameEnumerator = parameterNames ? . GetEnumerator ( ) ;
63+ var attributeEnumerator = parameterAttributes ? . GetEnumerator ( ) ;
64+ if ( nameEnumerator != null )
65+ {
66+ if ( attributeEnumerator != null )
67+ {
68+ while ( typeEnumerator . MoveNext ( ) && nameEnumerator . MoveNext ( ) && attributeEnumerator . MoveNext ( ) )
69+ {
70+ yield return ( typeEnumerator . Current , nameEnumerator . Current , attributeEnumerator . Current ) ;
71+ }
72+ }
73+ else
74+ {
75+ while ( typeEnumerator . MoveNext ( ) && nameEnumerator . MoveNext ( ) )
76+ {
77+ yield return ( typeEnumerator . Current , nameEnumerator . Current , ParameterAttributes . None ) ;
78+ }
79+ }
80+ }
81+ else
82+ {
83+ if ( attributeEnumerator != null )
84+ {
85+ while ( typeEnumerator . MoveNext ( ) && attributeEnumerator . MoveNext ( ) )
86+ {
87+ yield return ( typeEnumerator . Current , null , attributeEnumerator . Current ) ;
88+ }
89+ }
90+ else
91+ {
92+ while ( typeEnumerator . MoveNext ( ) )
93+ {
94+ yield return ( typeEnumerator . Current , null , ParameterAttributes . None ) ;
95+ }
96+ }
97+ }
4598 }
4699}
0 commit comments