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:
@ -4,7 +4,7 @@ using System.Text;
|
||||
|
||||
namespace Esiur.Resource;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Event)]
|
||||
[AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Event)]
|
||||
public class AnnotationAttribute : Attribute
|
||||
{
|
||||
|
||||
@ -13,4 +13,8 @@ public class AnnotationAttribute : Attribute
|
||||
{
|
||||
this.Annotation = annotation;
|
||||
}
|
||||
public AnnotationAttribute(params string[] annotations)
|
||||
{
|
||||
this.Annotation = String.Join("\n", annotations);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user