This is .NET 4.0/C#. I have a class that inherits from an interface:
public class DocumentModel : IDocumentObject
{
//this is not in the interface and wont ever be
public void NewMethod(){//my code}
}
In my DocumentModel class, I added a public method that is not a part of the interface. When I call it,
var doc = new DocumentModel();
doc.NewMethod();
I get the following:
Error 30 ‘IDocumentObject’ does not contain a definition for ‘NewMethod’ and no
extension method ‘NewMethod’ accepting a first argument of type ‘IDocumentObject’
How do I add a method to my class that’s not in the interface? Thanks
In the interface add the method declaration.
Or if you do not want it in the interface, you’ll have to create an instance of the class of the type of the class, not the type of interface.