tags:

views:

136

answers:

4

I would like to do something like the below

public interface IFormatter<TData, TFormat>
{
    TFormat Format(TData data);
}

public abstract class BaseFormatter<TData> : IFormatter<TData, XElement>
{
    public abstract XElement Format(TData data);
}

However, when I do the above I get an error about "The type or method has 2 generic parameters but only 1 was provided ...". I'll try and tackle it another way but I'm curious as to why this cannot be done?

Note that while this compiles in a single assembly, I have since noticed that the error message is actually generated by an assembly that is using this piece of code (a test assembly). This is where the error message noted above is generated.

+4  A: 

Is that the exact code you have? If it is, then you are missing the keyword class

aside from that, this should compile just fine:

public interface IFormatter<TData, TFormat>
{
    TFormat Format(TData data);
}

public abstract class BaseFormatter<TData> : IFormatter<TData, XElement>
{
    // blah blah
    public XElement Format(TData data)
    {
     throw new NotImplementedException();
    }
}
Josh
Thanks! I will go back and peek at my code to see what I was missing.
Jeffrey Cameron
Josh, I'm sorry for the confusion. The code above does compile, the problem, when I looked for it, was when another assembly tried to reference this assembly. That is when I was getting the error. I edited my original question to reflect this. Any thoughts?
Jeffrey Cameron
+1  A: 

Is it maybe complaining (indirectly) about the missing 'class' keyword in the abstract class declaration?

Jonathan
A: 

This code complies fine at my side:

public interface IFormatter<TData, TFormat>
{
    TFormat Format(TData data);
}

public abstract class BaseFormatter<TData> : IFormatter<TData, XElement>
{
    #region IFormatter<TData,XElement> Members

    public XElement Format(TData data)
    {
        throw new NotImplementedException();
    }

    #endregion
}
veggerby
A: 

Just in case anyone has this issue:

It turns out that the problem was related to the private field accessor in a MSTest unit testing project in the same solution. When I removed the accessor the project compiled.

Jeffrey Cameron
Ahhhh!!!! Don't test private fields! It will screw you when you want to refactor later ;)
Josh
I don't. It was only the accessor class, it wasn't used anywhere. The accessor class made its way in by accident a number of months ago and wasn't removed until it caused this weird bug on me! :-)
Jeffrey Cameron