Skip to content
Ali Al-Ramadan edited this page Nov 14, 2026 · 2 revisions

The rules of the method stereotypes, the free-function stereotypes, and the class stereotypes hold in C# as in every language of Stereocode. The section Data Members and Calls of the method stereotypes states the conventions by which Stereocode determines the facts of these rules in every language. This page gives the forms that these facts take in C#, the built-in lists that Stereocode reads for C#, and one labeled example of each stereotype.

Language Facts

Classes and functions

  • A function among the top-level statements of a program is a free function. Structs and interfaces get their stereotypes with the options -t and -i.
  • The accessors get and set of a property are methods of the class. A set accessor returns void and receives the new value of its property as the hidden parameter value. The type of this parameter counts for collaborator, as the type of any other parameter does.

Data members

  • A method reaches its object through this.
  • An event without accessors is a data member of its delegate type, while a static event counts as a static field. A call to any method on an event, such as Closed.SafeInvoke(this, args), reads the event and counts as a call of a free function.

Types and variables

  • A parameter shares its object with the caller when it is a ref or out parameter or a parameter of a class type. The modifier in before a parameter of a class type leaves the object shared, since in makes only the reference read-only. A struct or an enum of the archive passed by value is a copy that shares nothing, also with generic arguments such as Slot<string>.
  • Using directives decide which class of the archive a type name refers to. A directive for every type of a namespace, such as using Model;, yields to the types that the other files of the namespace of the current file declare. Stereocode follows a using alias directive, such as using Alias = N.Item;, for the type of a data member.
  • Stereocode reads a type without its attributes. The arguments of an attribute inside a method body, such as [Obsolete("x")] on a local variable, count as no read and no call.
  • Stereocode reads System.Nullable<int> as int?, a primitive type that makes no method a collaborator.
  • The variable of a type pattern, such as found of other is Gauge found, is a local variable of the type that the pattern names. The variables of a tuple declaration, such as var (low, high) = pair;, of a using declaration, and of a query expression, such as item of from item in items, are local variables as well.
  • A deconstruction such as (low, high) = pair; writes low and high. The discard _, as in _ = Run(); or Parse(text, out _), is no variable.
  • The null-forgiving operator ! changes no fact about the variable that it follows. buffer![0] = value writes buffer, writer!.Flush() is a call on writer, and return name!; returns name.
  • A name in the argument of nameof, such as label of nameof(label), reads no value.
  • The name before = or : in an object initializer, a with expression, or a property pattern, such as Left of other with { Left = 1 }, names a member of the created or matched object and reads no data member.

Returned values

  • A method with the specifier async returns the value of its task. Task and ValueTask count as void, while Task<T> and ValueTask<T> count as T. A method without async returns the task itself.
  • return ref head; returns the data member head, as return head; does.

Calls

  • A call without an object whose name matches no method of the type or of its ancestors in the archive is a call to the object itself in two cases. First, the name is an accessor of System.Object with its number of arguments, namely Equals, GetHashCode, ToString, GetType, or MemberwiseClone. Second, the type has a parent outside the archive. Such a call stays a call of a free function where its name is a static method that the type can access, such as a static method of an ancestor or of a using static directive.
  • A call on a data member through an extension method of the archive, such as basket.IsEmpty() for IsEmpty(this Basket basket), counts as the static call BasketExtensions.IsEmpty(basket) does. It reads the data member and counts as a call of a free function.
  • A variable passed with ref or out, such as count in Interlocked.Increment(ref count), counts as written by the call, whether the variable is a data member, a parameter, or a static field, since the called method may write the variable.
  • A target-typed new(), a creation with an initializer such as new Report { }, and an anonymous object new { Total = 1 } are constructor calls.

Built-in Lists

Stereocode reads four built-in lists for C#. The list files of the options -p, -c, -s, and -q add entries to these lists under the section [C#], as the README states. Each list below opens with a click.

Primitive types (37 entries)

A type of this list makes no method a collaborator and no return type of a factory.

bool, Boolean, Byte, byte, Char, char, Decimal, decimal, Double, double, float, Half, int, Int128, Int16, Int32, Int64, IntPtr, long, nint, nuint, SByte, sbyte, short, Single, String, string, uint, UInt128, UInt16, UInt32, UInt64, UIntPtr, ulong, ushort, Void, void

Ignored calls (8 entries)

The rules ignore a call of these names, also after a qualifier, as System.Console.WriteLine for Console.WriteLine.

Console.Error.WriteLine, Console.Write, Console.WriteLine, Debug.Assert, Debug.WriteLine, Environment.Exit, nameof, Trace.WriteLine

Specifiers and containers (62 entries)

Stereocode strips these entries from a written type before it reads the names of the type. A container counts by the types of its elements. Each entry is a regular expression, such as \.\.\. for ....

<, >, \*, \?, abstract, async, BitArray, BlockingCollection, ConcurrentBag, ConcurrentDictionary, ConcurrentQueue, ConcurrentStack, const, Dictionary, event, explicit, extern, HashSet, HybridDictionary, ICollection(?=<), IEnumerable(?=<), IList(?=<), implicit, in, internal, IReadOnlyCollection, IReadOnlyList, ISet, KeyedCollection, LinkedList, List, NameValueCollection, new, Nullable(?=<), OrderedDictionary, out, override, params, partial, private, protected, public, Queue, readonly, ReadOnlyCollection, ReadOnlyDictionary, ref, required, scoped, sealed, SortedList, SortedSet, Stack, static, StringCollection, StringDictionary, this, Tuple, unsafe, ValueTuple, virtual, volatile

Query methods (9 entries)

A call of these methods only reads the variable that the call is on. An entry with a slash, such as GetValue/1, holds only for that number of arguments.

Contains, ContainsKey, Count, Equals, GetHashCode, GetType, GetValue/1, ToString, TryGetValue

Examples

Each example below is the declaration of an element from the stereotype cases of Stereocode, whose expected stereotypes are written by hand in @stereotype comments. Each link opens the case on the branch develop. The second column gives every stereotype of the element. A stereotype without an example has no case in C#.

Methods

Stereotype Stereotypes of the element Declaration
get get public override int Count() { return count; }
predicate predicate get { return (bool)GetValue(IsOpenProperty); }
property property string Describe() { return this.ToString(); }
void-accessor void-accessor void PeekOut(out int r) { r = x; }
set set void Store(int value) { buffer![0] = value; }
command command public void Increment() { count++; steps++; }
non-void-command non-void-command public int Padded() { return Width("a", "b"); }
factory factory collaborator stateless public Widget Make() { return new Widget(); }
collaborator predicate collaborator public bool IsLast() { return next == null; }
controller controller void AfterCallThenDot() { Current()?.y.Z(); }
wrapper wrapper public void FireIfSet() { onFire?.Invoke(); }
incidental incidental public int[] Numbers() { return new int[3]; }
stateless controller stateless void Trim(Node other) { other.Name!.Trim(); }
empty empty public void Close() { /* nothing to release */ }
constructor constructor protected Shape(int count) { sides = count; }
copy-constructor copy-constructor public Matrix(Matrix other) { rows = other.rows; }
destructor destructor ~Matrix() { }
unclassified unclassified public void PrintOwner()

TABLE 1. Examples of the method stereotypes in C#.

Free functions

Stereotype Stereotypes of the element Declaration
main main public static void Main(string[] args) { Report(args.Length); }
predicate predicate public static bool IsEven(int value) { return value % 2 == 0; }
property property static int Thrice(int x) { return x * 3; }
global-command global-command public static void Hit(int n) { hits += n; }
command command public static void Touch(Node p) { p?.y?.Z(); }
factory property factory public static Widget MakeWidget(int style) { Widget widget = new Widget(style...
literal literal public static int Answer() { return 42; }
wrapper wrapper public static void Run(Action action) { action(); }
empty empty public static void Noop(int value) { }
unclassified unclassified static void ResetPlain(Holder h) { h = null; }

TABLE 2. Examples of the free-function stereotypes in C#, which the option -f assigns.

Types

Stereotype Stereotypes of the element Declaration
boundary boundary public class Exporter
commander commander small-class public abstract partial class Job
controller controller public class Spooler
data-class data-class public class Account
data-interface data-provider data-interface small-interface public interface IChain
data-provider data-provider public class Circle
data-struct data-provider data-struct small-struct private struct Pair
degenerate entity degenerate public class Plugin
empty empty public interface IShape
entity entity boundary public class Measure
factory factory controller public class WidgetFactory
large-class large-class public class Box
large-interface large-interface public interface IShape
large-struct large-struct public struct Frame
lazy-class lazy-class public class Settings
lazy-interface data-provider lazy-interface public interface ILazy
lazy-struct lazy-struct public struct Slot
minimal-entity minimal-entity commander public class Counter
pure-controller pure-controller public class Dispatcher
small-class small-class class Clock
small-interface data-provider data-interface small-interface public interface IChain
small-struct data-provider data-struct small-struct private struct Pair
unclassified unclassified public class Large22

TABLE 3. Examples of the class stereotypes in C#, where large-class, lazy-class, data-class, and small-class of a type of another kind take that kind in place of class, such as data-struct.

Clone this wiki locally