Converting int to nullable enumeration...

This is the piece of code that's throwing the exception

field.PropertyInfo.SetValue(row, dataReader[field.Name],null);

The field in the database is a number, nullable. On the other hand, the Property in the object is of type TerrainSequence , where TerrainSequence is an enumeration. When I try to do this conversion (int to TerrainSequence ) , this is the exception it throws.
Object of type 'System.Int32' cannot be converted to type 'System.Nullable`1[FairPlay.Data.Persistables.TerrainSequence]'.
Any idea on how to tackle this conversion


Answer this question

Converting int to nullable enumeration...

  • jdaddy18

    Ok.. I read the documentation and the Convert.ChangeType only works for objects that implement the IConvertible interface... so I guess the enum doesn't implement this.
    One thing that bugs me is that you can do this:

    int integer = 0;
    TerrainSegmentEnum tsEnum = (TerrainSegmentEnum )integer;

    but, you cant do this:

    typeof(TerrainSegmentEnum ).IsAssignableFrom(typeof(int));

    Any1 want to comment on this.. :S

  • DJacobson

    This is still bugging me.. is this a BCL error
    i wrote this just to try something.. can any1 tell me whats wrong
    [code]
    int trueValue = (int )value;
    return Convert.ChangeType(trueValue, typeof(int ));
    [/code]
    Its throwing the execption at the Convert.ChangeType method.

  • Converting int to nullable enumeration...