diff --git a/Esiur/Data/NullableAttribute.cs b/Esiur/Data/NullableAttribute.cs
new file mode 100644
index 0000000..ac8fde7
--- /dev/null
+++ b/Esiur/Data/NullableAttribute.cs
@@ -0,0 +1,27 @@
+namespace System.Runtime.CompilerServices
+{
+ [AttributeUsage(
+ AttributeTargets.Class |
+ AttributeTargets.Event |
+ AttributeTargets.Field |
+ AttributeTargets.GenericParameter |
+ AttributeTargets.Parameter |
+ AttributeTargets.Property |
+ AttributeTargets.ReturnValue,
+ AllowMultiple = false,
+ Inherited = false)]
+ public sealed class NullableAttribute : Attribute
+ {
+ public readonly byte[] Flags;
+ public readonly byte Flag;
+
+ public NullableAttribute(byte flag)
+ {
+ Flag = flag;// new byte[] { flag };
+ }
+ public NullableAttribute(byte[] flags)
+ {
+ Flags = flags;
+ }
+ }
+}
diff --git a/Esiur/Data/NullableContextAttribute.cs b/Esiur/Data/NullableContextAttribute.cs
new file mode 100644
index 0000000..2a6b51c
--- /dev/null
+++ b/Esiur/Data/NullableContextAttribute.cs
@@ -0,0 +1,19 @@
+namespace System.Runtime.CompilerServices
+{
+ [System.AttributeUsage(
+ AttributeTargets.Class |
+ AttributeTargets.Delegate |
+ AttributeTargets.Interface |
+ AttributeTargets.Method |
+ AttributeTargets.Struct,
+ AllowMultiple = false,
+ Inherited = false)]
+ public sealed class NullableContextAttribute : Attribute
+ {
+ public readonly byte Flag;
+ public NullableContextAttribute(byte flag)
+ {
+ Flag = flag;
+ }
+ }
+}
diff --git a/Esiur/Data/RepresentationType.cs b/Esiur/Data/RepresentationType.cs
index c1fb14e..0d355ad 100644
--- a/Esiur/Data/RepresentationType.cs
+++ b/Esiur/Data/RepresentationType.cs
@@ -89,14 +89,20 @@ namespace Esiur.Data
public RepresentationType?[] SubTypes = new RepresentationType[3];
- public static RepresentationType? FromType(Type type)
+ public static RepresentationType? FromType(Type type, bool forceNullable = false)
{
- var nullType = System.Nullable.GetUnderlyingType(type);
- var nullable = false;
- if (nullType != null) {
- type = nullType;
- nullable = true;
+ var nullable = forceNullable;
+
+ if (!forceNullable)
+ {
+ var nullType = System.Nullable.GetUnderlyingType(type);
+
+ if (nullType != null)
+ {
+ type = nullType;
+ nullable = true;
+ }
}
if (type.IsGenericType)
diff --git a/Esiur/Esiur.csproj b/Esiur/Esiur.csproj
index dd27022..d91b6ce 100644
--- a/Esiur/Esiur.csproj
+++ b/Esiur/Esiur.csproj
@@ -72,6 +72,7 @@
+
diff --git a/Esiur/Resource/Instance.cs b/Esiur/Resource/Instance.cs
index 7c240c1..b450f44 100644
--- a/Esiur/Resource/Instance.cs
+++ b/Esiur/Resource/Instance.cs
@@ -15,6 +15,7 @@ using Esiur.Proxy;
using Esiur.Core;
using System.Text.Json;
using System.ComponentModel.DataAnnotations.Schema;
+using System.Reflection.Emit;
namespace Esiur.Resource;
@@ -607,6 +608,27 @@ public class Instance
}
}
+ internal void EmitResourceEventByIndex(byte eventIndex, object value)
+ {
+ IResource res;
+ if (this.resource.TryGetTarget(out res))
+ {
+ var eventTemplate = template.GetEventTemplateByIndex(eventIndex);
+ EventOccurred?.Invoke(new EventOccurredInfo(res, eventTemplate, value));
+ }
+ }
+
+ internal void EmitCustomResourceEventByIndex(object issuer, Func receivers, byte eventIndex, object value)
+ {
+ IResource res;
+ if (this.resource.TryGetTarget(out res))
+ {
+ var eventTemplate = template.GetEventTemplateByIndex(eventIndex);
+ CustomEventOccurred?.Invoke(new CustomEventOccurredInfo(res, eventTemplate, receivers, issuer, value));
+ }
+ }
+
+
///
/// Get the value of a given property by name.
///
@@ -844,6 +866,13 @@ public class Instance
///
public AutoList Managers => managers;
+
+ public void CallMeTest(Instance ins, int? val) =>
+ ins.EmitResourceEventByIndex(201, val);
+
+ public void CallMeTest2(Instance instance, object issuer, Func receivers, int? val) =>
+ instance.EmitCustomResourceEventByIndex(issuer, receivers, 201, val);
+
///
/// Create new instance.
///
@@ -893,10 +922,11 @@ public class Instance
#endif
+ var emitEventByIndexMethod = GetType().GetMethod("EmitResourceEventByIndex", BindingFlags.Instance | BindingFlags.NonPublic);
+ var emitCustomEventByIndexMethod = GetType().GetMethod("EmitCustomResourceEventByIndex", BindingFlags.Instance | BindingFlags.NonPublic);
+
foreach (var evt in template.Events)
{
- //if (evt.EventHandlerType != typeof(ResourceEventHandler))
- // continue;
if (evt.EventInfo == null)
continue;
@@ -906,21 +936,51 @@ public class Instance
if (eventGenericType == typeof(ResourceEventHandler<>))
{
- // var ca = (ResourceEvent[])evt.GetCustomAttributes(typeof(ResourceEvent), true);
- // if (ca.Length == 0)
- // continue;
+ var dm = new DynamicMethod("_", null,
+ new Type[] {typeof(Instance), evt.EventInfo.EventHandlerType.GenericTypeArguments[0] },
+ typeof(Instance).Module, true);
- ResourceEventHandler