Changes

Jump to navigation Jump to search
Line 49: Line 49:     
===Patching static constructors===
 
===Patching static constructors===
The <tt>AccessTools</tt> methods for constructors (<tt>DeclaredConstructor</tt>, <tt>Constructor</tt>, and <tt>GetDeclaredConstructors</tt>) no longer match static constructors by default. Pass <tt>searchForStatic: true</tt> to the methods if needed.
+
The <tt>AccessTools</tt> methods for constructors (<tt>Constructor</tt>, <tt>DeclaredConstructor</tt>, and <tt>GetDeclaredConstructors</tt>) no longer match static constructors by default. Use the new <tt>searchForStatic</tt> argument if you need to match them:
 +
 
 +
<source lang="c#">
 +
// match static constructors only
 +
var method = AccessTools.Constructor(typeof(ExampleType), searchForStatic: true);
 +
 
 +
// match static *or* instance constructors
 +
var method =
 +
  AccessTools.Constructor(typeof(ExampleType), searchForStatic: true)
 +
  ?? AccessTools.Constructor(typeof(ExampleType));
 +
</source>
 +
 
 +
Note that Harmony no longer matches static constructors for a good reason — they're only called once for the type, so often static constructor patches won't work correctly.
    
===Patching virtual methods===
 
===Patching virtual methods===
translators
8,447

edits

Navigation menu