2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-05-06 11:32:59 +00:00
This commit is contained in:
Ahmed Zamil 2024-02-06 13:45:54 +03:00
parent 0e865406eb
commit 3c1e0fd9db
2 changed files with 29 additions and 12 deletions

View File

@ -1,4 +1,5 @@
using Esiur.Data;
using Esiur.Core;
using Esiur.Data;
using System;
using System.Collections.Generic;
using System.Linq;
@ -27,7 +28,7 @@ public class EventTemplate : MemberTemplate
var name = base.Compose();
var hdr = Inherited ? (byte)0x80 : (byte)0;
if (Listenable)
hdr |= 0x8;
@ -46,16 +47,16 @@ public class EventTemplate : MemberTemplate
}
else
hdr |= 0x40;
return new BinaryList()
.AddUInt8(hdr)
.AddUInt8((byte)name.Length)
.AddUInt8Array(name)
.AddUInt8Array(ArgumentType.Compose())
.ToArray();
return new BinaryList()
.AddUInt8(hdr)
.AddUInt8((byte)name.Length)
.AddUInt8Array(name)
.AddUInt8Array(ArgumentType.Compose())
.ToArray();
}
public EventTemplate(TypeTemplate template, byte index, string name,bool inherited, RepresentationType argumentType, string annotation = null, bool listenable = false)
: base(template, index, name, inherited)
public EventTemplate(TypeTemplate template, byte index, string name, bool inherited, RepresentationType argumentType, string annotation = null, bool listenable = false)
: base(template, index, name, inherited)
{
this.Annotation = annotation;
this.Listenable = listenable;
@ -64,6 +65,15 @@ public class EventTemplate : MemberTemplate
public static EventTemplate MakeEventTemplate(Type type, EventInfo ei, byte index = 0, string customName = null, TypeTemplate typeTemplate = null)
{
if (!ei.EventHandlerType.IsGenericType)
throw new Exception($"Unsupported event handler type in event `{type.Name}.{ei.Name}`");
if (ei.EventHandlerType.GetGenericTypeDefinition() != typeof(ResourceEventHandler<>)
&& ei.EventHandlerType.GetGenericTypeDefinition() != typeof(CustomResourceEventHandler<>))
throw new Exception($"Unsupported event handler type in event `{type.Name}.{ei.Name}`");
var argType = ei.EventHandlerType.GenericTypeArguments[0];
var evtType = RepresentationType.FromType(argType);

View File

@ -170,7 +170,7 @@ public class TypeTemplate
var rt = new Guid(hash);
return rt;
}
static Type[] GetDistributedTypes(Type type)
{
if (type.IsArray)
@ -593,13 +593,20 @@ public class TypeTemplate
if (classIsPublic)
{
var mis = type.GetMembers(BindingFlags.Public | BindingFlags.Instance
var mis = type.GetMembers(BindingFlags.Public | BindingFlags.Instance
| BindingFlags.DeclaredOnly | BindingFlags.Static)
.Where(x => x.MemberType == MemberTypes.Property || x.MemberType == MemberTypes.Field
|| x.MemberType == MemberTypes.Event || x.MemberType == MemberTypes.Method)
.Where(x => !(x is FieldInfo c && !c.IsStatic))
.Where(x => x.GetCustomAttribute<IgnoreAttribute>() == null)
.Where(x => x.Name != "Instance")
.Where(x => !(x is MethodInfo m && m.IsSpecialName))
.Where(x=> !(x is EventInfo e &&
!(e.EventHandlerType.IsGenericType &&
(e.EventHandlerType.GetGenericTypeDefinition() == typeof(ResourceEventHandler<>)
|| e.EventHandlerType.GetGenericTypeDefinition() == typeof(CustomResourceEventHandler<>))
)
))
.Select(x => new MemberData()
{
Name = x.GetCustomAttribute<ExportAttribute>()?.Name ?? x.Name,