[Mono-list] Embedded API: calling explicit interface properties
Jonathan Mitchell
jonathan at mugginsoft.com
Tue Jul 15 11:24:34 UTC 2014
Hi
I have a class that implements the following two interfaces and I am having trouble accessing explicit interface properties via the embedded API.
My unit tests fail (see below).
The explicit interface properties are found okay but the property assignment fails in a way which makes me think there is a parameter type problem.
Is there anything I should be aware of with regard to constructing the property access signature?
If I log the mono class method info it looks okay - again this is listed below.
Any suggestions would be appreciated.
MONO
======
public interface IReferenceObject1 : IReferenceObjectBase
{
int ExIntTestProperty { get; set; }
}
public interface IReferenceObject2 : IReferenceObjectBase
{
float ExIntTestProperty { get; set; }
}
public class ReferenceObject : IReferenceObject1, IReferenceObject2
{
// explicit interface properties
/*
* Here we have one property with 3 different return types
* two of which should be accessible via explicit interface references
*/
public bool ExIntTestProperty { get; set; }
float IReferenceObject2.ExIntTestProperty { get; set; }
int IReferenceObject1.ExIntTestProperty { get; set; }
// get interfaces
public IReferenceObject1 ReferenceObject1 {
get {
return (IReferenceObject1)this;
}
}
public IReferenceObject2 ReferenceObject2 {
get {
return (IReferenceObject2)this;
}
}
}
// MonoClass dump
// iterate over mono_class_get_methods
============== Mono Class Info ========================
2014-07-15 11:54:14.544 otest[4933:303] Class namespace : Dubrovnik.UnitTests
2014-07-15 11:54:14.545 otest[4933:303] Class name : IReferenceObject1
2014-07-15 11:54:14.545 otest[4933:303] Class type name : Dubrovnik.UnitTests.IReferenceObject1
2014-07-15 11:54:14.545 otest[4933:303] Method count : 2
2014-07-15 11:54:14.545 otest[4933:303] Method name: Dubrovnik.UnitTests.IReferenceObject1:get_ExIntTestProperty ()
2014-07-15 11:54:14.546 otest[4933:303] Method name: Dubrovnik.UnitTests.IReferenceObject1:set_ExIntTestProperty (int)
2014-07-15 11:54:14.546 otest[4933:303] Interface name: IReferenceObjectBase
2014-07-15 11:54:23.206 otest[4933:303]
============== Mono Class Info ========================
2014-07-15 11:54:23.207 otest[4933:303] Class namespace : Dubrovnik.UnitTests
2014-07-15 11:54:23.207 otest[4933:303] Class name : IReferenceObject2
2014-07-15 11:54:23.208 otest[4933:303] Class type name : Dubrovnik.UnitTests.IReferenceObject2
2014-07-15 11:54:23.208 otest[4933:303] Method count : 2
2014-07-15 11:54:23.208 otest[4933:303] Method name: Dubrovnik.UnitTests.IReferenceObject2:get_ExIntTestProperty ()
2014-07-15 11:54:23.209 otest[4933:303] Method name: Dubrovnik.UnitTests.IReferenceObject2:set_ExIntTestProperty (single)
2014-07-15 11:54:23.210 otest[4933:303] Interface name: IReferenceObjectBase
Obj-C property accessors
=====================
// IReferenceObject1 returns Int
// Managed property name : ExIntTestProperty
// Managed property type : System.Int32
@synthesize exIntTestProperty = _exIntTestProperty;
- (int32_t)exIntTestProperty
{
MonoObject *monoObject = [self getMonoProperty:"ExIntTestProperty"];
_exIntTestProperty = DB_UNBOX_INT32(monoObject);
return _exIntTestProperty;
}
- (void)setExIntTestProperty:(int32_t)value
{
_exIntTestProperty = value;
MonoObject *monoObject = DB_VALUE(value);
[self setMonoProperty:"ExIntTestProperty" valueObject:monoObject];
}
// IReferenceObject2 returns float
// Managed property name : ExIntTestProperty
// Managed property type : System.Single
@synthesize exIntTestProperty = _exIntTestProperty;
- (float)exIntTestProperty
{
MonoObject *monoObject = [self getMonoProperty:"ExIntTestProperty"];
_exIntTestProperty = DB_UNBOX_FLOAT(monoObject);
return _exIntTestProperty;
}
- (void)setExIntTestProperty:(float)value
{
_exIntTestProperty = value;
MonoObject *monoObject = DB_VALUE(value);
[self setMonoProperty:"ExIntTestProperty" valueObject:monoObject];
}
Obj-C unit test
============
// query explicit interface implementation properties.
// we should be able to access the same property with three different return types via the
// original object and two explicit interface references.
// BOOL
BOOL boolValue = [(DBUReferenceObject *)refObject exIntTestProperty]; // cast need to silence type warning
NSAssert(boolValue == YES, DBUEqualityTestFailed);
// int
Dubrovnik_UnitTests_IReferenceObject1 *refObject1 = [refObject referenceObject1];
[refObject1 logMonoClassInfo];
[refObject1 setExIntTestProperty:89467];
int32_t intValue = [refObject1 exIntTestProperty];
#warning failing test code - return value is 123
NSAssert(intValue == 89467, DBUEqualityTestFailed);
// float
Dubrovnik_UnitTests_IReferenceObject2 *refObject2 = [refObject referenceObject2];
[refObject2 logMonoClassInfo];
[refObject2 setExIntTestProperty:20202.f];
float floatValue = [refObject2 exIntTestProperty];
#warning failing test code - return value is 0
NSAssert(floatValue == 20202.f, DBUEqualityTestFailed);
Thanks
Jonathan
More information about the Mono-list
mailing list