mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 05:23:13 +00:00
GetHierarchy
This commit is contained in:
@ -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]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user