Reputation: 38228
I want to do this (I'm on silverlight but nothing specific so want to do this also on winform and wpf)
namespace MyComponents
{
public class IMyManager : ILibManager
{
void SetModel(ILibModel model);
}
}
but get this error
Error 2 'MyComponents.IMymanager' does not implement interface member 'lib.manager.ILibManager.SetModel(lib.model.ILibModel)'. 'MyComponents.IMymanager.SetModel(lib.model.ILibModel)' cannot implement an interface member because it is not public. C:...\MyComponents\MyComponents\IMymanager.cs 17 18 MyComponents
Why ? This is the code in Lib
using lib.model;
using System;
using System.Collections.Generic;
using System.Text;
namespace lib.manager
{
public interface ILibManager
{
public void SetModel(ILibModel model);
}
}
using lib.model;
using System;
using System.Net;
using System.Windows;
namespace lib.manager
{
public class Manager: IManager
{
// Constructor
public Manager() {
}
public void SetModel(ILibModel model) {
}
}
}
namespace lib.model
{
public interface ILibModel
{
}
}
namespace lib.model
{
public class Model : ILibModel
{
}
}
Upvotes: 1
Views: 1304
Reputation: 11
You might also try explicit implementation, such as:
public class MyManager : ILibManager
{
void ILibManager:SetModel(ILibModel model)
{
// ...
}
}
Upvotes: 1
Reputation: 3854
I believe you had two errors here, didn't you? there should be an error saying that SetModel should have a body because IMyManager isn't an interface or an abstract class!
So, I believe you should have a body for that method, and then it has to be "public" since it's part of an implementation of an interface. And you should also rename IMyManager to be "MyManager", since it's not an interface. you should have your class like this:
public class MyManager : ILibManager
{
public void SetModel(ILibModel model)
{
// implementation of SetModel
}
}
Hope this helps :)
Upvotes: 2
Reputation: 3385
Try this instead:
namespace MyComponents
{
public class MyManager : ILibManager
{
public void SetModel(ILibModel model)
{
// ...
}
}
}
A class that conforms to an interface (contract!) must implement it in a public manner.
Upvotes: 1