Answer the question
In order to leave comments, you need to log in
Minimum set of required parameters in an Interface method in C#?
Good day.
There is an interface with a mandatory method and a minimum set of required parameters.
How to use additional sets of parameters in an inherited class overriding an interface method?
Example:
interface IClass
{
// устанавливаем минимальный набор обязательных параметров
bool A(a,b,c,d);
}
// и наследуюмый класс
class MyClass : IClass
{
// здесь нужно использовать еще и дополнительные параметры
bool a(a,b,c,d,e)
{
return false
}
}
Answer the question
In order to leave comments, you need to log in
Instead of a set of parameters, in your case, you need to use an interface \ class, then you can pass a more parameterized interface \ class to the heir and work with it.
It is impossible to add REQUIREMENT of new fields. In general, this behavior is considered undesirable, but if you really need it...:
interface IClassParam
{
string A { get; set; }
}
class ClassParam : IClassParam
{
public string A { get; set; }
public string B { get; set; }
}
interface IClass
{
bool A(IClassParam param);
}
class MyClass : IClass
{
public bool A(IClassParam param)
{
// Field A is available.
var extend = param as ClassParam;
if (extend != null)
{
// you can work with property B
}
return true;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question