using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; namespace Island.StandardLib.Reflection { public class DynamicType { public Type ClassType { get; private set; } Dictionary CachedMethods; Dictionary CachedMembers; public DynamicType(Type classType) { ClassType = classType; CachedMethods = new Dictionary(); CachedMembers = new Dictionary(); } public MethodInfo[] FindMethod(string methodName) { if (CachedMethods.TryGetValue(methodName, out MethodInfo[] result)) return result; MethodInfo[] methods = (from met in ClassType.GetMethods() where met.Name == methodName select met).ToArray(); if (methods.Length == 0) return methods; CachedMethods.Add(methodName, methods); return methods; } public MemberInfo FindMember(string memberName) { if (CachedMembers.TryGetValue(memberName, out MemberInfo result)) return result; MemberInfo[] members = (from meb in ClassType.GetMembers() where meb.Name == memberName select meb).ToArray(); if (members.Length == 0) return null; CachedMembers.Add(memberName, members[0]); return members[0]; } } }