Make enums be considered userdata, and not numbers. Allow C# functions that consume enums to use both numbers and userdata
This commit is contained in:
parent
0a034013ea
commit
2ef06b3fd7
|
@ -106,7 +106,6 @@ namespace Upsilon.BoundTypes
|
||||||
throw new Exception("Trying to bind an enum with a type that's not an enum");
|
throw new Exception("Trying to bind an enum with a type that's not an enum");
|
||||||
|
|
||||||
Properties = new Dictionary<string, UserDataBoundProperty>();
|
Properties = new Dictionary<string, UserDataBoundProperty>();
|
||||||
var enumUnderlyingType = Enum.GetUnderlyingType(enumType);
|
|
||||||
var enumValues = Enum.GetValues(enumType);
|
var enumValues = Enum.GetValues(enumType);
|
||||||
|
|
||||||
Name = name;
|
Name = name;
|
||||||
|
@ -119,11 +118,12 @@ namespace Upsilon.BoundTypes
|
||||||
Properties.Add(valueName, new UserDataBoundProperty()
|
Properties.Add(valueName, new UserDataBoundProperty()
|
||||||
{
|
{
|
||||||
Name = valueName,
|
Name = valueName,
|
||||||
ActualType = enumUnderlyingType.ToString(),
|
ActualType = enumType.ToString(),
|
||||||
Type = Type.Number
|
Type = Type.UserData
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserDataBoundEnumDefinition(IEnumerable<string> values, string name) : base(name, new Dictionary<string, UserDataBoundProperty>())
|
public UserDataBoundEnumDefinition(IEnumerable<string> values, string name) : base(name, new Dictionary<string, UserDataBoundProperty>())
|
||||||
{
|
{
|
||||||
Properties = new Dictionary<string, UserDataBoundProperty>();
|
Properties = new Dictionary<string, UserDataBoundProperty>();
|
||||||
|
@ -131,11 +131,11 @@ namespace Upsilon.BoundTypes
|
||||||
|
|
||||||
foreach (var value in values)
|
foreach (var value in values)
|
||||||
{
|
{
|
||||||
var valueName = value.ToString().ToLowerInvariant();
|
var valueName = value.ToLowerInvariant();
|
||||||
Properties.Add(valueName, new UserDataBoundProperty()
|
Properties.Add(valueName, new UserDataBoundProperty()
|
||||||
{
|
{
|
||||||
Name = valueName,
|
Name = valueName,
|
||||||
Type = Type.Number
|
Type = Type.UserData
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,6 +141,9 @@ namespace Upsilon.StandardLibraries
|
||||||
|
|
||||||
public static Type DeriveValidTypes(System.Type type)
|
public static Type DeriveValidTypes(System.Type type)
|
||||||
{
|
{
|
||||||
|
if (type.IsEnum)
|
||||||
|
return Type.UserData | Type.Number;
|
||||||
|
|
||||||
var typeCode = System.Type.GetTypeCode(type);
|
var typeCode = System.Type.GetTypeCode(type);
|
||||||
switch (typeCode)
|
switch (typeCode)
|
||||||
{
|
{
|
||||||
|
@ -181,8 +184,6 @@ namespace Upsilon.StandardLibraries
|
||||||
if (type == typeof(IIterable))
|
if (type == typeof(IIterable))
|
||||||
return Type.Table | Type.UserData;
|
return Type.Table | Type.UserData;
|
||||||
|
|
||||||
if (type.IsEnum)
|
|
||||||
return Type.UserData | Type.Number;
|
|
||||||
if (typeof(IEnumerable).IsAssignableFrom(type))
|
if (typeof(IEnumerable).IsAssignableFrom(type))
|
||||||
return Type.Table | Type.UserData;
|
return Type.Table | Type.UserData;
|
||||||
return Type.UserData;
|
return Type.UserData;
|
||||||
|
|
Loading…
Reference in New Issue