You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.9 KiB
106 lines
2.9 KiB
// <file> |
|
// <copyright see="prj:///doc/copyright.txt"/> |
|
// <license see="prj:///doc/license.txt"/> |
|
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/> |
|
// <version>$Revision$</version> |
|
// </file> |
|
|
|
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using System.ComponentModel; |
|
using System.Drawing; |
|
using System.Reflection; |
|
using System.Windows.Forms; |
|
|
|
using ICSharpCode.PythonBinding; |
|
using PythonBinding.Tests.Utils; |
|
|
|
namespace PythonBinding.Tests.Designer |
|
{ |
|
/// <summary> |
|
/// Base class for all LoadFormTestFixture classes. |
|
/// </summary> |
|
public class LoadFormTestFixtureBase : IComponentCreator |
|
{ |
|
List <CreatedComponent> createdComponents = new List<CreatedComponent>(); |
|
List <CreatedInstance> createdInstances = new List<CreatedInstance>(); |
|
List <AddedComponent> addedComponents = new List<AddedComponent>(); |
|
List<string> typeNames = new List<string>(); |
|
|
|
public LoadFormTestFixtureBase() |
|
{ |
|
} |
|
|
|
public IComponent CreateComponent(Type componentClass, string name) |
|
{ |
|
CreatedComponent c = new CreatedComponent(componentClass.FullName, name); |
|
createdComponents.Add(c); |
|
|
|
object instance = componentClass.Assembly.CreateInstance(componentClass.FullName); |
|
return (IComponent)instance; |
|
} |
|
|
|
public void Add(IComponent component, string name) |
|
{ |
|
AddedComponent addedComponent = new AddedComponent(component, name); |
|
addedComponents.Add(addedComponent); |
|
} |
|
|
|
public object CreateInstance(Type type, ICollection arguments, string name, bool addToContainer) |
|
{ |
|
CreatedInstance createdInstance = new CreatedInstance(type, arguments, name, addToContainer); |
|
createdInstances.Add(createdInstance); |
|
|
|
object[] argumentsArray = new object[arguments.Count]; |
|
arguments.CopyTo(argumentsArray, 0); |
|
|
|
object o = type.Assembly.CreateInstance(type.FullName, true, BindingFlags.CreateInstance, null, argumentsArray, null, new object[0]); |
|
createdInstance.Object = o; |
|
return o; |
|
} |
|
|
|
public Type GetType(string typeName) |
|
{ |
|
typeNames.Add(typeName); |
|
|
|
// Lookup type in System.Windows.Forms assembly. |
|
Type type = typeof(Form).Assembly.GetType(typeName); |
|
if (type == null) { |
|
// Lookup type System.Drawing assembly. |
|
type = typeof(Size).Assembly.GetType(typeName); |
|
} |
|
return type; |
|
} |
|
|
|
protected List<CreatedComponent> CreatedComponents { |
|
get { return createdComponents; } |
|
} |
|
|
|
protected List<AddedComponent> AddedComponents { |
|
get { return addedComponents; } |
|
} |
|
|
|
protected List<CreatedInstance> CreatedInstances { |
|
get { return createdInstances; } |
|
} |
|
|
|
protected List<string> TypeNames { |
|
get { return typeNames; } |
|
} |
|
|
|
protected string LastTypeNameResolved { |
|
get { return TypeNames[TypeNames.Count - 1]; } |
|
} |
|
|
|
protected CreatedInstance GetCreatedInstance(Type type) |
|
{ |
|
foreach (CreatedInstance instance in createdInstances) { |
|
if (instance.InstanceType == type) { |
|
return instance; |
|
} |
|
} |
|
return null; |
|
} |
|
} |
|
}
|
|
|