|
From: Vaughn, C. <Va...@va...> - 2003-09-09 13:01:22
|
I discovered this problem with VB code because you can easily create
properties that take arguments, but I recreated it in C# with an indexer.
Here's a test to reveal the bug:
public interface IDiffIndexers
{
object this[ int index ] { get; }
object this[ int index, int index2 ] { get; }
}
public void TestGetItem()
{
IMock foo = new DynamicMock( typeof( IDiffIndexers )
);
foo.ExpectAndReturn( "Item", "bob", 0 );
Assertion.AssertEquals( "retval", "bob",
((IDiffIndexers)foo.MockInstance)[0] );
}
... and my hack of a fix....
void checkMethodIsValidIfNoConstraints(MethodSignature
signature)
{
foreach(Type argType in signature.argumentTypes)
{
if(typeof(IConstraint).IsAssignableFrom(argType)) return;
}
Type[] allTypes = new InterfaceLister().List(type);
foreach (Type t in allTypes)
{
string [] prefixes = new string[] { "",
"get_", "set_" };
foreach ( string prefix in prefixes )
{
MethodInfo method =
t.GetMethod(prefix + signature.methodName,
ClassGenerator.ALL_INSTANCE_METHODS, null,
signature.argumentTypes,
null);
if(method != null)
{
if(!method.IsVirtual)
{
throw new
ArgumentException(String.Format("method <{0}> is not virtual", signature ));
}
return;
}
}
}
throw new
MissingMethodException(String.Format("method <{0}> not defined", signature
));
}
cliff
Clifton F. Vaughn
Senior Business Analyst
Information Technology
Valassis / IT Division
19975 Victor Parkway Livonia, MI 48152
Tel 734.591.3000 Ext. 16726 Fax 734.632.6151
va...@va...
www.valassis.com
This message may have included proprietary or protected information. This
message and the information contained herein are not to be further
communicated without my express written consent.
|