简体   繁体   中英

c# to c++/cli Enum declaration

I have looked several places, but can't seem to find quite what I'm looking for. I'm making a WPF app, using c++/cli to mess with the c# xmal. I have an interface where I declare whatever I want the xaml to see for DataContext that is in c#, but what I declared in my c# interface is implemented in my c++/cli file.

I'm trying to find a way to declare an enum in c# and then actually define what it is in the c++/cli, but I am having problems with it. (Whatever I declare in the c# interface requires an accessor, which might be part of the problem)

What I have tried so far is in the c# interface,

Enum Days { get; }

Then in the c++/cli

enum class days { Sun= 0, Mon, ...}
virtual property System::Enum^ Days
    { System::Enum^ get() { return days; } }

However on the return statement, it says, "type name is not allowed". I think that is because the System::Enum^ is supposed to be value from an enum, not the created enum type itself. Is there some kind of base class or something that all enum types inherit from, or any other way to do what I'm looking to do?

I'm trying to find a way to declare an enum in c# and then actually define what it is in the c++/cli.

You can't declare a type in one assembly and define it in another. It doesn't work like that.

You can declare properties as type Enum in C#, and return any enum value, and that'll work. However, you need to return an enum value , not the name of an enum class.

System::Enum^ get() { return days::Monday; } // works

Or, you could declare a property where you inform the rest of the application of the enum type you're using. The rest of the application would use reflection to figure out which values are in the enumeration.

System::Type^ get() { return days::typeid; } // also works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM