question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type configuration being applied to all derived types of the abstract class that implements the member

See original GitHub issue

Hi @Mike-E-wins not sure if this is a bug but I’m seeing somewhat the opposite of issue #398 where I configure the member of a derived type, but all types deriving from the base where the member is defined receive that configuration. I tried both with and without the custom extension from #398

Here’s myrepro:

        [Test]
        public void MyTest()
        {
            var serializer = new ConfigurationContainer()
                .EnableImplicitTyping(typeof(Subject))
                .UseOptimizedNamespaces()
                .Type<SubjectA>().Member(x => x.Signature).Ignore() // <-- only configuring SubjectA, not SubjectB
                .Create();


            var subjects = new List<ISubject>();
            subjects.Add(new SubjectA { Signature = "testa" });
            subjects.Add(new SubjectB { Signature = "testb" });

            var str = serializer.Serialize(
                new XmlWriterSettings { Indent = true }, subjects);

            Console.WriteLine(str);
        }

        interface ISubject
        {
            string Signature { get; set; }
        }

        public abstract class BaseSubject : ISubject
        {
            public string Signature { get; set; }
        }
        public class SubjectA : BaseSubject
        {
        }
        public class SubjectB : BaseSubject
        {
        }

Output is:

<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ns1="clr-namespace:SerializerTests;assembly=UnitTestSerializer" xmlns:exs="https://extendedxmlserializer.github.io/v2" exs:arguments="ns1:Playground-ISubject" xmlns="https://extendedxmlserializer.github.io/system">
  <Capacity>4</Capacity>
  <ns1:Playground-SubjectA />
  <ns1:Playground-SubjectB />
</List>

I would have thought it would only ignore Signature on SubjectA

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
gmkadocommented, Jul 24, 2020

Thanks @Mike-E-angelo !

1reaction
issue-label-bot[bot]commented, Jul 20, 2020

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.66. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Abstract and Sealed Classes and Class Members - C# ...
The abstract keyword enables you to create classes and class members that are incomplete and must be implemented in a derived class.
Read more >
How can a user choose the implementation of an abstract ...
I want users of my class "ShapeHolder" to be able to set the "Shape shape" member variable to be any class with the...
Read more >
C# | Abstract Classes
Abstract classes are used to define a common set of behaviors or properties ... and all derived classes must implement abstract definitions.
Read more >
What code should be included in an abstract class?
In these cases, the abstract class is usually used as a place where you can put any kind of common code that current...
Read more >
Abstract Class in Java
Java Abstract class is used to provide common method implementation to all the subclasses or to provide default implementation. We can run  ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found