Giter Club home page Giter Club logo

Comments (7)

mauroservienti avatar mauroservienti commented on July 23, 2024 1

Great catch @MarcusChamberlain. I'll get it fixed. If I end up using the same approach as for RaiseEvent I can also drop the IDynamicViewModel interface entirely.

from servicecomposer.aspnetcore.

mauroservienti avatar mauroservienti commented on July 23, 2024

Hi @MarcusChamberlain, thanks for raising this. Never thought about that scenario, indeed sounds interesting and doable. I see to options:

  • DynamicViewModel has a Merge method
  • DynamicViewModel implements IDictionary<>

Thoughts?

from servicecomposer.aspnetcore.

MarcusChamberlain avatar MarcusChamberlain commented on July 23, 2024

Thanks for taking a look into this. Being able to call 'vm.Merge(myDynamic)' on the view model would be very nice.

from servicecomposer.aspnetcore.

mauroservienti avatar mauroservienti commented on July 23, 2024

@MarcusChamberlain I raised #33 to address this. The only thing I'm not sure about is the Merge behavior, right now I took the simplest approach that is to overwrite existing properties in DynamicViewModel. Obviously this can lead to some strange scenarios like:

dynamic d = new DynamicViewModel(....);
d.SomeProperty = 10;

dynamic source = new ExpandoObject();
source.SomeProperty = "some value";

d.Merge(source);

It'll work but now the DynamicViewModel instance SomeProperty type changed from int to string.

I could check that in case of overwrite the type is the same.

Thoughts?

from servicecomposer.aspnetcore.

MarcusChamberlain avatar MarcusChamberlain commented on July 23, 2024

Hi Mauro

The merge solution looks great. I did notice one issue though.

At the moment your unit tests (in the 'When_merging_to_DynamicViewModel' class) are able to run because you have a compiler instruction to make internal classes visible to the external assembly 'ServiceComposer.AspNetCore.Tests'. This is tricking your tests into passing - if you attempt to use vm.Merge() in an project without that compiler instruction, you'll get an error that DynamicViewModel does not contain a method called Merge().

This occurs because the call to Merge() goes through the 'TryInvokeMember' method. This has been set to only allow calls to 'RaiseEvents'.

The fix is to add the following to 'TryInvokeMember':

            if (binder.Name == "Merge")
            {
                this.Merge(args[0] as IDictionary<string, object>);
                return true;
            }

from servicecomposer.aspnetcore.

mauroservienti avatar mauroservienti commented on July 23, 2024

@MarcusChamberlain I just pushed a fix to #33

from servicecomposer.aspnetcore.

mauroservienti avatar mauroservienti commented on July 23, 2024

Merged the PR and deployed 0.0.11 to Nuget. Thanks @MarcusChamberlain.

from servicecomposer.aspnetcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.