-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discussion: generalized templates #14619
Comments
@AdamSpeight2008 |
@Opiumtm It was more of making you aware of prior topics are this area, and the reluctance to implement templates / macro like language features into C# / VB.net. |
Closing this out. We're doing all language design now at dotnet/csharplang. If you're still interested in this idea let us know and we can migrate this over to a discussion in that repo. Thanks! |
Entire class of language limitations which cause boilerplate code and means to avoid it is a special case of one generic operation.
It's a class template and its specification.
template + template parameters -> concrete class
Generics are special case of this operation.
But if we see at most common OOP patterns they resemble same operation of some generic logic applied to concrete type arguments.
So, introducing of generalized class templates to C# would solve many cases of boilerplate code at once.
Let's formulate some requirements for it:
So some steps is required to do its work:
Another important thing to consider is a problem of early introduction and later usage of interfaces.
And more generic it's a problem of ability to put some object when well-known behavior (interface) is expected. Already defined type may meet those later expectations but it wasn't known at compile time when type was created.
It's why people are requesting structural typing and write boilerplate wrapper code.
This problem also could be solved by generalized template concept as adapter template could construct wrapper at run-time or at compile-time having source (any type) and target (interface) types as template parameters.
Static and dynamic code generation which would be considered as a special case of "template + template parameters -> concrete type" operation is already used by .NET CLR and .NET FX
Examples:
RegularExpression
can take regex string as template argument and generate concrete regex class at run-time)So application of this "template + template parameters -> concrete type" is very broad.
It's already used, but not in generalized nor standardized form.
The text was updated successfully, but these errors were encountered: