@@ -23,6 +23,17 @@ public static bool AddPredefineMethodUsedContext<TFeature>(
2323 string methodId ) {
2424 return PredefineMethodUsedContext . Add ( methodId ) ;
2525 }
26+ static readonly Dictionary < string , bool > overwriteContextBoundCheck = [ ] ;
27+ public static void ForceOverrideContextBoundCheck < TFeature > (
28+ this TFeature _ ,
29+ string methodId , bool isContextBound ) {
30+ overwriteContextBoundCheck [ methodId ] = isContextBound ;
31+ }
32+ public static bool ForceOverrideContextBoundCheck < TFeature > (
33+ this TFeature _ ,
34+ MethodDefinition method , bool isContextBound ) {
35+ return overwriteContextBoundCheck [ method . GetIdentifier ( ) ] = isContextBound ;
36+ }
2637 private static bool ParamCheck ( MethodReferenceData referenceData , MethodDefinition callee , out bool shouldAddToCheckList ) {
2738 shouldAddToCheckList = true ;
2839 if ( ! callee . HasBody ) {
@@ -58,6 +69,10 @@ public static bool CheckUsedContextBoundField<TFeature>(
5869
5970 var methodId = checkMethod . GetIdentifier ( ) ;
6071
72+ if ( overwriteContextBoundCheck . TryGetValue ( methodId , out bool isContextBound ) ) {
73+ return isContextBound ;
74+ }
75+
6176 if ( useCache && checkUsedContextBountFieldCache . TryGetValue ( methodId , out bool value ) && value ) {
6277 return value ;
6378 }
@@ -150,25 +165,33 @@ public static bool CheckUsedContextBoundField<TFeature>(
150165 continue ;
151166 }
152167 foreach ( var callee in useds . ImplementedMethods ( ) ) {
153- if ( PredefineMethodUsedContext . Contains ( callee . GetIdentifier ( ) ) ) {
154- return CacheReturn ( true , useCache , methodId ) ;
155- }
156- if ( ParamCheck ( useds , callee , out var shouldAddToCheckList ) ) {
157- return CacheReturn ( true , useCache , methodId ) ;
158- }
159- if ( shouldAddToCheckList ) {
160- worklist . Push ( callee ) ;
168+
169+ if ( overwriteContextBoundCheck . TryGetValue ( callee . GetIdentifier ( ) , out bool isCalleeContextBound ) ) {
170+ if ( isCalleeContextBound ) {
171+ return CacheReturn ( true , useCache , methodId ) ;
172+ }
161173 }
162- if ( callee . Name == ".ctor" && callee . DeclaringType . Name . OrdinalStartsWith ( '<' ) ) {
163- foreach ( var autoGenerate in callee . DeclaringType . Methods ) {
164- if ( autoGenerate . Name == ".ctor" ) {
165- continue ;
166- }
167- if ( ParamCheck ( useds , autoGenerate , out shouldAddToCheckList ) ) {
168- return CacheReturn ( true , useCache , methodId ) ;
169- }
170- if ( shouldAddToCheckList ) {
171- worklist . Push ( autoGenerate ) ;
174+ else {
175+ if ( PredefineMethodUsedContext . Contains ( callee . GetIdentifier ( ) ) ) {
176+ return CacheReturn ( true , useCache , methodId ) ;
177+ }
178+ if ( ParamCheck ( useds , callee , out var shouldAddToCheckList ) ) {
179+ return CacheReturn ( true , useCache , methodId ) ;
180+ }
181+ if ( shouldAddToCheckList ) {
182+ worklist . Push ( callee ) ;
183+ }
184+ if ( callee . Name == ".ctor" && callee . DeclaringType . Name . OrdinalStartsWith ( '<' ) ) {
185+ foreach ( var autoGenerate in callee . DeclaringType . Methods ) {
186+ if ( autoGenerate . Name == ".ctor" ) {
187+ continue ;
188+ }
189+ if ( ParamCheck ( useds , autoGenerate , out shouldAddToCheckList ) ) {
190+ return CacheReturn ( true , useCache , methodId ) ;
191+ }
192+ if ( shouldAddToCheckList ) {
193+ worklist . Push ( autoGenerate ) ;
194+ }
172195 }
173196 }
174197 }
0 commit comments