2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-26 21:13:13 +00:00

GetHierarchy

This commit is contained in:
2022-08-20 01:57:18 +03:00
parent ebcf8525fa
commit acc2a546cf
9 changed files with 280 additions and 153 deletions

View File

@ -11,5 +11,6 @@ namespace Test
public class MyChildRecord : MyRecord
{
public string ChildName { get; set; }
}
}

View File

@ -11,6 +11,10 @@ namespace Test
public partial class MyChildResource : MyResource
{
[Public] string childName;
[Public] public int ChildMethod(string childName) => 111;
[Public("Hell2o")] public int ChildMethod(string childName) => 111;
[Public] public new string Hello() => "Hi from Child";
[Public] public string HelloChild() => "Hi from Child";
}
}

View File

@ -13,5 +13,11 @@ namespace Test
{
[Public][Annotation("Comment")] string description;
[Public] int categoryId;
[Public] public string Hello() => "Hi";
[Public] public string HelloParent() => "Hi from Parent";
}
}

View File

@ -42,6 +42,7 @@ using System.Runtime.CompilerServices;
using Esiur.Proxy;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Reflection;
namespace Test
{
@ -54,6 +55,10 @@ namespace Test
static async Task Main(string[] args)
{
var ppp = GetOrderedProperties(typeof(MyChildResource)).ToArray();
var childMethods = typeof(MyChildResource).GetMembers( BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance);
var parentMethods = typeof(MyResource).GetMethods(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance);
// Create stores to keep objects.
var system = await Warehouse.Put("sys", new MemoryStore());
var server = await Warehouse.Put("sys/server", new DistributedServer());
@ -222,6 +227,28 @@ namespace Test
return value.ToString();
}
public static IEnumerable<PropertyInfo> GetOrderedProperties(Type type)
{
Dictionary<Type, int> lookup = new Dictionary<Type, int>();
int count = 0;
lookup[type] = count++;
Type parent = type.BaseType;
while (parent != null)
{
lookup[parent] = count;
count++;
parent = parent.BaseType;
}
return type.GetProperties()
.OrderByDescending(prop => lookup[prop.DeclaringType]);
}
}