Files
pardeike-Harmony/docs/api/HarmonyLib.AccessTools.FieldRef-2.html
Andreas Pardeike 0072943ba5 draft for docs
2025-08-23 00:31:53 +02:00

467 lines
18 KiB
HTML

<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Delegate AccessTools.FieldRef&lt;T, F&gt;
</title>
<meta name="viewport" content="width=device-width">
<meta name="title" content="Delegate AccessTools.FieldRef&lt;T, F&gt;
">
<meta name="generator" content="docfx 2.48.1.0">
<link rel="shortcut icon" href="../favicon.ico">
<link rel="stylesheet" href="../styles/docfx.vendor.css">
<link rel="stylesheet" href="../styles/docfx.css">
<link rel="stylesheet" href="../styles/main.css">
<meta property="docfx:navrel" content="../toc.html">
<meta property="docfx:tocrel" content="toc.html">
</head>
<body data-spy="scroll" data-target="#affix" data-offset="120">
<div id="wrapper">
<header>
<nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="../index.html">
<img id="logo" class="svg" src="../logo.svg" alt="">
</a>
</div>
<div class="collapse navbar-collapse" id="navbar">
<form class="navbar-form navbar-right" role="search" id="search">
<div class="form-group">
<input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
</div>
</form>
</div>
</div>
</nav>
<div class="subnav navbar navbar-default">
<div class="container hide-when-search" id="breadcrumb">
<ul class="breadcrumb">
<li></li>
</ul>
</div>
</div>
</header>
<div role="main" class="container body-content hide-when-search">
<div class="sidenav hide-when-search">
<a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
<div class="sidetoggle collapse" id="sidetoggle">
<div id="sidetoc"></div>
</div>
</div>
<div class="article row grid-right">
<div class="col-md-10">
<article class="content wrap" id="_content" data-uid="HarmonyLib.AccessTools.FieldRef`2">
<h1 id="HarmonyLib_AccessTools_FieldRef_2" data-uid="HarmonyLib.AccessTools.FieldRef`2" class="text-break">Delegate AccessTools.FieldRef&lt;T, F&gt;
</h1>
<div class="markdown level0 summary"><p>A readable/assignable reference delegate to an instance field of a class or static field (NOT an instance field of a struct)</p>
</div>
<div class="markdown level0 conceptual"></div>
<h6><strong>Namespace</strong>: <a class="xref" href="HarmonyLib.html">HarmonyLib</a></h6>
<h6><strong>Assembly</strong>: 0Harmony.dll</h6>
<h5 id="HarmonyLib_AccessTools_FieldRef_2_syntax">Syntax</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public delegate F FieldRef&lt;in T, F&gt;(T instance = null);</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">T</span></td>
<td><span class="parametername">instance</span></td>
<td><p>The runtime instance to access the field (ignored and can be omitted for static fields)</p>
</td>
</tr>
</tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">F</span></td>
<td><p>A readable/assignable reference to the field</p>
</td>
</tr>
</tbody>
</table>
<h5 class="typeParameters">Type Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="parametername">T</span></td>
<td><p>An arbitrary type if the field is static; otherwise the class that defines the field, or a parent class (including <span class="xref">System.Object</span>),
implemented interface, or derived class of this type</p>
</td>
</tr>
<tr>
<td><span class="parametername">F</span></td>
<td><p>The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type),
a type that <span class="xref">System.Type.IsAssignableFrom(System.Type)</span> that type; or if the field's type is an enum type,
either that type or the underlying integral type of that enum type</p>
</td>
</tr>
</tbody>
</table>
<h5 id="HarmonyLib_AccessTools_FieldRef_2_remarks"><strong>Remarks</strong></h5>
<div class="markdown level0 remarks"><p>
This delegate cannot be used for instance fields of structs, since a struct instance passed to the delegate would be passed by
value and thus would be a copy that only exists within the delegate&apos;s invocation. This is fine for a readonly reference,
but makes assignment futile. Use <a class="xref" href="HarmonyLib.AccessTools.StructFieldRef-2.html">AccessTools.StructFieldRef&lt;T, F&gt;</a> instead.
</p>
<p>
Note that <code data-dev-comment-type="typeparamref" class="typeparamref">T</code> is not required to be the field&apos;s declaring type. It can be a parent class (including <span class="xref">System.Object</span>),
implemented interface, or a derived class of the field&apos;s declaring type (&quot;<code>instanceOfT is FieldDeclaringType</code>&quot; must be possible).
Specifically, <code data-dev-comment-type="typeparamref" class="typeparamref">F</code> must be <span class="xref">System.Type.IsAssignableFrom(System.Type)</span> OR to the field&apos;s declaring type.
Technically, this allows <code>Nullable</code>, although <code>Nullable</code> is only relevant for structs, and since only static fields of structs
are allowed for this delegate, and the instance passed to such a delegate is ignored, this hardly matters.
</p>
<p>
Similarly, <code data-dev-comment-type="typeparamref" class="typeparamref">F</code> is not required to be the field&apos;s field type, unless that type is a non-enum value type.
It can be a parent class (including <code>object</code>) or implemented interface of the field&apos;s field type. It cannot be a derived class.
This variance is not allowed for value types, since that would require boxing/unboxing, which is not allowed for ref values.
Special case for enum types: <code data-dev-comment-type="typeparamref" class="typeparamref">F</code> can also be the underlying integral type of the enum type.
Specifically, for reference types, <code data-dev-comment-type="typeparamref" class="typeparamref">F</code> must be <span class="xref">System.Type.IsAssignableFrom(System.Type)</span>
the field&apos;s field type; for non-enum value types, <code data-dev-comment-type="typeparamref" class="typeparamref">F</code> must be exactly the field&apos;s field type; for enum types,
<code data-dev-comment-type="typeparamref" class="typeparamref">F</code> must be either the field&apos;s field type or the underyling integral type of that field type.
</p>
<p>
This delegate supports static fields, even those defined in structs, for legacy reasons.
For such static fields, <code data-dev-comment-type="typeparamref" class="typeparamref">T</code> is effectively ignored.
Consider using <a class="xref" href="HarmonyLib.AccessTools.FieldRef-1.html">AccessTools.FieldRef&lt;F&gt;</a> (and <code>StaticFieldRefAccess</code> methods that return it) instead for static fields.
</p>
</div>
<h3 id="constructors">Constructors
</h3>
<a id="HarmonyLib_AccessTools_FieldRef_2__ctor_" data-uid="HarmonyLib.AccessTools.FieldRef`2.#ctor*"></a>
<h4 id="HarmonyLib_AccessTools_FieldRef_2__ctor_System_Object_System_IntPtr_" data-uid="HarmonyLib.AccessTools.FieldRef`2.#ctor(System.Object,System.IntPtr)">FieldRef(Object, IntPtr)</h4>
<div class="markdown level1 summary"></div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public FieldRef(object object, IntPtr method)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">System.Object</span></td>
<td><span class="parametername">object</span></td>
<td></td>
</tr>
<tr>
<td><span class="xref">System.IntPtr</span></td>
<td><span class="parametername">method</span></td>
<td></td>
</tr>
</tbody>
</table>
<h5 class="exceptions">Exceptions</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Condition</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">System.NullReferenceException</span></td>
<td><p>Null instance passed to a non-static field ref delegate</p>
</td>
</tr>
<tr>
<td><span class="xref">System.InvalidCastException</span></td>
<td><p>Instance of invalid type passed to a non-static field ref delegate
(this can happen if <code data-dev-comment-type="typeparamref" class="typeparamref">T</code> is a parent class or interface of the field's declaring type)</p>
</td>
</tr>
</tbody>
</table>
<h3 id="methods">Methods
</h3>
<a id="HarmonyLib_AccessTools_FieldRef_2_BeginInvoke_" data-uid="HarmonyLib.AccessTools.FieldRef`2.BeginInvoke*"></a>
<h4 id="HarmonyLib_AccessTools_FieldRef_2_BeginInvoke__0_System_AsyncCallback_System_Object_" data-uid="HarmonyLib.AccessTools.FieldRef`2.BeginInvoke(`0,System.AsyncCallback,System.Object)">BeginInvoke(T, AsyncCallback, Object)</h4>
<div class="markdown level1 summary"></div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public virtual IAsyncResult BeginInvoke(T instance, AsyncCallback callback, object object)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">T</span></td>
<td><span class="parametername">instance</span></td>
<td></td>
</tr>
<tr>
<td><span class="xref">System.AsyncCallback</span></td>
<td><span class="parametername">callback</span></td>
<td></td>
</tr>
<tr>
<td><span class="xref">System.Object</span></td>
<td><span class="parametername">object</span></td>
<td></td>
</tr>
</tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">System.IAsyncResult</span></td>
<td></td>
</tr>
</tbody>
</table>
<h5 class="exceptions">Exceptions</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Condition</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">System.NullReferenceException</span></td>
<td><p>Null instance passed to a non-static field ref delegate</p>
</td>
</tr>
<tr>
<td><span class="xref">System.InvalidCastException</span></td>
<td><p>Instance of invalid type passed to a non-static field ref delegate
(this can happen if <code data-dev-comment-type="typeparamref" class="typeparamref">T</code> is a parent class or interface of the field's declaring type)</p>
</td>
</tr>
</tbody>
</table>
<a id="HarmonyLib_AccessTools_FieldRef_2_EndInvoke_" data-uid="HarmonyLib.AccessTools.FieldRef`2.EndInvoke*"></a>
<h4 id="HarmonyLib_AccessTools_FieldRef_2_EndInvoke_System_IAsyncResult_" data-uid="HarmonyLib.AccessTools.FieldRef`2.EndInvoke(System.IAsyncResult)">EndInvoke(IAsyncResult)</h4>
<div class="markdown level1 summary"></div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public virtual F EndInvoke(IAsyncResult result)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">System.IAsyncResult</span></td>
<td><span class="parametername">result</span></td>
<td></td>
</tr>
</tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">F</span></td>
<td></td>
</tr>
</tbody>
</table>
<h5 class="exceptions">Exceptions</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Condition</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">System.NullReferenceException</span></td>
<td><p>Null instance passed to a non-static field ref delegate</p>
</td>
</tr>
<tr>
<td><span class="xref">System.InvalidCastException</span></td>
<td><p>Instance of invalid type passed to a non-static field ref delegate
(this can happen if <code data-dev-comment-type="typeparamref" class="typeparamref">T</code> is a parent class or interface of the field's declaring type)</p>
</td>
</tr>
</tbody>
</table>
<a id="HarmonyLib_AccessTools_FieldRef_2_Invoke_" data-uid="HarmonyLib.AccessTools.FieldRef`2.Invoke*"></a>
<h4 id="HarmonyLib_AccessTools_FieldRef_2_Invoke__0_" data-uid="HarmonyLib.AccessTools.FieldRef`2.Invoke(`0)">Invoke(T)</h4>
<div class="markdown level1 summary"></div>
<div class="markdown level1 conceptual"></div>
<h5 class="decalaration">Declaration</h5>
<div class="codewrapper">
<pre><code class="lang-csharp hljs">public virtual F Invoke(T instance = null)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">T</span></td>
<td><span class="parametername">instance</span></td>
<td></td>
</tr>
</tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">F</span></td>
<td></td>
</tr>
</tbody>
</table>
<h5 class="exceptions">Exceptions</h5>
<table class="table table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Type</th>
<th>Condition</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="xref">System.NullReferenceException</span></td>
<td><p>Null instance passed to a non-static field ref delegate</p>
</td>
</tr>
<tr>
<td><span class="xref">System.InvalidCastException</span></td>
<td><p>Instance of invalid type passed to a non-static field ref delegate
(this can happen if <code data-dev-comment-type="typeparamref" class="typeparamref">T</code> is a parent class or interface of the field's declaring type)</p>
</td>
</tr>
</tbody>
</table>
</article>
</div>
<div class="hidden-sm col-md-2" role="complementary">
<div class="sideaffix">
<div class="contribution">
<ul class="nav">
</ul>
</div>
<nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
<!-- <p><a class="back-to-top" href="#top">Back to top</a><p> -->
</nav>
</div>
</div>
</div>
</div>
<footer>
<div class="grad-bottom"></div>
<div class="footer">
<div class="container">
<span class="pull-right">
<a href="#top">Back to top</a>
</span>
<span>Generated by <strong>DocFX</strong></span>
</div>
</div>
</footer>
</div>
<script type="text/javascript" src="../styles/docfx.vendor.js"></script>
<script type="text/javascript" src="../styles/docfx.js"></script>
<script type="text/javascript" src="../styles/main.js"></script>
</body>
</html>