5.6 KiB
Class and Interface Registration
Comprehensive registration system for classes and interfaces with methods, properties, and events.
VlppReflection provides extensive macros for registering classes and interfaces, enabling complete runtime reflection support including methods, properties, events, constructors, and inheritance relationships. The system supports both classes and interfaces with shared registration patterns.
Basic Registration Patterns
Class Registration
- Use
BEGIN_CLASS_MEMBERandEND_CLASS_MEMBERfor class registration - Provides foundation for making class types accessible through reflection
- Supports all class features including inheritance, methods, and properties
Interface Registration
- Use
BEGIN_INTERFACE_MEMBERandEND_INTERFACE_MEMBERfor inheritable interfaces - Use
BEGIN_INTERFACE_MEMBER_NOPROXYandEND_INTERFACE_MEMBERfor non-inheritable interfaces - Interfaces can be inherited in Workflow scripts when using the regular
BEGIN_INTERFACE_MEMBER
Registration Components
Base Class Declaration
- Use
CLASS_MEMBER_BASEfor reflectable base class declaration - Enables proper inheritance hierarchy in reflection
- Supports multiple inheritance scenarios
Field Registration
- Use
CLASS_MEMBER_FIELDfor member field registration - Exposes public fields through the reflection system
- Enables dynamic field access and manipulation
Constructor Registration
- Use
CLASS_MEMBER_CONSTRUCTORfor constructor registration withPtr<Class>(types...)orClass*(types...) - Use
CLASS_MEMBER_EXTERNALCTORfor external function constructors - Constructor type determines whether instances are boxed in
Ptr<T>or not
Method Registration
- Use
CLASS_MEMBER_METHODfor method registration with parameter names - Use
CLASS_MEMBER_METHOD_OVERLOADfor overloaded method registration - Use
CLASS_MEMBER_EXTERNALMETHODfor external function methods - Use
CLASS_MEMBER_STATIC_METHODfor static method registration
Event Registration
- Use
CLASS_MEMBER_EVENTfor event registration - Events are typically
Event<T>type fields - Enables dynamic event subscription and notification
Property Registration
- Use
CLASS_MEMBER_PROPERTY_READONLY,CLASS_MEMBER_PROPERTYfor property registration - Use
CLASS_MEMBER_PROPERTY_READONLY_FAST,CLASS_MEMBER_PROPERTY_FASTfor standard getter/setter patterns - Use
CLASS_MEMBER_PROPERTY_EVENT_READONLY_FAST,CLASS_MEMBER_PROPERTY_EVENT_FASTfor properties with change events
Parameter Name Specifications
Function Arguments
For constructors and methods, argument names are required in the declaration:
- Use
NO_PARAMETERfor parameterless functions - Use
{ L"arg1" _ L"arg2" ... }for parameter name lists - The
_macro must be defined as,in the implementation file
Registration Examples
Basic Class Registration
BEGIN_CLASS_MEMBER(MyClass)
CLASS_MEMBER_FIELD(FirstField)
CLASS_MEMBER_FIELD(SecondField)
END_CLASS_MEMBER(MyClass)
Interface Registration
BEGIN_INTERFACE_MEMBER(IMyInterface)
CLASS_MEMBER_FIELD(FirstField)
CLASS_MEMBER_FIELD(SecondField)
END_INTERFACE_MEMBER(IMyInterface)
Complete Class with All Features
#define _ ,
BEGIN_CLASS_MEMBER(MyClass)
CLASS_MEMBER_BASE(BaseClass)
CLASS_MEMBER_FIELD(fieldName)
CLASS_MEMBER_CONSTRUCTOR(Ptr<MyClass>(vint), { L"value" })
CLASS_MEMBER_METHOD(MethodName, { L"arg1" _ L"arg2" })
CLASS_MEMBER_STATIC_METHOD(StaticMethod, NO_PARAMETER)
CLASS_MEMBER_EVENT(SomeEvent)
CLASS_MEMBER_PROPERTY_FAST(PropertyName)
END_CLASS_MEMBER(MyClass)
#undef _
Interface Requirements
Proxy Requirements
Using BEGIN_INTERFACE_MEMBER requires a proxy to EXIST in the header file, which means the interface can be inherited in Workflow script.
Using BEGIN_INTERFACE_MEMBER_NOPROXY requires a proxy to NOT EXIST in the header file, which means the interface cannot be inherited in Workflow script.
Constructor Limitations
There is no constructor in an interface registration - only classes support constructor registration.
Extra Content
Advanced Registration Features
Method Overloading
For overloaded methods, use specific macros:
CLASS_MEMBER_METHOD_OVERLOAD(name, parameter, function-type)CLASS_MEMBER_METHOD_OVERLOAD_RENAME(new-name, name, parameter, function-type)- Function type must be a pointer to member function
External Methods
For methods implemented as external functions:
CLASS_MEMBER_EXTERNALMETHOD(name, parameters, function-type, source)- First parameter acts as
thispointer - Should not appear in parameters or function-type
Property Shortcuts
Fast property registration shortcuts:
CLASS_MEMBER_PROPERTY_READONLY_FAST(X)forGetX()getter and propertyXCLASS_MEMBER_PROPERTY_FAST(X)forGetX()getter,SetX()setter, and propertyXCLASS_MEMBER_PROPERTY_EVENT_FAST(X)includesXChangedevent
Best Practices
- Complete Registration: Register all public members that should be accessible
- Consistent Naming: Follow established naming conventions
- Parameter Documentation: Provide meaningful parameter names
- Event Integration: Use events to notify property changes
- Type Safety: Ensure all referenced types are properly registered
Performance Considerations
- Registration occurs at startup time with minimal runtime overhead
- Dynamic method calls have slight performance cost compared to direct calls
- Property access through reflection is slower than direct field access
- Consider caching reflection results for frequently used operations