tools/VsIdeHostAdapter/TargetAddIn/HostSide/HostAdapterHostSide.cs
/// <summary>
/// Attempt to run an arbitrary method on the host side on the current thread.
/// Note: Ideal for ad hoc code execution outside the context of an MSTest TestMethod
/// </summary>
Attempt to run an arbitrary method on the host side on the current thread.
Note: Ideal for ad hoc code execution outside the context of an MSTest TestMethod
Attempt to run an arbitrary method on the host side on the current thread . Note : Ideal for ad hoc code execution outside the context of an MSTest TestMethod
public object RunNonTestMethod(String typeName, String methodName, ArrayList args, String assemblyHintPath = null)
        {
            #region Arg Checks
            Debug.Assert(typeName != null, "typeName is null");
            Debug.Assert(methodName != null, "methodName is null");
            #endregion
            Assembly assembly = Assembly.GetExecutingAssembly();
            if (assemblyHintPath != null)
                assembly = Assembly.LoadFrom(assemblyHintPath);
            Type targetType = assembly.GetType(typeName);
            if (targetType == null)
            {
                throw new InvalidOperationException(
                    String.Format("Unable to locate type {0} in assembly {1}", typeName, assembly.FullName));
            }
            MethodInfo targetMethod = targetType.GetMethod(methodName);
            if (targetMethod == null)
            {
                throw new InvalidOperationException(
                    String.Format("Unable to locate method {0} in type {1}", methodName, typeName));
            }
            object target = null;
            if (!targetMethod.IsStatic)
                target = Activator.CreateInstance(targetType);
            return targetMethod.Invoke(target, args.ToArray());
        }
public object RunNonTestMethod ( String typeName , String methodName , ArrayList args , String assemblyHintPath = null ) { region  Arg Checks Debug . Assert ( typeName != null , " " ) ; Debug . Assert ( methodName != null , " " ) ; endregion Assembly assembly = Assembly . GetExecutingAssembly ( ) ; if ( assemblyHintPath != null ) assembly = Assembly . LoadFrom ( assemblyHintPath ) ; Type targetType = assembly . GetType ( typeName ) ; if ( targetType == null ) { throw new InvalidOperationException ( String . Format ( " " , typeName , assembly . FullName ) ) ; } MethodInfo targetMethod = targetType . GetMethod ( methodName ) ; if ( targetMethod == null ) { throw new InvalidOperationException ( String . Format ( " " , methodName , typeName ) ) ; } object target = null ; if ( ! targetMethod . IsStatic ) target = Activator . CreateInstance ( targetType ) ; return targetMethod . Invoke ( target , args . ToArray ( ) ) ; }
Attempt to run an arbitrary method on the host side on the current thread.
Attempt to run an arbitrary method on the host side on the current thread .
// Load the assembly // Find the type // Find the method // Invoke, instantiating the type if non-static
typeName
String
methodName
String
args
ArrayList
assemblyHintPath
String