2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 05:23:13 +00:00
This commit is contained in:
2023-11-07 16:31:23 +03:00
parent d6e223384c
commit 0e865406eb
9 changed files with 32 additions and 25 deletions

View File

@ -6,11 +6,11 @@ namespace Esiur.Resource;
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Event | AttributeTargets.Class | AttributeTargets.Enum)]
public class PublicAttribute : Attribute
public class ExportAttribute : Attribute
{
public string Name { get; set; }
public PublicAttribute(string name = null)
public ExportAttribute(string name = null)
{
Name = name;
}

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Text;
namespace Esiur.Resource;
public class PrivateAttribute : Attribute
public class IgnoreAttribute : Attribute
{
}

View File

@ -588,6 +588,8 @@ public class Instance
}
}
// internal void EmitResourceEvent(string name, string[] users, DistributedConnection[] connections, object[] args)
internal void EmitCustomResourceEvent(object issuer, Func<Session, bool> receivers, EventTemplate eventTemplate, object value)

View File

@ -373,7 +373,7 @@ public class TypeTemplate
public static ConstantTemplate MakeConstantTemplate(Type type, FieldInfo ci, PublicAttribute publicAttr, byte index = 0, TypeTemplate typeTemplate = null)
public static ConstantTemplate MakeConstantTemplate(Type type, FieldInfo ci, ExportAttribute exportAttr, byte index = 0, TypeTemplate typeTemplate = null)
{
var annotationAttr = ci.GetCustomAttribute<AnnotationAttribute>(true);
var nullableAttr = ci.GetCustomAttribute<NullableAttribute>(true);
@ -388,7 +388,7 @@ public class TypeTemplate
if (typeTemplate.Type == TemplateType.Enum)
value = Convert.ChangeType(value, ci.FieldType.GetEnumUnderlyingType());
var ct = new ConstantTemplate(typeTemplate, index, publicAttr?.Name ?? ci.Name, ci.DeclaringType != type, valueType, value, annotationAttr?.Annotation);
var ct = new ConstantTemplate(typeTemplate, index, exportAttr?.Name ?? ci.Name, ci.DeclaringType != type, valueType, value, annotationAttr?.Annotation);
return ct;
@ -589,7 +589,7 @@ public class TypeTemplate
while (type != null)
{
var classIsPublic = type.IsEnum || (type.GetCustomAttribute<PublicAttribute>() != null);
var classIsPublic = type.IsEnum || (type.GetCustomAttribute<ExportAttribute>() != null);
if (classIsPublic)
{
@ -598,11 +598,11 @@ public class TypeTemplate
.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<PrivateAttribute>() == null)
.Where(x => x.GetCustomAttribute<IgnoreAttribute>() == null)
.Where(x => !(x is MethodInfo m && m.IsSpecialName))
.Select(x => new MemberData()
{
Name = x.GetCustomAttribute<PublicAttribute>()?.Name ?? x.Name,
Name = x.GetCustomAttribute<ExportAttribute>()?.Name ?? x.Name,
Info = x,
Order = order
})
@ -618,11 +618,11 @@ public class TypeTemplate
.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<PublicAttribute>() != null)
.Where(x => x.GetCustomAttribute<ExportAttribute>() != null)
.Where(x => !(x is MethodInfo m && m.IsSpecialName))
.Select(x => new MemberData
{
Name = x.GetCustomAttribute<PublicAttribute>()?.Name ?? x.Name,
Name = x.GetCustomAttribute<ExportAttribute>()?.Name ?? x.Name,
Info = x,
Order = order
})

View File

@ -375,8 +375,6 @@ public static class Warehouse
public static async AsyncReply<IResource[]> Query(string path)
{
var rt = new AsyncReply<IResource[]>();
var p = path.Trim().Split('/');
IResource resource;
@ -512,7 +510,7 @@ public static class Warehouse
var res = await Query(path);
if (res.Length == 0)
if (res == null || res.Length == 0)
return default(T);
else
return (T)res.First();