My code might be bit lengthy but easy to understand as I have tried my best to explain it, so please bare with me. I have a controller class as:
public class QueryController : ControllerBase
{
private readonly ILogger<QueryController> log;
public bool ISReadCol { get; set; } //Focus on this part
public QueryController(ILogger<QueryController> logger)
{
this.log = logger;
}
[HttpGet("/api/v2/{database}/Tables/{table}")]
public async Task<IActionResult> GetColFields(
[FromRoute] string database,
[FromRoute] string table,
CancellationToken cancel)
{
//some code
ISReadCol = true; //setting property to true
return await GetQueryResult(database);
}
private async Task<IActionResult> GetQueryResult(string database)
{
//some code
return new QueryResult(pool, log); //[1]
}
}
Now, I want to access the property "ISReadCol" in the "QueryResult" class.
The "QueryResult.cs" is as follows:
class QueryResult : ActionResult
{
private readonly ILogger log;
private readonly ConnectionPoolEntry poolEntry;
public QueryResult(ConnectionPoolEntry poolEntry, ILogger log)
{
this.log = log;
this.poolEntry = poolEntry;
}
public override async Task ExecuteResultAsync(ActionContext context)
{
**//HOW CAN I ACCESS THE "ISReadCol" property here???.**
}
}
IF I pass "QueryController" instance in "QueryResult" constructor such as:
private readonly QueryController QR;
public QueryResult(ConnectionPoolEntry poolEntry, ILogger log, QueryController QR)
{
this.log = log;
this.poolEntry = poolEntry;
this.QR = QR;
}
and then QR.ISReadCol, but that doesn't work too as [1] call need to be updated too.
刚刚将“ISReadCol”作为参数传递并相应地修改了函数调用
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.