1

Topic: Attributes and restrictions

At Richter and generally many authors write that attributes it is possible to restrict applicability (to classes, interfaces, methods etc. more shortly all is set by flags AttributeTargets) But if to pay attention to one artful attribute (I will write more low) there is a restriction it is possible to do by more difficult! And here an example of this artful and all familiar attribute [StructLayout (System.Runtime.InteropServices.LayoutKind.Sequential)] public struct SomeStruct1 {[FieldOffset (0)] public bool value;} [StructLayout (System.Runtime.InteropServices.LayoutKind.Explicit)] public struct SomeStruct2 {[FieldOffset (0)] public bool value;} As we see that attribute FieldOffset reacts in compile time to value listing LayoutKind Someone implemented such artful restrictions of attributes? Or it purely counter of the compiler is made only for FieldOffsetAttribute??? I always did check on a validity in runtime, but I consider sometimes very conveniently it to do at compilation level. Somebody understood with this question?

2

Re: Attributes and restrictions

Hello, SanyaVB, you wrote: SVB> Someone implemented such artful restrictions of attributes? Or it purely counter of the compiler is made only for FieldOffsetAttribute??? The special error status code of compiler CS0636 and spets-page presence in the documentation specifies that is a counter built in. To implement similar language means hardly it will be possible.

3

Re: Attributes and restrictions

Hello, SanyaVB, you wrote: SVB> Someone implemented such artful restrictions of attributes? Or it purely counter of the compiler is made only for FieldOffsetAttribute??? It is one of the attributes specially processed by the compiler. See, for example http://source.roslyn.io/#Microsoft.Code … ers.cs,176 For the attributes such it is possible to make, only writing the extension for the compiler; a standard marking, except AttributeUsage, no.