This project is read-only.


Empty method in NestedMember


I stumbled upon a strange piece of code while looking for the cause of a mysterious error:
namespace Glue.Internals
internal partial class ObjectMemberFactory
    private class NestedMember : ObjectMember, INestedMember
        internal NestedMember(IObjectMemberAccessor member) : base(member, true)
        public override void InvokeSet(object toInvokeOn, object toSet)
InvokeSet does absolutely nothing. As result the target property remains unchanged. When I removed the override, my test application worked like I expexted.
I can upload the whole project if you need it, but I think a short description should do it for now.
--- Test application ---
Basically it just maps a Class1 object to a Class2 object and uses a converter to transform their properties (Class3ToClass4Converter).
        Class1 c1 = new Class1() { Class3 = new Class3() };
        Class2 c2 = new Class2();
        var mapping = new Mapping<Class1, Class2>();
        mapping.AddConverter(new Class3ToClass4Converter());
        mapping.Relate(leftSide => leftSide.Class3, rightSide => rightSide.Class4);
        c2 = mapping.Map(c1, c2);
        if(c2.Class4 == null){
          throw new Exception("Class3 not mapped to Class4");
Class1 to Class4 are just plain dummy classes. Class1 contains a property Class3 of type Class3. Class2 contains a property Class4 of type Class4. Class3 and Class4 are completely empty. Thats it.
The converter:
public class Class3ToClass4Converter: BaseSimpleConverter<Class3, Class4>
    public override Class3 MapTowardsLeft(Class4 from)
        return new Class3();
    public override Class4 MapTowardsRight(Class3 from)
        return new Class4();
Closed Feb 7, 2013 at 9:11 AM by ToreVestues


ToreVestues wrote Jan 8, 2012 at 12:35 PM


I've added your code to the testexamples-project (GlueExamples/ReportedIssues/EmptyMethodInNestedMember.cs), changeset 71771, but it does not cause any errors. It would be nice if you can give me the complete code, and/or a description of what this mysterious error you get is.

I can understand that it looks like an error that InvokeSet just returns, but that is intended. Unless we're in automagical state, ObjectMembers are supposed to be set in advance, so this is not the place to re-set it.

tobeno wrote Jan 9, 2012 at 1:23 AM


ok I suppose I understand the problem now. I tried to use Glue together with other mappers on the same object. That required me to pass one already created instance to the Map(obj1, obj2) method of Glue. I overread the fact, that automatical mode is only available, when Glue creates the whole object tree by calling Map(obj1).
It was probably a bit misleading, when I talked about "error". What I meant: When I tried the code above (thinking to be in automagical mode), the nested property didn't get set. When I debugged my code, there was no sign, that I did anything wrong. Even my Converter (Class3ToClass4Converter) got called like expected and returned the new instance for Class4, which then vanished into thin air without an Exception. So it's more like an unexpected behaviour and not an error. When I look at it now, it's pretty clear what happened, but still some kind of Exception would have been really helpfull.

Since it's not a coding error, I have a question: Is it possible to map an already existing object with Glue and still get into automagical state? I could dig into the heart of Glue and define a custom extension method, but I would prefer a cleaner solution. I can't really imagine I'm the only one, who could use that kind of feature.

Sorry for the confusing example by the way. I will try to make them more clear in the future.

tobeno wrote Jan 9, 2012 at 10:41 AM

I also updated my example to give an Exception. It will always throw an exception because of strict mode, but at least it shows what originally got me confused.

A thing I forgot to mention in my last comment:
I still find it quite strange, that my example only works in automagical mode, since there is no "magic" object creation involved. I dont see the point in pre-initializing the Class4 property. It will just be reset to the converted object, so why instanciate it before mapping? I get your point, when the nested object is not created by a custom converter and instead gets mapped generically, but otherwise it seems a bit to strict at least for me.

Still: A way to enable automatigal mode, even if you give an pre-created instance to the mapper, whould be quite useful.

wrote Feb 7, 2013 at 9:11 AM

wrote Feb 14, 2013 at 7:41 PM

wrote May 16, 2013 at 7:43 AM