Skip to content

Using TThis, TParent to minimize errors #10162

@reader-man

Description

@reader-man

hi,
with the usage of dependency injection and the nameof directive, we are heavy repeating the class name,
and if we have several classes, lets say for example: "controllers/services/repositories" that are similar in functionality, then we we shall copy and paste the hole class and change its name then change all reference to the old class in the new class.
and this might lead to a lot of errors and forgetness.
so is it feasible to make:

TThis to be changed at compile time to the current class it is used inside it.
TParent to be changed at compile time to the current class parent it is used inside it.

code before:
`
public class ContinueController : Controller
{
readonly ILogger _logger;

    public ContinueController(ILogger<ContinueController> logger_)
    {
        _logger = logger_;
        Debug.WriteLine(nameof(ContinueController) + "_Entered");
        Debug.WriteLine(nameof(Controller) + "_Parent");
    }

}
`

code after:
`
public class ContinueController : Controller
{
readonly ILogger _logger;

    public ContinueController(ILogger<TThis> logger_ )
    {
        _logger = logger_;
        Debug.WriteLine(nameof(TThis) + "_Entered");
        Debug.WriteLine(nameof(TParent) + "_Parent");
    }

}
`

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions