Search code examples
reflectionwindows-runtimeintrospectionc++-cx

WinRT Reflection (C++/CX)


how can I introspect an object in C++/CX? I known how to get its class name (using IInspectable) but I wasn't able to figure out how to get a list of its properties or how to invoke methods if I have just a name of the method (string). I searched for an answer here and at Google but what I found is related to the .NET layer of WinRT (the System.Reflection namespace doesn't seem to be available in C++/CX).


Solution

  • C++ doesn't provide any specific APIs to reflect on WinRT types, these types are fully defined in CX compliant metadata files and you can use the CLR native metadata APIs to read their definition. There is a snippet at

    http://social.msdn.microsoft.com/Forums/windowsapps/en-US/211ef583-db11-4e55-926b-6d9ab53dbdb4/ccx-reflection

    James McNellis released a full C++ library for CX reflection last year

    http://seaplusplus.com/2012/04/26/cxxreflect-native-reflection-for-the-windows-runtime/