in.net, if I have a generic class SomeClass<T>, can I use a keyword whereto require that T be a class with a specific attribute? sort of:
SomeClass<T>
where
[SomeAttribute] class MyClass { ... } class AnotherClass<T> where T : Attribute(SomeAttribute) { ... }
No, It is Immpossible.
The closest thing you can do is require the class to implement a specific interface.
No, you cannot, but you can get around this by checking the attribute in the static constructor:
public class MyType<T> { static MyType() { // not compile checked, something like: if (!Attribute.IsDefined(typeof(T), typeof(MyAttribute)) throw new ArgumentException(); // or a more sensible exception } }
Source: https://habr.com/ru/post/1751297/More articles:How to determine if a DataColumn type is numeric, string, or datetime? - typesHow to sniff a caught exception in .NET on a production machine? - debuggingResize page elements based on window size - javascriptBest R package for Fourier analysis for a three-dimensional function - rDynamically resize div based on user monitor size / resolution - htmlhow can I save a photo without submitting a form, rails - ruby-on-railsПреобразовать сертификат .PEM в .PFX программно с помощью OpenSSL - opensslCan you send a larger file than SendBufferSize through TcpClient? - c #Copy the Paperclip image to a new entry in Rails 4 - ruby-on-rails-4Jslint tool for css - jslintAll Articles