Visual Studio reports that
“‘PhoenixEngineTypes.BehaviorTypes’ is a ‘type’ but is used like a ‘variable'”.
public void AddBehavior(BehaviorTypes type)
{
if (Enum.IsDefined(BehaviorTypes, type))
{
switch (type)
{
case BehaviorTypes.render:
break;
}
}
The definition of BehaviorTypes is:
[Flags]
enum BehaviorTypes : uint
{
default_behavior = 1 >> 0,
select = 1 >> 1,
render = 1 >> 2,
animate = 1 >> 3,
navigate = 1 >> 4,
rotate = 1 >> 5,
group = 1 >> 6,
scale = 1 >> 7,
collide = 1 >> 8,
kill = 1 >> 9,
attack = 1 >> 10,
audio = 1 >> 11,
all = UInt32.MaxValue
}
And finally:
public static bool IsDefined(Type enumType, object value);
Why can’t I do this?
I tried using typeof(type) and it compiles, but why waste a function call when the type is not variable? Shouldn’t I be able to use the token directly?
You need to call
IsDefinedas followsas it expects an instance of
Typeas input.BehaviorTypesis not an instance ofType, but you can get the correspondingTypeinstance for a type by usingtypeof.See http://msdn.microsoft.com/en-us/library/system.enum.isdefined.aspx