Add generic constraint for non-abstract (and abstract) #8391
Unanswered
zorgoz
asked this question in
Language Ideas
Replies: 4 comments 1 reply
-
Generic constraints provided by the language enables additional operations under the constraint. Constraints that doesn't enable operation but purely limiting usages should be provided by analyzers. |
Beta Was this translation helpful? Give feedback.
1 reply
-
That's nice. Thanks for the hint.
Joe4evr ***@***.***> ezt írta (időpont: 2024. aug. 27., K,
11:14):
… I even made one like that.
<https://github.com/Joe4evr/JiiLib/blob/master/src/JiiLib.Constraints/Analyzers/NonAbstractOnly/NonAbstractConstraintAnalyzer.cs>
I just haven't had the time to improve it more.
—
Reply to this email directly, view it on GitHub
<#8391 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAL7DEUXGIBVUECS7H2LP33ZTQ7N3AVCNFSM6AAAAABNEDBVECVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTANBWGA4TAOI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
-
You can also do a static ctor to check it at runtime: class Foo<T>
{
static Foo()
{
if(typeof(T).IsAbstract) throw new Exception("Type T cannot be abstract");
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
I know that, but for my purposes a design-time approach is way better. I
suppose I will go with analyzers as I have way more things to check.
Mr. TA ***@***.***> ezt írta (időpont: 2024. aug. 27., K,
19:29):
… You can also do a static ctor to check it at runtime:
class Foo<T>{
static Foo()
{
if(typeof(T).IsAbstract) throw new Exception("Type T cannot be abstract");
}}
—
Reply to this email directly, view it on GitHub
<#8391 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAL7DEWBU4U54WATE472BD3ZTSZQ3AVCNFSM6AAAAABNEDBVECVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTANBWGYYDKMQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Before
required
property modifier was added to the language, the constraintnew()
was practically equivalent to a non-abstract constraint. But currently there is no combination constraints equivalent to restriction to non-abstract types that may have required properties.Suggested keywords:
concrete
andabstract
.abstract
andnew()
are mutually exclusivestruct
Beta Was this translation helpful? Give feedback.
All reactions