#define old using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading; namespace System { public static class Extensions { #if !old private static readonly Dictionary mMethod_FullNameCache = new Dictionary(); private static readonly ReaderWriterLockSlim mMethod_FullNameCache_Locker = new ReaderWriterLockSlim(); public static string GetFullName(this MethodBase aMethod) { mMethod_FullNameCache_Locker.EnterReadLock(); try { if (mMethod_FullNameCache.ContainsKey(aMethod.MethodHandle.Value)) { var xResult = mMethod_FullNameCache[aMethod.MethodHandle.Value]; if (aMethod.GetHashCode() == 2031104736) { ; } if(!xResult.Equals(GenerateFullName(aMethod))) { throw new Exception(""); } return mMethod_FullNameCache[aMethod.MethodHandle.Value]; } } finally { mMethod_FullNameCache_Locker.ExitReadLock(); } mMethod_FullNameCache_Locker.EnterWriteLock(); try { if (mMethod_FullNameCache.ContainsKey(aMethod.MethodHandle.Value)) { var xResult = mMethod_FullNameCache[aMethod.MethodHandle.Value]; if (!xResult.Equals(GenerateFullName(aMethod))) { throw new Exception(""); } return mMethod_FullNameCache[aMethod.MethodHandle.Value]; } var xName = GenerateFullName(aMethod); mMethod_FullNameCache.Add(aMethod.MethodHandle.Value, xName); return xName; } finally { mMethod_FullNameCache_Locker.ExitWriteLock(); } } #else public static string GetFullName(this MethodBase aMethod) { return GenerateFullName(aMethod); } #endif private static string GenerateFullName(MethodBase aMethod) { if (aMethod == null) { throw new ArgumentNullException("aMethod"); } var xBuilder = new StringBuilder(256); var xParts = aMethod.ToString().Split(' '); var xParts2 = xParts.Skip(1).ToArray(); var xMethodInfo = aMethod as MethodInfo; if (xMethodInfo != null) { xBuilder.Append(xMethodInfo.ReturnType.FullName); } else { var xCtor = aMethod as ConstructorInfo; if (xCtor != null) { xBuilder.Append(typeof (void).FullName); } else { xBuilder.Append(xParts[0]); } } xBuilder.Append(" "); xBuilder.Append(aMethod.DeclaringType.FullName); xBuilder.Append("."); xBuilder.Append(aMethod.Name); xBuilder.Append("("); var xParams = aMethod.GetParameters(); for (var i = 0; i < xParams.Length; i++) { if (xParams[i].Name == "aThis" && i == 0) { continue; } xBuilder.Append(xParams[i].ParameterType.FullName); if (i < (xParams.Length - 1)) { xBuilder.Append(", "); } } xBuilder.Append(")"); return String.Intern(xBuilder.ToString()); } public static string GetFullName(this FieldInfo aField) { return aField.FieldType.FullName + " " + aField.DeclaringType.FullName + "." + aField.Name; //var xSB = new StringBuilder(aField.FieldType.FullName.Length + 1 + aField.DeclaringType.FullName.Length + 1 + aField.Name); //xSB.Append(aField.FieldType.FullName); //xSB.Append(" "); //xSB.Append(aField.DeclaringType.FullName); //xSB.Append("."); //xSB.Append(aField.Name); //return String.Intern(xSB.ToString()); } } }