private static DynamicMethodHandle GetCachedMethod(object obj, System.Reflection.MethodInfo info, params object[] parameters) { var key = new MethodCacheKey(obj.GetType().FullName, info.Name, GetParameterTypes(parameters)); DynamicMethodHandle mh = null; var found = false; try { found = _methodCache.TryGetValue(key, out mh); } catch { /* failure will drop into !found block */ } if (!found) { lock (_methodCache) { if (!_methodCache.TryGetValue(key, out mh)) { mh = new DynamicMethodHandle(info, parameters); _methodCache.Add(key, mh); } } } return(mh); }
public override bool Equals(object obj) { MethodCacheKey key = obj as MethodCacheKey; if (key != null && key.TypeName == this.TypeName && key.MethodName == this.MethodName && ArrayEquals(key.ParamTypes, this.ParamTypes)) { return(true); } return(false); }
private static DynamicMethodHandle GetCachedMethod(object obj, System.Reflection.MethodInfo info, params object[] parameters) { var key = new MethodCacheKey(obj.GetType().FullName, info.Name, GetParameterTypes(parameters)); DynamicMethodHandle mh = null; if (!_methodCache.TryGetValue(key, out mh)) { lock (_methodCache) { if (!_methodCache.TryGetValue(key, out mh)) { mh = new DynamicMethodHandle(info, parameters); _methodCache.Add(key, mh); } } } return(mh); }
private static DynamicMethodHandle GetCachedMethod(object obj, string method, bool hasParameters, params object[] parameters) { var key = new MethodCacheKey(obj.GetType().FullName, method, GetParameterTypes(hasParameters, parameters)); DynamicMethodHandle mh = null; if (!_methodCache.TryGetValue(key, out mh)) { lock (_methodCache) { if (!_methodCache.TryGetValue(key, out mh)) { var info = GetMethod(obj.GetType(), method, hasParameters, parameters); mh = new DynamicMethodHandle(info, parameters); _methodCache.Add(key, mh); } } } return(mh); }
private static DynamicMethodHandle GetCachedMethod(object obj, System.Reflection.MethodInfo info, params object[] parameters) { var key = new MethodCacheKey(obj.GetType().FullName, info.Name, GetParameterTypes(parameters)); DynamicMethodHandle mh = null; var found = false; try { found = _methodCache.TryGetValue(key, out mh); } catch { /* failure will drop into !found block */ } if (!found) { lock (_methodCache) { if (!_methodCache.TryGetValue(key, out mh)) { mh = new DynamicMethodHandle(info, parameters); _methodCache.Add(key, mh); } } } return mh; }
public static DataPortalMethodInfo GetMethodInfo(Type objectType, string methodName, params object[] parameters) { var key = new MethodCacheKey(objectType.FullName, methodName, MethodCaller.GetParameterTypes(parameters)); DataPortalMethodInfo result = null; var found = false; try { found = _cache.TryGetValue(key, out result); } catch { /* failure will drop into !found block */ } if (!found) { lock (_cache) { if (!_cache.TryGetValue(key, out result)) { result = new DataPortalMethodInfo(MethodCaller.GetMethod(objectType, methodName, parameters)); _cache.Add(key, result); } } } return result; }
internal static DynamicMemberHandle GetCachedField(Type objectType, string fieldName) { var key = new MethodCacheKey(objectType.FullName, fieldName, GetParameterTypes(null)); DynamicMemberHandle mh = null; if (!_memberCache.TryGetValue(key, out mh)) { lock (_memberCache) { if (!_memberCache.TryGetValue(key, out mh)) { FieldInfo info = objectType.GetField(fieldName, fieldFlags); if (info == null) { throw new InvalidOperationException( string.Format(Resources.MemberNotFoundException, fieldName)); } mh = new DynamicMemberHandle(info); _memberCache.Add(key, mh); } } } return(mh); }
private static DynamicMethodHandle GetCachedMethod(object obj, string method, bool hasParameters, params object[] parameters) { var key = new MethodCacheKey(obj.GetType().FullName, method, GetParameterTypes(hasParameters, parameters)); DynamicMethodHandle mh = null; if (!_methodCache.TryGetValue(key, out mh)) { lock (_methodCache) { if (!_methodCache.TryGetValue(key, out mh)) { var info = GetMethod(obj.GetType(), method, hasParameters, parameters); mh = new DynamicMethodHandle(info, parameters); _methodCache.Add(key, mh); } } } return mh; }
internal static DynamicMemberHandle GetCachedField(Type objectType, string fieldName) { var key = new MethodCacheKey(objectType.FullName, fieldName, GetParameterTypes(null)); DynamicMemberHandle mh = null; if (!_memberCache.TryGetValue(key, out mh)) { lock (_memberCache) { if (!_memberCache.TryGetValue(key, out mh)) { FieldInfo info = objectType.GetField(fieldName, fieldFlags); if (info == null) throw new InvalidOperationException( string.Format(Resources.MemberNotFoundException, fieldName)); mh = new DynamicMemberHandle(info); _memberCache.Add(key, mh); } } } return mh; }