Reflection
Limited runtime type information, GetTypeName, Type class, and attributes.
Runtime Type Name via GetTypeName()
include/System/Object.hpp
Every System::Object subclass must implement the pure virtual GetTypeName().
This returns a static string with the type name — it is the closest analog to
GetType().Name in .NET.
System::Object* obj = new MyClass();
const std::string& name = obj->GetTypeName(); // "MyClass"
Implementation is assisted by macros:
// In .hpp:
GetTypeNameHPP()
// expands to: [[nodiscard]] virtual const std::string& GetTypeName() const override;
// In .cpp:
GetTypeNameCPP(MyClass, MyClass)
// expands to: const std::string& MyClass::GetTypeName() const {
// const static std::string type_name = "MyClass";
// return type_name; }
System::Type
include/System/Type.hpp
A partial stub for the .NET System.Type class. C++ cannot provide full runtime type metadata
(member enumeration, method invocation by name, assembly metadata, etc.).
The stub exists for compatibility — code that references System::Type will compile, but
most functionality is not implemented.
System::Type in sharp-runtime needs review from the header file.
It is expected to be a minimal stub.
Attribute Classes
sharp-runtime provides many attribute header files for API compatibility. These are empty or near-empty stub classes — they allow code to compile but do not implement runtime attribute inspection:
| Attribute | Header |
|---|---|
System::Attribute | System/Attribute.hpp |
ObsoleteAttribute | System/ObsoleteAttribute.hpp |
FlagsAttribute | System/FlagsAttribute.hpp |
SerializableAttribute | System/SerializableAttribute.hpp |
CLSCompliantAttribute | System/CLSCompliantAttribute.hpp |
AttributeUsageAttribute | System/AttributeUsageAttribute.hpp |
Diagnostics::ConditionalAttribute | System/Diagnostics/ConditionalAttribute.hpp |
Runtime::CompilerServices::MethodImplAttribute | System/Runtime/CompilerServices/MethodImplAttribute.hpp |
No Dynamic Invocation
.NET Activator.CreateInstance(), MethodInfo.Invoke(), and similar
reflection-based dynamic invocation are not available.
These are listed as ❌ IGNORE in the porting plan, as they require managed runtime support
that cannot be replicated in C++.
What to Use Instead
- Use virtual dispatch (virtual functions) instead of reflection-based dispatch
- Use
dynamic_cast<T*>for runtime type checking - Use
typeidfor C++ RTTI if needed - Use factory functions or
std::functioninstead ofActivator.CreateInstance()