Bind indexing of userdata
This commit is contained in:
22
Upsilon/BoundTypes/BoundTypeDefinition.cs
Normal file
22
Upsilon/BoundTypes/BoundTypeDefinition.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Upsilon.BaseTypes;
|
||||
|
||||
namespace Upsilon.BoundTypes
|
||||
{
|
||||
public class BoundTypeDefinition
|
||||
{
|
||||
public BoundTypeDefinition(Type scriptType, System.Type[] validInternalTypes)
|
||||
{
|
||||
ScriptType = scriptType;
|
||||
ValidInternalTypes = validInternalTypes;
|
||||
}
|
||||
|
||||
public BoundTypeDefinition(Type scriptType, System.Type backingType)
|
||||
{
|
||||
ScriptType = scriptType;
|
||||
ValidInternalTypes = new []{backingType};
|
||||
}
|
||||
|
||||
public Type ScriptType { get; }
|
||||
public System.Type[] ValidInternalTypes { get; }
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,8 @@ namespace Upsilon.BoundTypes
|
||||
{
|
||||
public static class BoundTypeHandler
|
||||
{
|
||||
private static readonly Dictionary<string, BoundTypeDefinition> TypeDefinitions = new Dictionary<string, BoundTypeDefinition>
|
||||
private static readonly Dictionary<string, BoundTypeDefinition> DefaultTypeDefinitions =
|
||||
new Dictionary<string, BoundTypeDefinition>
|
||||
{
|
||||
{"string", new BoundTypeDefinition(Type.String, typeof(string))},
|
||||
{
|
||||
@@ -19,27 +20,36 @@ namespace Upsilon.BoundTypes
|
||||
{"function", new BoundTypeDefinition(Type.Function, new System.Type[0])},
|
||||
};
|
||||
|
||||
private static Dictionary<string, BoundTypeDefinition> _typeDefinitions =
|
||||
new Dictionary<string, BoundTypeDefinition>(DefaultTypeDefinitions);
|
||||
|
||||
public static void Reset()
|
||||
{
|
||||
_typeDefinitions =
|
||||
new Dictionary<string, BoundTypeDefinition>(DefaultTypeDefinitions);
|
||||
}
|
||||
|
||||
public static BoundTypeDefinition GetTypeDefinition(string key)
|
||||
{
|
||||
return TypeDefinitions[key.ToLowerInvariant()];
|
||||
var normalizedName = key.ToLowerInvariant();
|
||||
if (_typeDefinitions.TryGetValue(normalizedName, out var bt))
|
||||
{
|
||||
return bt;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class BoundTypeDefinition
|
||||
{
|
||||
public BoundTypeDefinition(Type scriptType, System.Type[] validInternalTypes)
|
||||
public static void LoadUserDataTypeDefinition(UserDataBoundTypeDefinition def)
|
||||
{
|
||||
ScriptType = scriptType;
|
||||
ValidInternalTypes = validInternalTypes;
|
||||
var key = def.Name.ToLowerInvariant();
|
||||
if (_typeDefinitions.ContainsKey(key))
|
||||
{
|
||||
_typeDefinitions[key] = def;
|
||||
}
|
||||
else
|
||||
{
|
||||
_typeDefinitions.Add(key, def);
|
||||
}
|
||||
}
|
||||
|
||||
public BoundTypeDefinition(Type scriptType, System.Type validInternalType)
|
||||
{
|
||||
ScriptType = scriptType;
|
||||
ValidInternalTypes = new []{validInternalType};
|
||||
}
|
||||
|
||||
public Type ScriptType { get; }
|
||||
public System.Type[] ValidInternalTypes { get; }
|
||||
}
|
||||
}
|
||||
32
Upsilon/BoundTypes/UserDataBoundTypeDefinition.cs
Normal file
32
Upsilon/BoundTypes/UserDataBoundTypeDefinition.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using Upsilon.BaseTypes;
|
||||
|
||||
namespace Upsilon.BoundTypes
|
||||
{
|
||||
public class UserDataBoundTypeDefinition : BoundTypeDefinition
|
||||
{
|
||||
public string Name { get; }
|
||||
public Dictionary<string, UserDataBoundProperty> Properties { get; }
|
||||
|
||||
public UserDataBoundTypeDefinition(System.Type backingType)
|
||||
: base(Type.UserData, backingType)
|
||||
{
|
||||
Name = backingType.Name;
|
||||
}
|
||||
|
||||
public UserDataBoundTypeDefinition(string name, Dictionary<string, UserDataBoundProperty> properties)
|
||||
: base(Type.UserData, new System.Type[0])
|
||||
{
|
||||
Name = name;
|
||||
Properties = properties;
|
||||
}
|
||||
}
|
||||
|
||||
public class UserDataBoundProperty
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Type Type { get; set; }
|
||||
public string ActualType { get; set; }
|
||||
public string Comment { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user