PDA

View Full Version : new Modifier


Tolo
09-27-2005, 12:44 PM
Hi,

I’m getting Ambiguous Match found exception when I try to “inject” an object into a property with the new modifier.

I’m using the next definition for the object:


<object id="EnvRegularizacion" type="Engel.Business.Comun.Envoltorios.Operativa.Regular izacion, Engel.Business.Comun" singleton="false">
<property name="GestorEntidad">
<ref object="GestorRegularizaciones"/>
</property>
...
...
</object>

GestorRegularizaciones is defined in another xml file. GestorEntidad is defined with the new modifier.

Do you know how can I fix it?


Thanks

Rick Evans
09-27-2005, 02:45 PM
Hi

I am at a loss as to why you are getting such an exception. I honestly don't think this is an issue with Spring.NET... I may be wrong.

If possible, can you post the class definition of the Regularizacion class (including its superclass or superclasses)? Can you also post the class that is associated with the GestorEntidad property (including its superclass or superclasses)? Maybe even just the relevant snippets from the relvant classes?

I realise that your actual code may be confidential :) so if you want you can post it to me in the strictest confidence (my email address is attached to my post).

Ciao
Rick

Tolo
09-27-2005, 05:33 PM
Hi,

I don't have the code here (I'm at home now), but it's something like:

public new IGestorRegularizaciones GestorEntidad
{
get
{
return (IGestorRegularizaciones)base.GestorEntidad;
}
set
{
base.GestorEntidad=value;
}
}


The base GestorEntidad method is something like:


public IGestor GestorEntidad
{
get
{
return gestorEntidad;
}
set
{
gestorEntidad=value;
}
}


IGestorRegularizaciones is a son of IGestor.

I believe that the problem is the use of new because if I create another property with another name instead of GestorEntidad all works fine (changing the xml file too). I mean something like


public IGestorRegularizaciones GestorCabecera
{
get
{
return (IGestorRegularizaciones)GestorEntidad;
}
set
{
GestorEntidad=value;
}
}


I'm using the above workaround and all works fine. I believe that this is the first time that I use the new modifier, so I don’t have any problem with the workaround :)

Thanks for your time.

Rick Evans
09-28-2005, 01:09 AM
Hi Tolo

I honestly don't think this is an issue with Spring.NET... I may be wrong.

Ok, I was wrong :?

I have written tests to flush out the the corner case that you discovered (http://opensource2.atlassian.com/projects/spring/browse/SPRNET-198), and then fixed and commited said fix. This fix will be in the 1.0.1 release. If you can't wait that long (November), you can always grab the code in the CVS HEAD and compile your own version.

While I'm here though... why is your code the way it is? Is it merely to save having to perform a cast each and every time you access the GestorEntidad property from within a derived class? I'd be interested to know :D

Ciao
Rick

P.S The 'fix' was one line of code in the GetPropertyInfo method of the ObjectWrapper class (if you're inclined to just patch your own version, due to the code currently in the CVS HEAD not being the same as the 1.0 release code).

Tolo
09-28-2005, 08:06 AM
Hi Tolo
While I'm here though... why is your code the way it is? Is it merely to save having to perform a cast each and every time you access the GestorEntidad property from within a derived class? I'd be interested to know :D

Hi,

Yes, you are right is just a cast, I am a lazy programmer :).

I am not a new modifier fan, but I believe that it can be useful in this kind of situations because the new property is compatible with the base one so I don’t mix concepts.

Thanks a lot for the ultra-fast fix :)