Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: Possible to not implement a protected internal abstract on an abstract class?

what do I need to change in my abstract base so that the implementations don't have to implement BOTH methods when only one is needed in any given scenario? My example is:

internal abstract class BaseBar<T> where T : BaseThing
{
    protected internal abstract T DataFromXmlElements(IEnumerable<XmlNode> nodes);
    protected internal abstract T DataFromXmlElements(IEnumerable<XmlNode> nodes, string[] fieldNames);
}

class FooBarMapper : BaseBar<FooData>
{
    protected internal override SforceObjectValueData DataObjectFromXmlElements(IEnumerable<XmlNode> nodes)
    {
        throw new NotImplementedException();
    }

    protected internal override FooData DataFromXmlElements(IEnumerable<XmlNode> nodes, string[] fieldNames)
    {
        FooData o = new FooData
        {
            bar1 = bar1,
            bar2 = bar2
        };
        return o;
    }
}

Cheers.

edit: The design is weird/bad/stupid I know...I'm working with legacy code and time is not on my side right now for a refactor. I'm trying to add the second method with the string array.

like image 770
bryan Avatar asked Dec 22 '22 21:12

bryan


1 Answers

Maybe this works out for you?

internal abstract class BaseBar<T> where T : BaseThing
{
    protected internal abstract T DataFromXmlElements(IEnumerable<XmlNode> nodes, params string[] fieldNames);
}
like image 152
Stormenet Avatar answered Dec 24 '22 11:12

Stormenet