Support for easy loading assemblies, and instantly creating enums in the static scope
This commit is contained in:
@@ -39,6 +39,7 @@ namespace Upsilon.BoundTypes
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static BoundTypeDefinition GetTypeDefinition(System.Type type)
|
||||
{
|
||||
return _typeDefinitions.Values.FirstOrDefault(x => x.ValidInternalTypes.Contains(type));
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Upsilon.BoundTypes
|
||||
{
|
||||
public class UserDataBoundTypeDefinition : BoundTypeDefinition
|
||||
{
|
||||
public string Name { get; }
|
||||
public string Name { get; protected set; }
|
||||
public Dictionary<string, UserDataBoundProperty> Properties { get; protected set; }
|
||||
|
||||
internal UserDataBoundTypeDefinition(System.Type backingType)
|
||||
@@ -28,11 +28,12 @@ namespace Upsilon.BoundTypes
|
||||
|
||||
|
||||
|
||||
public static UserDataBoundTypeDefinition Create(System.Type backingType)
|
||||
public static UserDataBoundTypeDefinition Create(System.Type backingType, string name)
|
||||
{
|
||||
var obj = new UserDataBoundTypeDefinition(backingType)
|
||||
{
|
||||
Properties = new Dictionary<string, UserDataBoundProperty>()
|
||||
Properties = new Dictionary<string, UserDataBoundProperty>(),
|
||||
Name = name
|
||||
};
|
||||
var fields = backingType.GetFields().Select(x => new UserDataBoundProperty()
|
||||
{
|
||||
@@ -60,15 +61,15 @@ namespace Upsilon.BoundTypes
|
||||
{
|
||||
if (backingMethod.IsSpecialName)
|
||||
continue;
|
||||
var name = backingMethod.Name;
|
||||
var methodName = backingMethod.Name;
|
||||
var attribute = backingMethod.GetCustomAttribute(typeof(ScriptFunctionAttribute));
|
||||
if (attribute is ScriptFunctionAttribute sfa )
|
||||
{
|
||||
name = sfa.Name;
|
||||
methodName = sfa.Name;
|
||||
}
|
||||
methods.Add(new UserDataBoundMethod()
|
||||
{
|
||||
Name = name,
|
||||
Name = methodName,
|
||||
Type = Type.Function,
|
||||
ResultType = backingMethod.ReturnType.GetScriptType()
|
||||
});
|
||||
@@ -88,7 +89,7 @@ namespace Upsilon.BoundTypes
|
||||
|
||||
public class UserDataBoundEnumDefinition : UserDataBoundTypeDefinition
|
||||
{
|
||||
public UserDataBoundEnumDefinition(System.Type enumType) : base(enumType)
|
||||
public UserDataBoundEnumDefinition(System.Type enumType, string name) : base(enumType)
|
||||
{
|
||||
if (!enumType.IsEnum)
|
||||
throw new Exception("Trying to bind an enum with a type that's not an enum");
|
||||
@@ -97,14 +98,16 @@ namespace Upsilon.BoundTypes
|
||||
var enumUnderlyingType = Enum.GetUnderlyingType(enumType);
|
||||
var enumValues = Enum.GetValues(enumType);
|
||||
|
||||
Name = name;
|
||||
|
||||
for (var i=0; i < enumValues.Length; i++)
|
||||
{
|
||||
var value = enumValues.GetValue(i);
|
||||
|
||||
var name = value.ToString().ToLowerInvariant();
|
||||
Properties.Add(name, new UserDataBoundProperty()
|
||||
var valueName = value.ToString().ToLowerInvariant();
|
||||
Properties.Add(valueName, new UserDataBoundProperty()
|
||||
{
|
||||
Name = name,
|
||||
Name = valueName,
|
||||
ActualType = enumUnderlyingType.ToString(),
|
||||
Type = Type.Number
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user