private static DynamicMethodHandle GetCachedMethod(object obj, MethodInfo info, params object[] parameters) { MethodCacheKey key = new MethodCacheKey(obj.GetType().FullName, info.Name, MethodCaller.GetParameterTypes(parameters)); DynamicMethodHandle dynamicMethodHandle = null; if (MethodCaller._methodCache.TryGetValue(key, out dynamicMethodHandle)) { return(dynamicMethodHandle); } lock (MethodCaller._methodCache) { if (!MethodCaller._methodCache.TryGetValue(key, out dynamicMethodHandle)) { dynamicMethodHandle = new DynamicMethodHandle(info, parameters); MethodCaller._methodCache.Add(key, dynamicMethodHandle); } } return(dynamicMethodHandle); }
internal static DynamicMemberHandle GetCachedProperty(Type objectType, string propertyName) { MethodCacheKey key = new MethodCacheKey(objectType.FullName, propertyName, MethodCaller.GetParameterTypes(null)); DynamicMemberHandle dynamicMemberHandle = null; if (MethodCaller._memberCache.TryGetValue(key, out dynamicMemberHandle)) { return(dynamicMemberHandle); } lock (MethodCaller._memberCache) { if (!MethodCaller._memberCache.TryGetValue(key, out dynamicMemberHandle)) { PropertyInfo propertyInfo = MethodCaller.FindProperty(objectType, propertyName); if (propertyInfo != null) { dynamicMemberHandle = new DynamicMemberHandle(propertyInfo); } MethodCaller._memberCache.Add(key, dynamicMemberHandle); } } return(dynamicMemberHandle); }
internal static DynamicMemberHandle GetCachedField(Type objectType, string fieldName) { MethodCacheKey key = new MethodCacheKey(objectType.FullName, fieldName, MethodCaller.GetParameterTypes(null)); DynamicMemberHandle dynamicMemberHandle = null; if (MethodCaller._memberCache.TryGetValue(key, out dynamicMemberHandle)) { return(dynamicMemberHandle); } lock (MethodCaller._memberCache) { if (!MethodCaller._memberCache.TryGetValue(key, out dynamicMemberHandle)) { FieldInfo field = objectType.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { dynamicMemberHandle = new DynamicMemberHandle(field); } MethodCaller._memberCache.Add(key, dynamicMemberHandle); } } return(dynamicMemberHandle); }
public override bool Equals(object obj) { MethodCacheKey key = obj as MethodCacheKey; return(((key != null) && (key.TypeName == this.TypeName)) && ((key.MethodName == this.MethodName) && this.ArrayEquals(key.ParamTypes, this.ParamTypes))); }