Template:Code Reference: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
m (add Category:Templates)
(expound on documentation)
Line 1: Line 1:
<noinclude>This template is used for cohesive citation of the game's C# classes. It's called like so:
<noinclude>Use this template instead of a <code><nowiki><ref></nowiki></code> tag if you are citing a class from the game's C# assemblies, such as <code>Assembly-CSharp.dll</code>. This is useful for cohesively formatting all such code references.
 
{| class="wikitable"
|-
! Template Parameter !! Required? !! Default Value
|-
| <code>namespace</code> || No || <code>XRL.World.Parts</code>
|-
| <code>class</code> || Yes || None – This must be specified or else the template will error.
|-
| <code>method</code> || No || None – If omitted, a method name will not be included in the reference.
|}
 
== Usage Examples ==
 
Use the following form if you need to reference a part definition:
 
<pre><nowiki>{{Code Reference
| class = FakePart
}}</nowiki></pre>{{Code Reference
| class = FakePart
}}
 
Use the following form if you need to reference a class in a different namespace from <code>XRL.World.Parts</code>:


<pre><nowiki>{{Code Reference
<pre><nowiki>{{Code Reference
| namespace = Fake.Namespace
| class    = FakeClass
}}</nowiki></pre>{{Code Reference
| namespace = Fake.Namespace
| class    = FakeClass
}}
In some cases, it may be useful to additionally specify which method the logic in question occurs in. In that case, use the following form:
<pre><nowiki>{{Code Reference
| namespace = Fake.Namespace
| class    = FakeClass
| method    = FakeMethod
}}</nowiki></pre>{{Code Reference
| namespace = Fake.Namespace
| namespace = Fake.Namespace
| class    = FakeClass
| class    = FakeClass
| method    = FakeMethod
| method    = FakeMethod
}}</nowiki></pre>
}}


All parameters except <code>class</code> can usefully be omitted:
If there are multiple method definitions with the same name, or it otherwise may help to be even more exact, you may append the parameter signature to the name of the method to specify an overload like so:


* If <code>class</code> is missing, the page will be tagged with [[:Category:Pages with code reference errors]].
<pre><nowiki>{{Code Reference
* If <code>namespace</code> is missing, it defaults to <code>XRL.World.Parts</code>.
| namespace = Fake.Namespace
* If <code>method</code> is missing, the descriptive text related to it is omitted.
| class    = FakeClass
 
| method    = FakeMethod(GameObject, GameObject)
The above example results in the following citation:{{Code Reference
}}</nowiki></pre>{{Code Reference
| namespace = Fake.Namespace
| namespace = Fake.Namespace
| class    = FakeClass
| class    = FakeClass
| method    = FakeMethod
| method    = FakeMethod(GameObject, GameObject)
}}
}}


[[Category:Templates]]</noinclude><includeonly>{{#if:{{{class|}}}|{{#tag:ref|<code>{{{namespace|XRL.World.Parts}}}.{{{class}}}{{#if:{{{method|}}}|, method {{{method}}}}}</code>}}|[[Category:Pages with code reference errors]]}}</includeonly>
[[Category:Templates]]</noinclude><includeonly>{{#if:{{{class|}}}|{{#tag:ref|<code>{{{namespace|XRL.World.Parts}}}.{{{class}}}{{#if:{{{method|}}}|, method {{{method}}}}}</code>}}|[[Category:Pages with code reference errors]]}}</includeonly>

Revision as of 04:24, 25 August 2020

Use this template instead of a <ref> tag if you are citing a class from the game's C# assemblies, such as Assembly-CSharp.dll. This is useful for cohesively formatting all such code references.

Template Parameter Required? Default Value
namespace No XRL.World.Parts
class Yes None – This must be specified or else the template will error.
method No None – If omitted, a method name will not be included in the reference.

Usage Examples

Use the following form if you need to reference a part definition:

{{Code Reference
| class = FakePart
}}

[1]

Use the following form if you need to reference a class in a different namespace from XRL.World.Parts:

{{Code Reference
| namespace = Fake.Namespace
| class     = FakeClass
}}

[2]

In some cases, it may be useful to additionally specify which method the logic in question occurs in. In that case, use the following form:

{{Code Reference
| namespace = Fake.Namespace
| class     = FakeClass
| method    = FakeMethod
}}

[3]

If there are multiple method definitions with the same name, or it otherwise may help to be even more exact, you may append the parameter signature to the name of the method to specify an overload like so:

{{Code Reference
| namespace = Fake.Namespace
| class     = FakeClass
| method    = FakeMethod(GameObject, GameObject)
}}

[4]

  1. XRL.World.Parts.FakePart
  2. Fake.Namespace.FakeClass
  3. Fake.Namespace.FakeClass, method FakeMethod
  4. Fake.Namespace.FakeClass, method FakeMethod(GameObject, GameObject)