mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-01-27 01:20:39 +00:00
Merge branch 'ver-3' of https://github.com/esiur/esiur-dotnet into ver-3
This commit is contained in:
@@ -174,7 +174,7 @@ public class DistributedServer : NetworkServer<DistributedConnection>, IResource
|
|||||||
|
|
||||||
public DistributedServer MapCall(string call, Delegate handler)
|
public DistributedServer MapCall(string call, Delegate handler)
|
||||||
{
|
{
|
||||||
var ft = FunctionTemplate.MakeFunctionTemplate(null, handler.Method);
|
var ft = FunctionTemplate.MakeFunctionTemplate(null, handler.Method, 0, call, null);
|
||||||
Calls.Add(call, new CallInfo() { Delegate = handler, Template = ft });
|
Calls.Add(call, new CallInfo() { Delegate = handler, Template = ft });
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
using static Esiur.Resource.Template.PropertyTemplate;
|
||||||
|
|
||||||
namespace Esiur.Resource;
|
namespace Esiur.Resource;
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ namespace Esiur.Resource;
|
|||||||
public class ExportAttribute : Attribute
|
public class ExportAttribute : Attribute
|
||||||
{
|
{
|
||||||
public string Name { get; private set; } = null;
|
public string Name { get; private set; } = null;
|
||||||
|
public PropertyPermission? Permission { get; private set; }
|
||||||
|
|
||||||
public ExportAttribute()
|
public ExportAttribute()
|
||||||
{
|
{
|
||||||
@@ -21,4 +23,17 @@ public class ExportAttribute : Attribute
|
|||||||
Name = name;
|
Name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ExportAttribute(PropertyPermission permission)
|
||||||
|
{
|
||||||
|
Permission = permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ExportAttribute(string name, PropertyPermission permission)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Permission = permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
13
Esiur/Resource/PropertyPermission.cs
Normal file
13
Esiur/Resource/PropertyPermission.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Esiur.Resource
|
||||||
|
{
|
||||||
|
public enum PropertyPermission : byte
|
||||||
|
{
|
||||||
|
Read = 1,
|
||||||
|
Write,
|
||||||
|
ReadWrite,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,13 +18,13 @@ public class AttributeTemplate : MemberTemplate
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static AttributeTemplate MakeAttributeTemplate(Type type, PropertyInfo pi, byte index = 0, string customName = null, TypeTemplate typeTemplate = null)
|
public static AttributeTemplate MakeAttributeTemplate(Type type, PropertyInfo pi, byte index, string name, TypeTemplate typeTemplate )
|
||||||
{
|
{
|
||||||
return new AttributeTemplate()
|
return new AttributeTemplate()
|
||||||
{
|
{
|
||||||
Index = index,
|
Index = index,
|
||||||
Inherited = pi.DeclaringType != type,
|
Inherited = pi.DeclaringType != type,
|
||||||
Name = customName,
|
Name = name,
|
||||||
PropertyInfo = pi
|
PropertyInfo = pi
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class EventTemplate : MemberTemplate
|
|||||||
// this.ArgumentType = argumentType;
|
// this.ArgumentType = argumentType;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
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, string name, TypeTemplate typeTemplate)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!ei.EventHandlerType.IsGenericType)
|
if (!ei.EventHandlerType.IsGenericType)
|
||||||
@@ -173,7 +173,7 @@ public class EventTemplate : MemberTemplate
|
|||||||
|
|
||||||
return new EventTemplate()
|
return new EventTemplate()
|
||||||
{
|
{
|
||||||
Name = customName ?? ei.Name,
|
Name = name,
|
||||||
ArgumentType = evtType,
|
ArgumentType = evtType,
|
||||||
Index = index,
|
Index = index,
|
||||||
Inherited = ei.DeclaringType != type,
|
Inherited = ei.DeclaringType != type,
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ public class FunctionTemplate : MemberTemplate
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static FunctionTemplate MakeFunctionTemplate(Type type, MethodInfo mi, byte index = 0, string customName = null, TypeTemplate typeTemplate = null)
|
public static FunctionTemplate MakeFunctionTemplate(Type type, MethodInfo mi, byte index, string name, TypeTemplate typeTemplate)
|
||||||
{
|
{
|
||||||
|
|
||||||
var genericRtType = mi.ReturnType.IsGenericType ? mi.ReturnType.GetGenericTypeDefinition() : null;
|
var genericRtType = mi.ReturnType.IsGenericType ? mi.ReturnType.GetGenericTypeDefinition() : null;
|
||||||
@@ -292,7 +292,7 @@ public class FunctionTemplate : MemberTemplate
|
|||||||
|
|
||||||
return new FunctionTemplate()
|
return new FunctionTemplate()
|
||||||
{
|
{
|
||||||
Name = customName ?? mi.Name,
|
Name = name,
|
||||||
Index = index,
|
Index = index,
|
||||||
Inherited = mi.DeclaringType != type,
|
Inherited = mi.DeclaringType != type,
|
||||||
IsStatic = mi.IsStatic,
|
IsStatic = mi.IsStatic,
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ public class MemberData
|
|||||||
public MemberData? Parent;
|
public MemberData? Parent;
|
||||||
public MemberData? Child;
|
public MemberData? Child;
|
||||||
public byte Index;
|
public byte Index;
|
||||||
|
|
||||||
|
public PropertyPermission PropertyPermission;
|
||||||
|
|
||||||
//public ExportAttribute ExportAttribute;
|
//public ExportAttribute ExportAttribute;
|
||||||
|
|
||||||
|
|
||||||
@@ -23,7 +26,35 @@ public class MemberData
|
|||||||
|
|
||||||
public MemberData(MemberInfo info, int order)
|
public MemberData(MemberInfo info, int order)
|
||||||
{
|
{
|
||||||
this.Name = info.GetCustomAttribute<ExportAttribute>()?.Name ?? info.Name;
|
var exportAttr = info.GetCustomAttribute<ExportAttribute>();
|
||||||
|
|
||||||
|
if (info is PropertyInfo pi)
|
||||||
|
{
|
||||||
|
if (exportAttr != null && exportAttr.Permission.HasValue)
|
||||||
|
{
|
||||||
|
if ((exportAttr.Permission == PropertyPermission.Write
|
||||||
|
|| exportAttr.Permission == PropertyPermission.ReadWrite) && !pi.CanWrite)
|
||||||
|
{
|
||||||
|
throw new Exception($"Property '{pi.Name}' does not have a setter, but ExportAttribute specifies it as writable.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((exportAttr.Permission == PropertyPermission.Read
|
||||||
|
|| exportAttr.Permission == PropertyPermission.ReadWrite) && !pi.CanRead)
|
||||||
|
{
|
||||||
|
throw new Exception($"Property '{pi.Name}' does not have a getter, but ExportAttribute specifies it as readable.");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.PropertyPermission = exportAttr.Permission.Value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.PropertyPermission = (pi.CanRead && pi.CanWrite) ? PropertyPermission.ReadWrite
|
||||||
|
: pi.CanWrite ? PropertyPermission.Write
|
||||||
|
: PropertyPermission.Read;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Name = exportAttr?.Name ?? info.Name;
|
||||||
this.Info = info;
|
this.Info = info;
|
||||||
this.Order = order;
|
this.Order = order;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,7 @@ public class PropertyTemplate : MemberTemplate
|
|||||||
{
|
{
|
||||||
public Map<string, string> Annotations { get; set; }
|
public Map<string, string> Annotations { get; set; }
|
||||||
|
|
||||||
public enum PropertyPermission : byte
|
|
||||||
{
|
|
||||||
Read = 1,
|
|
||||||
Write,
|
|
||||||
ReadWrite
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public PropertyInfo PropertyInfo
|
public PropertyInfo PropertyInfo
|
||||||
@@ -92,7 +87,7 @@ public class PropertyTemplate : MemberTemplate
|
|||||||
|
|
||||||
var hasAnnotation = ((data[offset] & 0x8) == 0x8);
|
var hasAnnotation = ((data[offset] & 0x8) == 0x8);
|
||||||
var recordable = ((data[offset] & 1) == 1);
|
var recordable = ((data[offset] & 1) == 1);
|
||||||
var permission = (PropertyTemplate.PropertyPermission)((data[offset++] >> 1) & 0x3);
|
var permission = (PropertyPermission)((data[offset++] >> 1) & 0x3);
|
||||||
var name = data.GetString(offset + 1, data[offset]);
|
var name = data.GetString(offset + 1, data[offset]);
|
||||||
|
|
||||||
offset += (uint)data[offset] + 1;
|
offset += (uint)data[offset] + 1;
|
||||||
@@ -209,7 +204,7 @@ public class PropertyTemplate : MemberTemplate
|
|||||||
// this.ValueType = valueType;
|
// this.ValueType = valueType;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
public static PropertyTemplate MakePropertyTemplate(Type type, PropertyInfo pi, byte index = 0, string customName = null, TypeTemplate typeTemplate = null)
|
public static PropertyTemplate MakePropertyTemplate(Type type, PropertyInfo pi, string name, byte index, PropertyPermission permission, TypeTemplate typeTemplate)
|
||||||
{
|
{
|
||||||
var genericPropType = pi.PropertyType.IsGenericType ? pi.PropertyType.GetGenericTypeDefinition() : null;
|
var genericPropType = pi.PropertyType.IsGenericType ? pi.PropertyType.GetGenericTypeDefinition() : null;
|
||||||
|
|
||||||
@@ -269,15 +264,16 @@ public class PropertyTemplate : MemberTemplate
|
|||||||
annotations.Add("", GetTypeAnnotationName(pi.PropertyType));
|
annotations.Add("", GetTypeAnnotationName(pi.PropertyType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return new PropertyTemplate()
|
return new PropertyTemplate()
|
||||||
{
|
{
|
||||||
Name = customName ?? pi.Name,
|
Name = name,
|
||||||
Index = index,
|
Index = index,
|
||||||
Inherited = pi.DeclaringType != type,
|
Inherited = pi.DeclaringType != type,
|
||||||
ValueType = propType,
|
ValueType = propType,
|
||||||
PropertyInfo = pi,
|
PropertyInfo = pi,
|
||||||
Recordable = storageAttr == null ? false : storageAttr.Mode == StorageMode.Recordable,
|
Recordable = storageAttr == null ? false : storageAttr.Mode == StorageMode.Recordable,
|
||||||
Permission = (pi.CanWrite && pi.CanRead) ? PropertyPermission.ReadWrite : (pi.CanWrite ? PropertyPermission.Write : PropertyPermission.Read),
|
Permission = permission,
|
||||||
Annotations = annotations,
|
Annotations = annotations,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ public class TypeTemplate
|
|||||||
foreach (var pd in hierarchy[MemberTypes.Property])
|
foreach (var pd in hierarchy[MemberTypes.Property])
|
||||||
{
|
{
|
||||||
properties.Add(PropertyTemplate.MakePropertyTemplate
|
properties.Add(PropertyTemplate.MakePropertyTemplate
|
||||||
(type, (PropertyInfo)pd.GetMemberInfo(), pd.Index, pd.Name, this));
|
(type, (PropertyInfo)pd.GetMemberInfo(), pd.Name, pd.Index, pd.PropertyPermission, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user