mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
.Net 6 Upgrade
This commit is contained in:
@ -4,46 +4,44 @@ using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public class ArgumentTemplate
|
||||
{
|
||||
public class ArgumentTemplate
|
||||
public string Name { get; set; }
|
||||
|
||||
public TemplateDataType Type { get; set; }
|
||||
|
||||
public ParameterInfo ParameterInfo { get; set; }
|
||||
|
||||
public static (uint, ArgumentTemplate) Parse(byte[] data, uint offset)
|
||||
{
|
||||
public string Name { get; set; }
|
||||
var cs = (uint)data[offset++];
|
||||
var name = data.GetString(offset, cs);
|
||||
offset += cs;
|
||||
var (size, type) = TemplateDataType.Parse(data, offset);
|
||||
|
||||
public TemplateDataType Type { get; set; }
|
||||
return (cs + 1 + size, new ArgumentTemplate(name, type));
|
||||
}
|
||||
|
||||
public ParameterInfo ParameterInfo { get; set; }
|
||||
public ArgumentTemplate()
|
||||
{
|
||||
|
||||
public static (uint, ArgumentTemplate) Parse(byte[] data, uint offset)
|
||||
{
|
||||
var cs = (uint)data[offset++];
|
||||
var name = data.GetString(offset, cs);
|
||||
offset += cs;
|
||||
var (size, type) = TemplateDataType.Parse(data, offset);
|
||||
}
|
||||
|
||||
return (cs + 1 + size, new ArgumentTemplate(name, type));
|
||||
}
|
||||
public ArgumentTemplate(string name, TemplateDataType type)
|
||||
{
|
||||
Name = name;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public ArgumentTemplate()
|
||||
{
|
||||
public byte[] Compose()
|
||||
{
|
||||
var name = DC.ToBytes(Name);
|
||||
|
||||
}
|
||||
|
||||
public ArgumentTemplate(string name, TemplateDataType type)
|
||||
{
|
||||
Name = name;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public byte[] Compose()
|
||||
{
|
||||
var name = DC.ToBytes(Name);
|
||||
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(Type.Compose())
|
||||
.ToArray();
|
||||
}
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(Type.Compose())
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
@ -6,21 +6,19 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public class AttributeTemplate : MemberTemplate
|
||||
{
|
||||
public class AttributeTemplate : MemberTemplate
|
||||
public PropertyInfo PropertyInfo
|
||||
{
|
||||
public PropertyInfo PropertyInfo
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public AttributeTemplate(TypeTemplate template, byte index, string name)
|
||||
: base(template, MemberType.Attribute, index, name)
|
||||
{
|
||||
public AttributeTemplate(TypeTemplate template, byte index, string name)
|
||||
: base(template, MemberType.Attribute, index, name)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,54 +6,52 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public class EventTemplate : MemberTemplate
|
||||
{
|
||||
public class EventTemplate : MemberTemplate
|
||||
public string Expansion
|
||||
{
|
||||
public string Expansion
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public bool Listenable { get; set; }
|
||||
|
||||
public EventInfo EventInfo { get; set; }
|
||||
|
||||
public TemplateDataType ArgumentType { get; set; }
|
||||
|
||||
public override byte[] Compose()
|
||||
{
|
||||
var name = base.Compose();
|
||||
|
||||
if (Expansion != null)
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public bool Listenable { get; set; }
|
||||
|
||||
public EventInfo EventInfo { get; set; }
|
||||
|
||||
public TemplateDataType ArgumentType { get; set; }
|
||||
|
||||
public override byte[] Compose()
|
||||
{
|
||||
var name = base.Compose();
|
||||
|
||||
if (Expansion != null)
|
||||
{
|
||||
var exp = DC.ToBytes(Expansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8(Listenable ? (byte) 0x58 : (byte) 0x50)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ArgumentType.Compose())
|
||||
.AddInt32(exp.Length)
|
||||
.AddUInt8Array(exp)
|
||||
.ToArray();
|
||||
}
|
||||
else
|
||||
return new BinaryList()
|
||||
.AddUInt8(Listenable ? (byte) 0x48 : (byte) 0x40)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ArgumentType.Compose())
|
||||
.ToArray();
|
||||
var exp = DC.ToBytes(Expansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8(Listenable ? (byte)0x58 : (byte)0x50)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ArgumentType.Compose())
|
||||
.AddInt32(exp.Length)
|
||||
.AddUInt8Array(exp)
|
||||
.ToArray();
|
||||
}
|
||||
else
|
||||
return new BinaryList()
|
||||
.AddUInt8(Listenable ? (byte)0x48 : (byte)0x40)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ArgumentType.Compose())
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public EventTemplate(TypeTemplate template, byte index, string name, TemplateDataType argumentType, string expansion = null, bool listenable=false)
|
||||
:base(template, MemberType.Property, index, name)
|
||||
{
|
||||
this.Expansion = expansion;
|
||||
this.Listenable = listenable;
|
||||
this.ArgumentType = argumentType;
|
||||
}
|
||||
public EventTemplate(TypeTemplate template, byte index, string name, TemplateDataType argumentType, string expansion = null, bool listenable = false)
|
||||
: base(template, MemberType.Property, index, name)
|
||||
{
|
||||
this.Expansion = expansion;
|
||||
this.Listenable = listenable;
|
||||
this.ArgumentType = argumentType;
|
||||
}
|
||||
}
|
||||
|
@ -6,71 +6,69 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public class FunctionTemplate : MemberTemplate
|
||||
{
|
||||
public class FunctionTemplate : MemberTemplate
|
||||
|
||||
public string Expansion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
//public bool IsVoid
|
||||
//{
|
||||
// get;
|
||||
// set;
|
||||
//}
|
||||
|
||||
public TemplateDataType ReturnType { get; set; }
|
||||
|
||||
public ArgumentTemplate[] Arguments { get; set; }
|
||||
|
||||
public MethodInfo MethodInfo
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public override byte[] Compose()
|
||||
{
|
||||
|
||||
public string Expansion
|
||||
var name = base.Compose();
|
||||
|
||||
var bl = new BinaryList()
|
||||
//.AddUInt8(Expansion != null ? (byte)0x10 : (byte)0)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ReturnType.Compose())
|
||||
.AddUInt8((byte)Arguments.Length);
|
||||
|
||||
for (var i = 0; i < Arguments.Length; i++)
|
||||
bl.AddUInt8Array(Arguments[i].Compose());
|
||||
|
||||
|
||||
if (Expansion != null)
|
||||
{
|
||||
get;
|
||||
set;
|
||||
var exp = DC.ToBytes(Expansion);
|
||||
bl.AddInt32(exp.Length)
|
||||
.AddUInt8Array(exp);
|
||||
bl.InsertUInt8(0, 0x10);
|
||||
}
|
||||
else
|
||||
bl.InsertUInt8(0, 0x0);
|
||||
|
||||
//public bool IsVoid
|
||||
//{
|
||||
// get;
|
||||
// set;
|
||||
//}
|
||||
|
||||
public TemplateDataType ReturnType { get; set; }
|
||||
|
||||
public ArgumentTemplate[] Arguments { get; set; }
|
||||
|
||||
public MethodInfo MethodInfo
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
return bl.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public override byte[] Compose()
|
||||
{
|
||||
|
||||
var name = base.Compose();
|
||||
|
||||
var bl = new BinaryList()
|
||||
//.AddUInt8(Expansion != null ? (byte)0x10 : (byte)0)
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ReturnType.Compose())
|
||||
.AddUInt8((byte)Arguments.Length);
|
||||
|
||||
for (var i = 0; i < Arguments.Length; i++)
|
||||
bl.AddUInt8Array(Arguments[i].Compose());
|
||||
|
||||
|
||||
if (Expansion != null)
|
||||
{
|
||||
var exp = DC.ToBytes(Expansion);
|
||||
bl.AddInt32(exp.Length)
|
||||
.AddUInt8Array(exp);
|
||||
bl.InsertUInt8(0, 0x10);
|
||||
}
|
||||
else
|
||||
bl.InsertUInt8(0, 0x0);
|
||||
|
||||
return bl.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public FunctionTemplate(TypeTemplate template, byte index, string name, ArgumentTemplate[] arguments, TemplateDataType returnType, string expansion = null)
|
||||
: base(template, MemberType.Property, index, name)
|
||||
{
|
||||
//this.IsVoid = isVoid;
|
||||
this.Arguments = arguments;
|
||||
this.ReturnType = returnType;
|
||||
this.Expansion = expansion;
|
||||
}
|
||||
public FunctionTemplate(TypeTemplate template, byte index, string name, ArgumentTemplate[] arguments, TemplateDataType returnType, string expansion = null)
|
||||
: base(template, MemberType.Property, index, name)
|
||||
{
|
||||
//this.IsVoid = isVoid;
|
||||
this.Arguments = arguments;
|
||||
this.ReturnType = returnType;
|
||||
this.Expansion = expansion;
|
||||
}
|
||||
}
|
||||
|
@ -5,43 +5,41 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public class MemberTemplate
|
||||
{
|
||||
public class MemberTemplate
|
||||
public enum MemberType
|
||||
{
|
||||
public enum MemberType
|
||||
{
|
||||
Function = 0,
|
||||
Property = 1,
|
||||
Event = 2,
|
||||
Attribute = 3
|
||||
}
|
||||
|
||||
public byte Index => index;
|
||||
public string Name => name;
|
||||
public MemberType Type => type;
|
||||
|
||||
TypeTemplate template;
|
||||
string name;
|
||||
MemberType type;
|
||||
byte index;
|
||||
|
||||
public TypeTemplate Template => template;
|
||||
|
||||
public MemberTemplate(TypeTemplate template, MemberType type, byte index, string name)
|
||||
{
|
||||
this.template = template;
|
||||
this.type = type;
|
||||
this.index = index;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public string Fullname => template.ClassName + "." + Name;
|
||||
|
||||
public virtual byte[] Compose()
|
||||
{
|
||||
return DC.ToBytes(Name);
|
||||
}
|
||||
Function = 0,
|
||||
Property = 1,
|
||||
Event = 2,
|
||||
Attribute = 3
|
||||
}
|
||||
|
||||
public byte Index => index;
|
||||
public string Name => name;
|
||||
public MemberType Type => type;
|
||||
|
||||
TypeTemplate template;
|
||||
string name;
|
||||
MemberType type;
|
||||
byte index;
|
||||
|
||||
public TypeTemplate Template => template;
|
||||
|
||||
public MemberTemplate(TypeTemplate template, MemberType type, byte index, string name)
|
||||
{
|
||||
this.template = template;
|
||||
this.type = type;
|
||||
this.index = index;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public string Fullname => template.ClassName + "." + Name;
|
||||
|
||||
public virtual byte[] Compose()
|
||||
{
|
||||
return DC.ToBytes(Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,138 +6,136 @@ using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public class PropertyTemplate : MemberTemplate
|
||||
{
|
||||
public class PropertyTemplate : MemberTemplate
|
||||
public enum PropertyPermission : byte
|
||||
{
|
||||
public enum PropertyPermission : byte
|
||||
Read = 1,
|
||||
Write,
|
||||
ReadWrite
|
||||
}
|
||||
|
||||
|
||||
public PropertyInfo PropertyInfo
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public TemplateDataType ValueType { get; set; }
|
||||
|
||||
|
||||
/*
|
||||
public bool Serilize
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
*/
|
||||
//bool ReadOnly;
|
||||
//IIPTypes::DataType ReturnType;
|
||||
public PropertyPermission Permission
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public bool Recordable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/*
|
||||
public PropertyType Mode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}*/
|
||||
|
||||
public string ReadExpansion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string WriteExpansion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/*
|
||||
public bool Storable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}*/
|
||||
|
||||
|
||||
public override byte[] Compose()
|
||||
{
|
||||
var name = base.Compose();
|
||||
var pv = ((byte)(Permission) << 1) | (Recordable ? 1 : 0);
|
||||
|
||||
if (WriteExpansion != null && ReadExpansion != null)
|
||||
{
|
||||
Read = 1,
|
||||
Write,
|
||||
ReadWrite
|
||||
var rexp = DC.ToBytes(ReadExpansion);
|
||||
var wexp = DC.ToBytes(WriteExpansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x38 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddInt32(wexp.Length)
|
||||
.AddUInt8Array(wexp)
|
||||
.AddInt32(rexp.Length)
|
||||
.AddUInt8Array(rexp)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public PropertyInfo PropertyInfo
|
||||
else if (WriteExpansion != null)
|
||||
{
|
||||
get;
|
||||
set;
|
||||
var wexp = DC.ToBytes(WriteExpansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x30 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddInt32(wexp.Length)
|
||||
.AddUInt8Array(wexp)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public TemplateDataType ValueType { get; set; }
|
||||
|
||||
|
||||
/*
|
||||
public bool Serilize
|
||||
else if (ReadExpansion != null)
|
||||
{
|
||||
get;set;
|
||||
var rexp = DC.ToBytes(ReadExpansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x28 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddInt32(rexp.Length)
|
||||
.AddUInt8Array(rexp)
|
||||
.ToArray();
|
||||
}
|
||||
*/
|
||||
//bool ReadOnly;
|
||||
//IIPTypes::DataType ReturnType;
|
||||
public PropertyPermission Permission
|
||||
else
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
public bool Recordable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/*
|
||||
public PropertyType Mode
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}*/
|
||||
|
||||
public string ReadExpansion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public string WriteExpansion
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/*
|
||||
public bool Storable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}*/
|
||||
|
||||
|
||||
public override byte[] Compose()
|
||||
{
|
||||
var name = base.Compose();
|
||||
var pv = ((byte)(Permission) << 1) | (Recordable ? 1 : 0);
|
||||
|
||||
if (WriteExpansion != null && ReadExpansion != null)
|
||||
{
|
||||
var rexp = DC.ToBytes(ReadExpansion);
|
||||
var wexp = DC.ToBytes(WriteExpansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x38 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddInt32(wexp.Length)
|
||||
.AddUInt8Array(wexp)
|
||||
.AddInt32(rexp.Length)
|
||||
.AddUInt8Array(rexp)
|
||||
.ToArray();
|
||||
}
|
||||
else if (WriteExpansion != null)
|
||||
{
|
||||
var wexp = DC.ToBytes(WriteExpansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x30 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddInt32(wexp.Length)
|
||||
.AddUInt8Array(wexp)
|
||||
.ToArray();
|
||||
}
|
||||
else if (ReadExpansion != null)
|
||||
{
|
||||
var rexp = DC.ToBytes(ReadExpansion);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x28 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.AddInt32(rexp.Length)
|
||||
.AddUInt8Array(rexp)
|
||||
.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x20 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public PropertyTemplate(TypeTemplate template, byte index, string name, TemplateDataType valueType, string read = null, string write = null, bool recordable = false)
|
||||
: base(template, MemberType.Property, index, name)
|
||||
{
|
||||
this.Recordable = recordable;
|
||||
//this.Storage = storage;
|
||||
this.ReadExpansion = read;
|
||||
this.WriteExpansion = write;
|
||||
this.ValueType = valueType;
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)(0x20 | pv))
|
||||
.AddUInt8((byte)name.Length)
|
||||
.AddUInt8Array(name)
|
||||
.AddUInt8Array(ValueType.Compose())
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public PropertyTemplate(TypeTemplate template, byte index, string name, TemplateDataType valueType, string read = null, string write = null, bool recordable = false)
|
||||
: base(template, MemberType.Property, index, name)
|
||||
{
|
||||
this.Recordable = recordable;
|
||||
//this.Storage = storage;
|
||||
this.ReadExpansion = read;
|
||||
this.WriteExpansion = write;
|
||||
this.ValueType = valueType;
|
||||
}
|
||||
}
|
||||
|
@ -4,106 +4,104 @@ using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public struct TemplateDataType
|
||||
{
|
||||
public struct TemplateDataType
|
||||
public DataType Type { get; set; }
|
||||
//public string TypeName { get; set; }
|
||||
public TypeTemplate TypeTemplate => TypeGuid == null ? null : Warehouse.GetTemplateByClassId((Guid)TypeGuid);
|
||||
|
||||
public Guid? TypeGuid { get; set; }
|
||||
//public TemplateDataType(DataType type, string typeName)
|
||||
//{
|
||||
// Type = type;
|
||||
// TypeName = typeName;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
public static TemplateDataType FromType(Type type)
|
||||
{
|
||||
public DataType Type { get; set; }
|
||||
//public string TypeName { get; set; }
|
||||
public TypeTemplate TypeTemplate => TypeGuid == null ? null : Warehouse.GetTemplateByClassId((Guid)TypeGuid);
|
||||
|
||||
public Guid? TypeGuid { get; set; }
|
||||
//public TemplateDataType(DataType type, string typeName)
|
||||
//{
|
||||
// Type = type;
|
||||
// TypeName = typeName;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
public static TemplateDataType FromType(Type type)
|
||||
var t = type switch
|
||||
{
|
||||
{ IsArray: true } => type.GetElementType(),
|
||||
{ IsEnum: true } => type.GetEnumUnderlyingType(),
|
||||
(_) => type
|
||||
};
|
||||
|
||||
var t = type switch
|
||||
{
|
||||
{ IsArray: true } => type.GetElementType(),
|
||||
{ IsEnum: true } => type.GetEnumUnderlyingType(),
|
||||
(_) => type
|
||||
};
|
||||
|
||||
DataType dt = t switch
|
||||
{
|
||||
_ when t == typeof(bool) => DataType.Bool,
|
||||
_ when t == typeof(char) => DataType.Char,
|
||||
_ when t == typeof(byte) => DataType.UInt8,
|
||||
_ when t == typeof(sbyte) => DataType.Int8,
|
||||
_ when t == typeof(short) => DataType.Int16,
|
||||
_ when t == typeof(ushort) => DataType.UInt16,
|
||||
_ when t == typeof(int) => DataType.Int32,
|
||||
_ when t == typeof(uint) => DataType.UInt32,
|
||||
_ when t == typeof(long) => DataType.Int64,
|
||||
_ when t == typeof(ulong) => DataType.UInt64,
|
||||
_ when t == typeof(float) => DataType.Float32,
|
||||
_ when t == typeof(double) => DataType.Float64,
|
||||
_ when t == typeof(decimal) => DataType.Decimal,
|
||||
_ when t == typeof(string) => DataType.String,
|
||||
_ when t == typeof(DateTime) => DataType.DateTime,
|
||||
_ when t == typeof(IResource) => DataType.Void, // Dynamic resource (unspecified type)
|
||||
_ when t == typeof(IRecord) => DataType.Void, // Dynamic record (unspecified type)
|
||||
_ when typeof(Structure).IsAssignableFrom(t) || t == typeof(ExpandoObject) => DataType.Structure,
|
||||
_ when Codec.ImplementsInterface(t, typeof(IResource)) => DataType.Resource,
|
||||
_ when Codec.ImplementsInterface(t, typeof(IRecord)) => DataType.Record,
|
||||
_ => DataType.Void
|
||||
};
|
||||
|
||||
|
||||
Guid? typeGuid = null;
|
||||
|
||||
if (dt == DataType.Resource || dt == DataType.Record)
|
||||
typeGuid = TypeTemplate.GetTypeGuid(t);
|
||||
|
||||
if (type.IsArray)
|
||||
dt = (DataType)((byte)dt | 0x80);
|
||||
|
||||
return new TemplateDataType()
|
||||
{
|
||||
Type = dt,
|
||||
TypeGuid = typeGuid
|
||||
};
|
||||
}
|
||||
|
||||
public byte[] Compose()
|
||||
DataType dt = t switch
|
||||
{
|
||||
if (Type == DataType.Resource ||
|
||||
Type == DataType.ResourceArray ||
|
||||
Type == DataType.Record ||
|
||||
Type == DataType.RecordArray)
|
||||
{
|
||||
var guid = DC.ToBytes((Guid)TypeGuid);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)Type)
|
||||
.AddUInt8Array(guid).ToArray();
|
||||
}
|
||||
else
|
||||
return new byte[] { (byte)Type };
|
||||
}
|
||||
|
||||
public override string ToString() => Type.ToString() + TypeTemplate != null ? "<" + TypeTemplate.ClassName + ">" : "";
|
||||
_ when t == typeof(bool) => DataType.Bool,
|
||||
_ when t == typeof(char) => DataType.Char,
|
||||
_ when t == typeof(byte) => DataType.UInt8,
|
||||
_ when t == typeof(sbyte) => DataType.Int8,
|
||||
_ when t == typeof(short) => DataType.Int16,
|
||||
_ when t == typeof(ushort) => DataType.UInt16,
|
||||
_ when t == typeof(int) => DataType.Int32,
|
||||
_ when t == typeof(uint) => DataType.UInt32,
|
||||
_ when t == typeof(long) => DataType.Int64,
|
||||
_ when t == typeof(ulong) => DataType.UInt64,
|
||||
_ when t == typeof(float) => DataType.Float32,
|
||||
_ when t == typeof(double) => DataType.Float64,
|
||||
_ when t == typeof(decimal) => DataType.Decimal,
|
||||
_ when t == typeof(string) => DataType.String,
|
||||
_ when t == typeof(DateTime) => DataType.DateTime,
|
||||
_ when t == typeof(IResource) => DataType.Void, // Dynamic resource (unspecified type)
|
||||
_ when t == typeof(IRecord) => DataType.Void, // Dynamic record (unspecified type)
|
||||
_ when typeof(Structure).IsAssignableFrom(t) || t == typeof(ExpandoObject) => DataType.Structure,
|
||||
_ when Codec.ImplementsInterface(t, typeof(IResource)) => DataType.Resource,
|
||||
_ when Codec.ImplementsInterface(t, typeof(IRecord)) => DataType.Record,
|
||||
_ => DataType.Void
|
||||
};
|
||||
|
||||
|
||||
public static (uint, TemplateDataType) Parse(byte[] data, uint offset)
|
||||
Guid? typeGuid = null;
|
||||
|
||||
if (dt == DataType.Resource || dt == DataType.Record)
|
||||
typeGuid = TypeTemplate.GetTypeGuid(t);
|
||||
|
||||
if (type.IsArray)
|
||||
dt = (DataType)((byte)dt | 0x80);
|
||||
|
||||
return new TemplateDataType()
|
||||
{
|
||||
var type = (DataType)data[offset++];
|
||||
if (type == DataType.Resource ||
|
||||
type == DataType.ResourceArray ||
|
||||
type == DataType.Record ||
|
||||
type == DataType.RecordArray)
|
||||
{
|
||||
var guid = data.GetGuid(offset);
|
||||
return (17, new TemplateDataType() { Type = type, TypeGuid = guid });
|
||||
}
|
||||
else
|
||||
return (1, new TemplateDataType() { Type = type });
|
||||
Type = dt,
|
||||
TypeGuid = typeGuid
|
||||
};
|
||||
}
|
||||
|
||||
public byte[] Compose()
|
||||
{
|
||||
if (Type == DataType.Resource ||
|
||||
Type == DataType.ResourceArray ||
|
||||
Type == DataType.Record ||
|
||||
Type == DataType.RecordArray)
|
||||
{
|
||||
var guid = DC.ToBytes((Guid)TypeGuid);
|
||||
return new BinaryList()
|
||||
.AddUInt8((byte)Type)
|
||||
.AddUInt8Array(guid).ToArray();
|
||||
}
|
||||
else
|
||||
return new byte[] { (byte)Type };
|
||||
}
|
||||
|
||||
public override string ToString() => Type.ToString() + TypeTemplate != null ? "<" + TypeTemplate.ClassName + ">" : "";
|
||||
|
||||
|
||||
public static (uint, TemplateDataType) Parse(byte[] data, uint offset)
|
||||
{
|
||||
var type = (DataType)data[offset++];
|
||||
if (type == DataType.Resource ||
|
||||
type == DataType.ResourceArray ||
|
||||
type == DataType.Record ||
|
||||
type == DataType.RecordArray)
|
||||
{
|
||||
var guid = data.GetGuid(offset);
|
||||
return (17, new TemplateDataType() { Type = type, TypeGuid = guid });
|
||||
}
|
||||
else
|
||||
return (1, new TemplateDataType() { Type = type });
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource.Template
|
||||
namespace Esiur.Resource.Template;
|
||||
public enum TemplateType : byte
|
||||
{
|
||||
public enum TemplateType:byte
|
||||
{
|
||||
Unspecified,
|
||||
Resource,
|
||||
Record,
|
||||
Wrapper,
|
||||
}
|
||||
Unspecified,
|
||||
Resource,
|
||||
Record,
|
||||
Wrapper,
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user