mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 11:32:59 +00:00
Events
This commit is contained in:
parent
0e865406eb
commit
3c1e0fd9db
@ -1,4 +1,5 @@
|
|||||||
using Esiur.Data;
|
using Esiur.Core;
|
||||||
|
using Esiur.Data;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -46,16 +47,16 @@ public class EventTemplate : MemberTemplate
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
hdr |= 0x40;
|
hdr |= 0x40;
|
||||||
return new BinaryList()
|
return new BinaryList()
|
||||||
.AddUInt8(hdr)
|
.AddUInt8(hdr)
|
||||||
.AddUInt8((byte)name.Length)
|
.AddUInt8((byte)name.Length)
|
||||||
.AddUInt8Array(name)
|
.AddUInt8Array(name)
|
||||||
.AddUInt8Array(ArgumentType.Compose())
|
.AddUInt8Array(ArgumentType.Compose())
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventTemplate(TypeTemplate template, byte index, string name,bool inherited, RepresentationType argumentType, string annotation = null, bool listenable = false)
|
public EventTemplate(TypeTemplate template, byte index, string name, bool inherited, RepresentationType argumentType, string annotation = null, bool listenable = false)
|
||||||
: base(template, index, name, inherited)
|
: base(template, index, name, inherited)
|
||||||
{
|
{
|
||||||
this.Annotation = annotation;
|
this.Annotation = annotation;
|
||||||
this.Listenable = listenable;
|
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)
|
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 argType = ei.EventHandlerType.GenericTypeArguments[0];
|
||||||
var evtType = RepresentationType.FromType(argType);
|
var evtType = RepresentationType.FromType(argType);
|
||||||
|
|
||||||
|
@ -599,7 +599,14 @@ public class TypeTemplate
|
|||||||
|| x.MemberType == MemberTypes.Event || x.MemberType == MemberTypes.Method)
|
|| x.MemberType == MemberTypes.Event || x.MemberType == MemberTypes.Method)
|
||||||
.Where(x => !(x is FieldInfo c && !c.IsStatic))
|
.Where(x => !(x is FieldInfo c && !c.IsStatic))
|
||||||
.Where(x => x.GetCustomAttribute<IgnoreAttribute>() == null)
|
.Where(x => x.GetCustomAttribute<IgnoreAttribute>() == null)
|
||||||
|
.Where(x => x.Name != "Instance")
|
||||||
.Where(x => !(x is MethodInfo m && m.IsSpecialName))
|
.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()
|
.Select(x => new MemberData()
|
||||||
{
|
{
|
||||||
Name = x.GetCustomAttribute<ExportAttribute>()?.Name ?? x.Name,
|
Name = x.GetCustomAttribute<ExportAttribute>()?.Name ?? x.Name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user