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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -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);

View File

@ -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,