2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00

Type Annotation

This commit is contained in:
2022-06-11 18:50:08 +03:00
parent 70ac2db694
commit 80922a13ee
6 changed files with 102 additions and 24 deletions

View File

@ -25,6 +25,8 @@ public class TypeTemplate
protected Guid classId;
protected Guid? parentId;
public string Annotation { get; set; }
string className;
List<MemberTemplate> members = new List<MemberTemplate>();
List<FunctionTemplate> functions = new List<FunctionTemplate>();
@ -157,7 +159,6 @@ public class TypeTemplate
}
public static Guid GetTypeGuid(Type type) => GetTypeGuid(GetTypeClassName(type));
public static Guid GetTypeGuid(string typeName)
@ -403,6 +404,7 @@ public class TypeTemplate
Warehouse.PutTemplate(this);
PropertyInfo[] propsInfo = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);// | BindingFlags.DeclaredOnly);
EventInfo[] eventsInfo = type.GetEvents(BindingFlags.Public | BindingFlags.Instance);// | BindingFlags.DeclaredOnly);
MethodInfo[] methodsInfo = type.GetMethods(BindingFlags.Public | BindingFlags.Instance); // | BindingFlags.DeclaredOnly);
@ -772,31 +774,37 @@ public class TypeTemplate
// find the first parent type that implements IResource
var hasParent = HasParent(type);
var classAnnotation = type.GetCustomAttribute<AnnotationAttribute>(false);
var hasAnnotation = classAnnotation != null && classAnnotation.Annotation != null;
if (HasParent(type))
var classNameBytes = DC.ToBytes(className);
b.AddUInt8((byte)((hasParent ? 0x80 : 0) | (hasAnnotation ? 0x40 : 0x0) | (byte)templateType))
.AddGuid(classId)
.AddUInt8((byte)classNameBytes.Length)
.AddUInt8Array(classNameBytes);
if (hasParent)
{
// find the first parent type that implements IResource
var ParentDefinedType = ResourceProxy.GetBaseType(type.BaseType);
var parentId = GetTypeGuid(ParentDefinedType);
b.AddUInt8((byte)(0x80 | (byte)templateType))
.AddGuid(classId)
.AddUInt8((byte)className.Length)
.AddString(className)
.AddGuid(parentId)
.AddInt32(version)
.AddUInt16((ushort)members.Count);
b.AddGuid(parentId);
}
else
if (hasAnnotation)
{
b.AddUInt8((byte)templateType)
.AddGuid(classId)
.AddUInt8((byte)className.Length)
.AddString(className)
.AddInt32(version)
.AddUInt16((ushort)members.Count);
var classAnnotationBytes = DC.ToBytes(classAnnotation.Annotation);
b.AddUInt16((ushort)classAnnotationBytes.Length)
.AddUInt8Array(classAnnotationBytes);
Annotation = classAnnotation.Annotation;
}
b.AddInt32(version)
.AddUInt16((ushort)members.Count);
foreach (var ft in functions)
b.AddUInt8Array(ft.Compose());
foreach (var pt in properties)
@ -848,6 +856,8 @@ public class TypeTemplate
od.content = data.Clip(offset, contentLength);
var hasParent = (data[offset] & 0x80) > 0;
var hasAnnotation = (data[offset] & 0x40) > 0;
od.templateType = (TemplateType)(data[offset++] & 0xF);
od.classId = data.GetGuid(offset);
@ -862,6 +872,14 @@ public class TypeTemplate
offset += 16;
}
if (hasAnnotation)
{
var len = data.GetUInt16(offset, Endian.Little);
offset += 2;
od.Annotation = data.GetString(offset, len);
offset += len;
}
od.version = data.GetInt32(offset, Endian.Little);
offset += 4;