Git Product home page Git Product logo

Comments (3)

esskar avatar esskar commented on August 22, 2024

can you provide a unit test that fails?

from serialize.linq.

Odeanathus avatar Odeanathus commented on August 22, 2024

I'll try and whip one together tomorrow, any prefered way of getting it? (Should I just zip it all and upload it somewhere or would you like a 'wall of text' here :-) Assuming I can get it to fail in a small unit test. (It's failing in my system integration tests atm).

from serialize.linq.

Odeanathus avatar Odeanathus commented on August 22, 2024

I've found the problem, which isn't actually in Serialize.Linq but in an example we use that you posted on your blog in the past, since your blog seems down here is the web archive link;

http://web.archive.org/web/20130430051839/http://blog.esskar.de/articles/2013/1/serialize_linq_dto_and_business.html

You mention the following snippet which we used to great success in the past (before we had a class that inherited;

class MyExpressionContext : ExpressionContext
    {
        public override Type ResolveType(TypeNode node)
        {
            var type = base.ResolveType(node);
            if(type == null)
                return null;

            if(type == typeof(PersonDto))
                return typeof(Person);
            return type;
        }
    }

We altered it slightly to be generic and what not but I got things to work when I actually checked on inheritance see the following snippet;

public class DtoExpressionContext<TDto, TActual> : ExpressionContext
    {
        public override Type ResolveType(TypeNode node)
        {
            var type = base.ResolveType(node);
            if (type == null)
                return null;

            Type dtoType = typeof (TDto);

            if (type == dtoType || dtoType.IsSubclassOf(type))
                return typeof(TActual);
            return type;
        }
    }

Since this isn't an issue within Serialize.Linq at all i'll close this, however should you decide to blog again (or maybe this code is in the examples as well, I didn't check that) you could change it slightly to allow for the inheritance.

from serialize.linq.

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.