Type System

Object base class, primitive type aliases, numeric wrappers, and type helpers.

System::Object — The Base Class

include/System/Object.hpp

All complex types in sharp-runtime inherit from System::Object, mirroring .NET's universal base class. It provides:

MethodDescriptionStatus
virtual std::string ToString() constReturns the type name by default. Override to provide meaningful representation.Implemented
virtual bool Equals(const Object*) constReference identity by default.Implemented
static bool Equals(const Object*, const Object*)Static null-safe equality helper.Implemented
static bool ReferenceEquals(const Object*, const Object*)Pointer comparison.Implemented
virtual int GetHashCode() constHashes object identity (address) by default.Implemented
virtual const std::string& GetTypeName() const = 0Pure virtual. Every concrete class must implement this.Required

GetTypeName Macros

Implementing GetTypeName() is boilerplate. Two macros reduce it:

// In the class declaration (.hpp):
class MyClass : public System::Object {
    GetTypeNameHPP()  // declares the override
};

// In the implementation (.cpp):
GetTypeNameCPP(MyClass, MyClass)
// Expands to: const std::string& MyClass::GetTypeName() const {
//               static const std::string n = "MyClass"; return n; }

Primitive Type Aliases

include/SharpRuntime/SharpRuntimeHelper.hpp

These aliases provide exact C# bit widths and allow ported code to read naturally:

namespace SharpRuntime {
    using sbytecs  = int8_t;    // C# sbyte
    using bytecs   = uint8_t;   // C# byte
    using shortcs  = int16_t;   // C# short
    using ushortcs = uint16_t;  // C# ushort
    using intcs    = int32_t;   // C# int
    using uintcs   = uint32_t;  // C# uint
    using longcs   = int64_t;   // C# long
    using ulongcs  = uint64_t;  // C# ulong
    using charcs   = char16_t;  // C# char (UTF-16)
    using IntPtr   = std::uintptr_t;  // C# IntPtr
}

Also provides .NET-name aliases: Int32, Int64, Byte, Single (float), String (std::string).

Constant bounds: INTCS_MAX, INTCS_MIN, BYTECS_MAX, etc. via std::numeric_limits.

Numeric Wrapper Types

These header-only types exist primarily to provide static MinValue / MaxValue constants, mirroring C# boxed types:

HeaderPurpose
include/System/Int32.hppInt32::MaxValue, Int32::MinValue constants
include/System/Int64.hppInt64::MaxValue, Int64::MinValue
include/System/UInt32.hppUInt32 constants
include/System/Byte.hppByte::MaxValue (255)
include/System/Single.hppfloat constants
include/System/Double.hppdouble constants
include/System/Char.hppChar utilities (IsDigit, IsLetter, etc.)
include/System/Boolean.hppBoolean TrueString / FalseString constants

Nullable<T>

include/System/Nullable.hpp

Maps to std::optional<T>. Provides getHasValueProperty(), getValueProperty(), GetValueOrDefault().

System::Nullable<int> n;           // null (no value)
System::Nullable<int> m = 42;      // has value
if (m.getHasValueProperty()) {
    int v = m.getValueProperty();  // 42
}
int safe = n.GetValueOrDefault();   // 0

Interfaces

Many .NET interface contracts have C++ equivalents as abstract base classes:

Interface Header.NET Equivalent
System/IDisposable.hppIDisposableDispose() method
System/IComparable.hppIComparable<T>CompareTo()
System/IEquatable.hppIEquatable<T>Equals(T)
System/ICloneable.hppICloneableClone()
System/IFormattable.hppIFormattableToString(format)
System/Collections/Generic/IEnumerable.hppIEnumerable<T>
System/Collections/Generic/IList.hppIList<T>
System/Collections/Generic/IDictionary.hppIDictionary<K,V>

Type Codes

include/System/TypeCode.hpp

An enum matching .NET TypeCode values: Empty, Object, DBNull, Boolean, Char, SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, Double, Decimal, DateTime, String.

Other Value Types

TypeHeaderDescription
System::DecimalSystem/Decimal.hpp128-bit decimal with full arithmetic
System::GuidSystem/Guid.hppRFC 4122 v4 GUID, NewGuid(), ToString()
System::DateTimeSystem/DateTime.hppDate and time, ISO-8601
System::TimeSpanSystem/TimeSpan.hppTime interval
System::VersionSystem/Version.hppMajor.Minor.Build.Revision, parse, compare
System::UriSystem/Uri.hppFull URL parsing
System::Span<T>System/Span.hppNon-owning view with Slice, range-for, bounds check
System::IndexSystem/Index.hppIndex from start or end
System::RangeSystem/Range.hppRange of indices
System::Tuple<>System/Tuple.hppTuple2/3/4 structs with Item1/Item2/...