views:

386

answers:

1

For instance, I was thinking of replacing this:

var.StringAttribute = input.ReadString();

With something like this:

var.EnumAttribute = input.ReadExternalReference<EnumName>();

However this doesn't work quite right. And ideas on how to get input to read a custom enumeration?

+1  A: 

ReadExternalReference Reads a link to an external file - that's not what you want to do.

If I understand you correctly, you want to read a string, and parse it as an enum.

Try this:

string value = input.ReadString();
var.EnumAttribute = Enum.Parse(typeof(EnumName), value);

Note that this will work for both numbers (anything within the range of the enum's underlying type - typically Int32) and string values, but will throw an exception for invalid values.

configurator