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. This page gives the forms that the facts of these rules take in C#, the built-in lists that Stereocode reads for C#, and one labeled example of each stereotype. The section Data Members and Calls states in full how Stereocode reads data members, types, returned values, and calls in C#.

Language Facts

  • A method reaches its object through this. The accessors get and set of a property are methods of the class. The hidden value of a setter counts as a parameter.
  • A parameter shares its object with the caller when it is a ref or out parameter or a parameter of a class type, also with the modifier in. A struct or an enum of the archive passed by value is a copy.
  • A method with the specifier async returns the value of its task. Task thus counts as void and Task<T> as T.
  • An event without accessors is a data member of its delegate type.
  • A call without an object to a method that no type of the archive defines is a call to the object itself when its name is an accessor of object with its number of arguments, namely Equals, GetHashCode, ToString, GetType, or MemberwiseClone. The same holds when the class has a parent outside the archive.
  • 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.

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 std::exit for exit and 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