61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
namespace ln.http.resources.reflection
|
|
{
|
|
public class Reflector
|
|
{
|
|
Type TargetType { get; }
|
|
|
|
Dictionary<string, PropertyInfo> properties = new Dictionary<string, PropertyInfo>();
|
|
Dictionary<string, MethodInfo> methods = new Dictionary<string, MethodInfo>();
|
|
|
|
public Reflector(Type targetType)
|
|
{
|
|
TargetType = targetType;
|
|
Initialize();
|
|
}
|
|
|
|
private void Initialize()
|
|
{
|
|
foreach (PropertyInfo propertyInfo in TargetType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
|
{
|
|
if (propertyInfo.GetCustomAttribute<CallableAttribute>() != null)
|
|
{
|
|
properties.Add(propertyInfo.Name, propertyInfo);
|
|
}
|
|
}
|
|
foreach (MethodInfo methodInfo in TargetType.GetMethods(BindingFlags.Public | BindingFlags.Instance))
|
|
{
|
|
if (methodInfo.GetCustomAttribute<CallableAttribute>() != null)
|
|
{
|
|
methods.Add(methodInfo.Name, methodInfo);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public object InvokeRequest(HttpRequest httpRequest,Queue<string> pathStack,object currentValue)
|
|
{
|
|
if (pathStack.Count == 0)
|
|
return currentValue;
|
|
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Dictionary<Type, Reflector> reflectorsCache = new Dictionary<Type, Reflector>();
|
|
public static Reflector GetReflector(Type targetType)
|
|
{
|
|
if (!reflectorsCache.ContainsKey(targetType))
|
|
{
|
|
reflectorsCache[targetType] = new Reflector(targetType);
|
|
}
|
|
return reflectorsCache[targetType];
|
|
}
|
|
}
|
|
}
|