我有一个通用接口,该接口需要一个属性(父),该属性是相同的接口,但类型不同。我将如何实现这一目标?
@app.route("/login/", methods=['POST'])
def login():
username = request.form["username"]
password = request.form["password"]
auth = authenticate(username, password)
return jsonify({'authentication': auth}), 200
我可以通过以下方法实现相同目的,但是我想利用c#的属性(如果适用):
public interface IConfigurator<T1>
{
string TableName { get; }
PropertyMapper<T1> PropertyMap { get; }
IConfigurator<T2> ParentConfigurator {get;set;} // this line is not valid c# code
}
答案 0 :(得分:0)
最好使用object
public interface IConfigurator<T>
{
string TableName { get; }
PropertyMapper<T> PropertyMap { get; }
object ParentConfigurator {get;set;}
}
因为如果沿着这条通用路径走得太多,它将变得更加混乱
public interface IConfigurator<T,TParent>
{
string TableName { get; }
PropertyMapper<T> PropertyMap { get; }
IConfigurator<TParent,??> ParentConfigurator { get; } // what are you going to put here for ?? object maybe
}
除非您创建其他界面
public interface IConfigurator<T>
{
string TableName { get; }
PropertyMapper<T> PropertyMap { get; }
}
public interface IConfigurator<T,TParent> : IConfigurator<T>
{
IConfigurator<TParent> ParentConfigurator { get; } // what are you going to put here for ?? object maybe
}