Beispiel #1
0
		/// <summary>
		///
		/// </summary>
		/// <param name="target"></param>
		/// <param name="methodName"></param>
		/// <param name="parameterTypes">Currently, use null here if you have a ref param</param>
		/// <param name="parameterList"></param>
		/// <returns>null or the MethodInfo if a matching one was found</returns>
		private MethodInfo CheckForMatchingMessage(IxCoreColleague target, string methodName, Type[] parameterTypes,
			object[] parameterList, Set<int> previous)
		{
#if false
			//tostring here is too expensive to leave lying around
			Trace.Indent();
			TraceVerboseLine(" Checking : "+ target.ToString());
#endif
			int x = target.GetHashCode();
			if (previous.Contains(x))
			{
				throw new ArgumentException("XCore Mediator encountered the same " + target.ToString() + " twice on check for " + methodName + ", as if there is a loop.");
			}
#if false
			TraceVerboseLine("Adding "+target.ToString()+":"+x.ToString());
#endif
			previous.Add(x);

			//NB: I did not think about these flags; I just copied them from an example
			BindingFlags flags =
				BindingFlags.NonPublic|BindingFlags.Public|BindingFlags.Instance;

			Type type = target.GetType();
			MethodInfo mi;
			//
			// By using the JetBrains dotTrace profiler, the addition of m_TypeMethodInfo is saving
			// a significant (>20%) amount of time by not having to make as many calls to the expensive
			// System.Type.GetMethod()
			//
			if (parameterTypes == null) // callers currently must use null here if they have a "ref" param (TODO)
			{
				string key = type.ToString() + "_" + methodName;
				if (m_TypeMethodInfo.ContainsKey(key))
				{
					mi = m_TypeMethodInfo[key];
				}
				else
				{
					mi = type.GetMethod(methodName, flags);
					m_TypeMethodInfo[key] = mi;
				}
			}
			else
			{
				string key2 = type.ToString() + "_" + methodName + "_" + parameterTypes.Length.ToString();
				if (m_TypeMethodInfo.ContainsKey(key2))
				{
					mi = m_TypeMethodInfo[key2];
				}
				else
				{
					mi= type.GetMethod(methodName, flags, null,	parameterTypes, null);
					m_TypeMethodInfo[key2] = mi;
				}
			}
#if false
			Trace.Unindent();
#endif
			return mi;
		}
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="target"></param>
        /// <param name="methodName"></param>
        /// <param name="parameterTypes">Currently, use null here if you have a ref param</param>
        /// <param name="parameterList"></param>
        /// <returns>null or the MethodInfo if a matching one was found</returns>
        private MethodInfo CheckForMatchingMessage(IxCoreColleague target, string methodName, Type[] parameterTypes)
        {
            //NB: I did not think about these flags; I just copied them from an example
            BindingFlags flags =
                BindingFlags.NonPublic|BindingFlags.Public|BindingFlags.Instance;

            Type type = target.GetType();
            MethodInfo mi;
            //
            // By using the JetBrains dotTrace profiler, the addition of m_TypeMethodInfo is saving
            // a significant (>20%) amount of time by not having to make as many calls to the expensive
            // System.Type.GetMethod()
            //
            if (parameterTypes == null) // callers currently must use null here if they have a "ref" param (TODO)
            {
                Dictionary<string, MethodInfo> methodDict;
                if (m_TypeMethodInfo.TryGetValue(type, out methodDict))
                {
                    if (methodDict.TryGetValue(methodName, out mi))
                        return mi;
                }
                else
                {
                    methodDict = new Dictionary<string, MethodInfo>();
                    m_TypeMethodInfo[type] = methodDict;
                }
                mi = type.GetMethod(methodName, flags);
                methodDict[methodName] = mi;
            }
            else
            {
                var key = parameterTypes.Length + methodName; // method name could end with number, but not start.
                Dictionary<string, MethodInfo> methodDict;
                if (m_TypeMethodInfo.TryGetValue(type, out methodDict))
                {
                    if (methodDict.TryGetValue(key, out mi))
                        return mi;
                }
                else
                {
                    methodDict = new Dictionary<string, MethodInfo>();
                    m_TypeMethodInfo[type] = methodDict;
                }
                mi = type.GetMethod(methodName, flags, null, parameterTypes, null);
                methodDict[key] = mi;
            }
            return mi;
        }
Beispiel #3
0
		private bool ColleagueHasBeenDisposed(IxCoreColleague target)
		{
			bool hasBeenDisposed = false;

			if (target is IDisposable)
			{
				// Have to use reflection to see if it has an IsDisposed property,
				// since that is not part of the interface for IDisposable for some odd reason.
				// Get the property infor for the ActiveViewHelper property on the control
				// (assuming there is one).
				PropertyInfo propInfo = target.GetType().GetProperty("IsDisposed",
					BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

				// If we successfully found an ActiveViewHelper property, then reference
				// it to set our class' active view helper member variable.
				if (propInfo != null)
				{
					hasBeenDisposed = (bool)propInfo.GetValue(target,
						BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public,
						null, null, null);

					if (!hasBeenDisposed)
					{
						propInfo = target.GetType().GetProperty("Disposing",
							BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

						// If we successfully found an ActiveViewHelper property, then reference
						// it to set our class' active view helper member variable.
						if (propInfo != null)
						{
							hasBeenDisposed = (bool)propInfo.GetValue(target,
								BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public,
								null, null, null);
						}
					}
				}
			}

			return hasBeenDisposed;
		}