0

I need to read the values of System.Management.PropertyData when it's an array.

PropertyData.IsArray Property

https://learn.microsoft.com/en-us/dotnet/api/system.management.propertydata.isarray?view=netframework-4.7.2

I have no idea how to convert PropertyData.Value to something readable. If I print PropertyData.Value as it is, I get a "System.String[]"

If I convert it to array<String>

for each(String s in (array<String>^)(object->Properties[propertyName]->Value))
    Console::WriteLine(s);

I get a

Error (active) the element type of a cli::array must be a handle or value type

Any help would be appreciated.

marco
  • 1,686
  • 1
  • 25
  • 33
  • That's by no means valid c++ code. – πάντα ῥεῖ Dec 12 '18 at 12:07
  • It's Microsoft C++/CX https://learn.microsoft.com/en-us/cpp/cppcx/quick-reference-c-cx?view=vs-2017 – marco Dec 12 '18 at 12:11
  • Tag your question appropriately then, but don't use the standard c++ tag please. – πάντα ῥεῖ Dec 12 '18 at 12:14
  • for each (String^ s in array^)... – kennyzx Dec 12 '18 at 12:17
  • @kennyzx Thanks, worked. You better post it as an answer so I can accept it, commit this ticket I'm working on and go back working on a logic, elegant and standard C++ – marco Dec 12 '18 at 12:22
  • The syntax is somewhat unusual. I only find C++/CLI useful once in my life when I need to reuse a large block of old C code in a library and the library is to be used in a .NET application. By using C++/CLI I can use both .NET classes and C in the same library. – kennyzx Dec 12 '18 at 12:31
  • I'm not a MS developer so, every time I have to code for Windows, I find MS code illogical and anti intuitive. – marco Dec 12 '18 at 12:48

1 Answers1

1

This is simply a syntax error.

The correct form is

for each (String^ s in (array<String^>^)...
kennyzx
  • 12,845
  • 6
  • 39
  • 83