iam creating an interface for a fluent ordered constructor and i have wrote this code:
public interface IMyObjectFactory: IObjectWithProperty
{
int objectId { get; set; }
IObjectWithProperty WithObjectId(int id);
}
public interface IObjectWithProperty
{
IObjectWithProperty WithObjectId(int id);
MyObject Create();
}
the second interface is need to enforce order in constructor method
the impl is this:
public class MyObjectFactory: IMyObjectFactory
{
public int objectId { get; set; }
private MyObjectFactory() { }
public static IObjectWithProperty BeginCreation()
{
return new ObjectFactory();
}
public IObjectWithProperty WithObjectId(int id)
{
objectId = id;
return this;
}
public MyObject Create()
{
return new MyObject(this);
}
}
And this is my object:
public class MyObject
{
public int Id { get; set; }
public MyObject(IMyObjectFactory factory)
{
this.Id = factory.objectId;
}
}
so I can write
MyObject mo = MyObjectFactory.BeginCreation().WithObjectId(1).Create();
but:
Warning 7 'FunzIA.DL.Factory.Interfaces.IMyObjectFactory.WithObjectId(int)' hides inherited member 'FunzIA.DL.Factory.Interfaces.IObjectWithProperty.WithObjectId(int)'. Use the new keyword if hiding was intended.
but is not a new method and i need the second interface to enforce order
Any suggestion? Thanks
I do it in this way:
public interface IMyObjectFactory: IObjectWithProperty
{
int objectId { get; set; }
}
public interface IObjectWithProperty
{
IObjectWithProperty WithObjectId(int id);
MyObject Create();
}
public class MyObjectFactory: IMyObjectFactory
{
public int objectId;
private MyObjectFactory() { }
public static IObjectWithProperty BeginCreation()
{
return new MyObjectFactory();
}
public IObjectWithProperty WithObjectId(int id)
{
objectId = id;
return this;
}
public MyObject Create()
{
return new MyObject(this);
}
}
public class MyObject
{
public int Id { get; set; }
public MyObject(IMyObjectFactory factory)
{
this.Id = factory.objectId;
}
}