Osy#betaRun it on Osyrin: osyrin.com

Reference / Function

C#'s other spellings — System. names, Int32,

System.Math.Max(2, 3) · global::System.Math.Abs(-3) · Int32 / String / Decimal · #region · #pragma · #if · global using

The spellings a pasted C# file is full of compile with C#'s meaning. A System.-qualified name is the type Osy# has (System.Math is Math), global:: is the global namespace every name already resolves from, Int32/String/Decimal are the types int/string/decimal alias, #region/#pragma/#nullable are inert, #if keeps the branch whose symbols are defined, and global using imports into every file of the app.

stable5 examples compiled by CIfunctioncsharpcompatibility

Summary#

A C# file you paste carries spellings that name nothing new — a namespace prefix, a BCL type name, a #region. Each compiles here with the meaning C# gives it:

WrittenMeansWhy
System.Math.Max(2, 3), System.Text.StringBuilderMath.Max(2, 3), StringBuilderthose types are Osy#'s own and always in scope, as with using System;
global::System.Math.Abs(-3)Math.Abs(-3)every name already resolves from the global namespace
Int32, Int64, String, Decimal, Double, Boolean, Char, Byteint, long, string, decimal, double, bool, char, bytethe keyword is C#'s alias for exactly that type
#region / #endregion, #pragma, #nullable, #warningnothingthey fold an outline or tune C#'s own warnings
#define X … #if X … #endifthe branch whose condition holdsC#'s conditional compilation, over the file's symbols
global using X;using X; in every fileC# 10's project-wide import

Signature#

int Bigger(int a, int b) => System.Math.Max(a, b);   // System.Math IS Math
Int32 Count;                                         // Int32 IS int
#region Helpers … #endregion                         // inert
#if DEBUG … #elif TRACE … #else … #endif             // C#'s conditional compilation
global using Shop;                                   // an import every file sees

Description#

Which System. names compile?#

A name qualified by a .NET namespace whose types Osy# provides — System, System.Collections.Generic, System.Linq, System.Text, System.Text.Json, System.Text.RegularExpressions, System.Threading.Tasks, System.Net — is the type itself. global:: in front changes nothing either.

int Bigger(int a, int b) { return System.Math.Max(a, b); }
int Distance(int a) { return global::System.Math.Abs(a); }
string Joined() {
  var sb = new System.Text.StringBuilder();
  var parts = new System.Collections.Generic.List<string> { "a", "b" };
  foreach (var p in parts) { sb.Append(p); }
  return sb.ToString() + System.String.Empty;
}

A namespace Osy# does not provide keeps its qualification and is refused by that namespace — System.IO.Path answers "System.IO.Path is from a .NET namespace Osy# does not provide", and System.Threading.* adds that there are no threads to lock ([[function-csharp-exclusions#threads]]).

What do Int32 and String mean here?#

The type their keyword names. Int32 is int in a signature, a local, a property, a generic argument, a cast and as the receiver of a static (Int32.Parse):

entity Rate { Decimal Value; Int32 Count; Boolean Live; }

Int64 Scaled(Int32 x) { return (Int64)x * Int32.Parse("3"); }
decimal Sum() {
  Decimal d = 1.5m; Int32 i = 2; String s = "ab"; Boolean b = true;
  return d + i + s.Length + (b ? 1 : 0);   // 6.5, as in C#
}

Object is not on the list: object is a type keyword Osy# leaves out, and the refusal says so by name.

Which preprocessor directives work?#

All of C#'s, at the start of a line. #region/#endregion, #pragma (warning and checksum alike), #nullable and #warning change nothing about what the program means, so they are accepted and ignored. #error text stops the compile with its text. #line is refused: it renumbers the file for a code generator, and every diagnostic here points at the source as written. A # line that is no directive — # a comment — is refused by name; a comment is //.

#region Helpers
#pragma warning disable CS0168
int One() { return 1; }
#pragma warning restore CS0168
#endregion

What does #if test?#

The symbols this FILE defines with #define (and removes with #undef), written before its first line of code, as C# requires — combined with !, &&, ||, ==, !=, parentheses, true and false — and the platform's feature symbols, which every file has (C#'s NET8_0_OR_GREATER): OSY_ACTOR_PRINCIPAL_IDS on a platform with Actor.PrincipalIds(). A platform older than a symbol does not define it, so a kit that must still compile there keeps the old code in the #else. A branch that is not taken is not read at all, so it need not be valid Osy#:

#define FAST
#if FAST && !SLOW
int Mode() { return 1; }
#elif SLOW
int Mode() { return 2; }
#else
anything at all — this branch is never read
#endif

What does global using do?#

The same import as using X;, in force in every file of the app instead of only its own — C# 10's meaning. For a System.* namespace it changes nothing (those types are always in scope); for one of the app's own namespaces or a capability, a file with no using of its own sees it.

global using System.Text;

string Greeting() { return new StringBuilder().Append("g").ToString(); }

global using static T; and a global using A = T; alias are refused by name: those two forms hold for the file they are written in, so write them without global in each file that needs them.

See also#

Related

The C# Osy# leaves out — and why

Osy# is C#-shaped, and leaves out three things on purpose: unsafe code (pointers, fixed, stackalloc, function pointers…

use

Declares a capability your app depends on, written inside the `app { }` manifest block. It provisions the capability…

function

A function is a top-level unit of work, written like a C# method — a return type, a name, typed parameters, a body. It…