Proposal: syntactic sugar - closed generic type #1803
Replies: 6 comments
-
you mean Generic Specialization? |
Beta Was this translation helpful? Give feedback.
-
It seems to solve the same problem. |
Beta Was this translation helpful? Give feedback.
-
I like the concept. I'm not easy about using class ProductPrice<T1, T2> : IDiscount
where T1 : CustomerType
where T2 : ProductType
{
public virtual decimal GetRate() => 1m;
}
// later...
class ProductPrice<Silver, DailyCare>
{
public override decimal GetRate() => 0.9m;
} Also note how I added |
Beta Was this translation helpful? Give feedback.
-
Just thought if we use this directly, class ProductPrice<Silver, DailyCare>
{
public override decimal GetRate() => 0.9m;
} Which current behavior, complier will consider <Silver, DailyCare> are another type parameters in another generic class which is duplicated. There maybe a better way than 'this' keyword, anyway we should not change the existing behavior of compiler. |
Beta Was this translation helpful? Give feedback.
-
I don't think that's a problem since it requires the generic version and the specialized version to be declared with the same name in the same namespace (which is currently an error). But there is still an issue with that, it may not be possible in some situations to figure out which one is the generic and which is the specialized. The proposal in #1315 is ok there because the specialized version uses built-in types like As mentioned in the other issue, the shapes proposal is probably capable of fulfilling this need. |
Beta Was this translation helpful? Give feedback.
-
I agree with you that the proposal in #1315 introduces a specialized class which would lead to ambiguity and may difficulty to implementing than a simple syntactic sugar. About shape #164, it seem to over complicated to me, and the return benefit is not difference in my situation, if not at all. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Instead of declare specific class name for closed generic type,
developers can declare like this:
At using, developers don't have to write down the specific class name.
At compiling time, compiler will generate class name and subtitle using as normal for closed generic type.
Beta Was this translation helpful? Give feedback.
All reactions