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:
| Method | Description | Status |
|---|---|---|
virtual std::string ToString() const | Returns the type name by default. Override to provide meaningful representation. | Implemented |
virtual bool Equals(const Object*) const | Reference 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() const | Hashes object identity (address) by default. | Implemented |
virtual const std::string& GetTypeName() const = 0 | Pure 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:
| Header | Purpose |
|---|---|
include/System/Int32.hpp | Int32::MaxValue, Int32::MinValue constants |
include/System/Int64.hpp | Int64::MaxValue, Int64::MinValue |
include/System/UInt32.hpp | UInt32 constants |
include/System/Byte.hpp | Byte::MaxValue (255) |
include/System/Single.hpp | float constants |
include/System/Double.hpp | double constants |
include/System/Char.hpp | Char utilities (IsDigit, IsLetter, etc.) |
include/System/Boolean.hpp | Boolean 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.hpp | IDisposable — Dispose() method |
System/IComparable.hpp | IComparable<T> — CompareTo() |
System/IEquatable.hpp | IEquatable<T> — Equals(T) |
System/ICloneable.hpp | ICloneable — Clone() |
System/IFormattable.hpp | IFormattable — ToString(format) |
System/Collections/Generic/IEnumerable.hpp | IEnumerable<T> |
System/Collections/Generic/IList.hpp | IList<T> |
System/Collections/Generic/IDictionary.hpp | IDictionary<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
| Type | Header | Description |
|---|---|---|
System::Decimal | System/Decimal.hpp | 128-bit decimal with full arithmetic |
System::Guid | System/Guid.hpp | RFC 4122 v4 GUID, NewGuid(), ToString() |
System::DateTime | System/DateTime.hpp | Date and time, ISO-8601 |
System::TimeSpan | System/TimeSpan.hpp | Time interval |
System::Version | System/Version.hpp | Major.Minor.Build.Revision, parse, compare |
System::Uri | System/Uri.hpp | Full URL parsing |
System::Span<T> | System/Span.hpp | Non-owning view with Slice, range-for, bounds check |
System::Index | System/Index.hpp | Index from start or end |
System::Range | System/Range.hpp | Range of indices |
System::Tuple<> | System/Tuple.hpp | Tuple2/3/4 structs with Item1/Item2/... |