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:
2024-12-05 15:11:24 +03:00
parent 2bccebd419
commit ebc80b08cf
7 changed files with 98 additions and 20 deletions

View File

@ -66,8 +66,8 @@ public class FunctionTemplate : MemberTemplate
return bl.ToArray();
}
public FunctionTemplate(TypeTemplate template, byte index, string name, bool inherited, bool isStatic, ArgumentTemplate[] arguments, RepresentationType returnType, string annotation = null)
: base(template, index, name, inherited)
public FunctionTemplate(TypeTemplate template, byte index, string name, bool inherited, bool isStatic, ArgumentTemplate[] arguments, RepresentationType returnType, string annotation = null)
: base(template, index, name, inherited)
{
this.Arguments = arguments;
this.ReturnType = returnType;
@ -82,9 +82,25 @@ public class FunctionTemplate : MemberTemplate
var genericRtType = mi.ReturnType.IsGenericType ? mi.ReturnType.GetGenericTypeDefinition() : null;
var rtType = genericRtType == typeof(AsyncReply<>) ?
RepresentationType.FromType(mi.ReturnType.GetGenericArguments()[0]) :
RepresentationType.FromType(mi.ReturnType);
RepresentationType rtType;
if (genericRtType == typeof(AsyncReply<>))
{
rtType = RepresentationType.FromType(mi.ReturnType.GetGenericArguments()[0]);
}
else if (genericRtType == typeof(IEnumerable<>) || genericRtType == typeof(IAsyncEnumerable<>))
{
// get export
rtType = RepresentationType.FromType(mi.GetCustomAttribute<ExportAttribute>()?.ReturnType ?? typeof(object));
}
else
{
rtType = RepresentationType.FromType(mi.ReturnType);
}
//var rtType = genericRtType == typeof(AsyncReply<>) ?
// RepresentationType.FromType(mi.ReturnType.GetGenericArguments()[0]) :
// RepresentationType.FromType(mi.ReturnType);
if (rtType == null)
throw new Exception($"Unsupported type `{mi.ReturnType}` in method `{type.Name}.{mi.Name}` return");
@ -106,7 +122,7 @@ public class FunctionTemplate : MemberTemplate
//var rtNullableAttr = mi.ReturnTypeCustomAttributes.GetCustomAttributes(typeof(NullableAttribute), true).FirstOrDefault() as NullableAttribute;
var rtNullableAttr = mi.ReturnTypeCustomAttributes.GetCustomAttributes(true).FirstOrDefault(x => x.GetType().FullName == "System.Runtime.CompilerServices.NullableAttribute");
// var rtNullableContextAttr = mi.ReturnTypeCustomAttributes
// .GetCustomAttributes(typeof(NullableContextAttribute), true)
@ -115,7 +131,7 @@ public class FunctionTemplate : MemberTemplate
var rtNullableContextAttr = mi.ReturnTypeCustomAttributes
.GetCustomAttributes(true).FirstOrDefault(x=>x.GetType().Name == "NullableContextAttribute")
.GetCustomAttributes(true).FirstOrDefault(x => x.GetType().Name == "NullableContextAttribute")
?? nullableContextAttr;
var rtNullableAttrFlags = (rtNullableAttr?.GetType().GetField("NullableFlags")?.GetValue(rtNullableAttr) as byte[] ?? new byte[0]).ToList();
@ -164,7 +180,7 @@ public class FunctionTemplate : MemberTemplate
var argNullableAttr = x.GetCustomAttributes(true).FirstOrDefault(x => x.GetType().FullName == "System.Runtime.CompilerServices.NullableAttribute");
var argNullableContextAttr = x.GetCustomAttributes(true).FirstOrDefault(x => x.GetType().FullName == "System.Runtime.CompilerServices.NullableContextAttr");
//var argFlags = argNullableAttr?.Flags?.ToList() ?? new List<byte>();
//var argFlags = ((byte[])argNullableAttr?.NullableFlags ?? new byte[0]).ToList();
@ -196,7 +212,7 @@ public class FunctionTemplate : MemberTemplate
})
.ToArray();
var fn = customName ?? mi.Name;
var fn = customName ?? mi.Name;
var ft = new FunctionTemplate(typeTemplate, index, fn, mi.DeclaringType != type,
mi.IsStatic,

View File

@ -16,10 +16,14 @@ public class MemberData
public MemberData? Parent;
public MemberData? Child;
public byte Index;
//public ExportAttribute ExportAttribute;
public MemberData(string name, MemberInfo info, int order)
//public string Name => ExportAttribute?.Name ?? Info.Name;
public MemberData(MemberInfo info, int order)
{
this.Name = name;
this.Name = info.GetCustomAttribute<ExportAttribute>()?.Name ?? info.Name;
this.Info = info;
this.Order = order;
}

View File

@ -611,7 +611,6 @@ public class TypeTemplate
)
))
.Select(x => new MemberData(
name: x.GetCustomAttribute<ExportAttribute>()?.Name ?? x.Name,
info: x,
order: order
))
@ -631,7 +630,6 @@ public class TypeTemplate
.Where(x => x.GetCustomAttribute<ExportAttribute>() != null)
.Where(x => !(x is MethodInfo m && m.IsSpecialName))
.Select(x => new MemberData (
name : x.GetCustomAttribute<ExportAttribute>()?.Name ?? x.Name,
info : x,
order : order
))