Files
pardeike-Harmony/docs/api/HarmonyLib.AccessTools.FieldRef-2.html
T
2020-09-25 14:25:18 +00:00

212 lines
9.7 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.56.2.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;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> the field's 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 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.
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; and for value types, <code data-dev-comment-type="typeparamref" class="typeparamref">F</code> must be exactly the field&apos;s 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.
This is also the reason that this delegate lacks a generic class constraint (it was added to certain <code>FieldRefAccess</code> methods,
but such a constraint cannot be added to this delegate without breaking binary compatibility).
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>
</article>
</div>
<div class="hidden-sm col-md-2" role="complementary">
<div class="sideaffix">
<div class="contribution">
<ul class="nav">
<li>
<a href="https://github.com/pardeike/Harmony/new/master/apiSpec/new?filename=HarmonyLib_AccessTools_FieldRef_2.md&amp;value=---%0Auid%3A%20HarmonyLib.AccessTools.FieldRef%602%0Asummary%3A%20'*You%20can%20override%20summary%20for%20the%20API%20here%20using%20*MARKDOWN*%20syntax'%0A---%0A%0A*Please%20type%20below%20more%20information%20about%20this%20API%3A*%0A%0A" class="contribution-link">Improve this Doc</a>
</li>
<li>
<a href="https://github.com/pardeike/Harmony/blob/master/Harmony/Tools/AccessTools.cs/#L829" class="contribution-link">View Source</a>
</li>
</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>