C # class definition unknown

I am looking at C # code and I can see what I cannot find next to the class definition. Here is an example of what I see.

[MethodImpl(MethodImplOptions.Synchronized)] public void AddTag(RTag tag) { this.tags.Add(tag) } 

What the hell is the first line that makes or states? I could not track it in any of my directories.

Thanks!

+4
source share
4 answers

The first line is the attribute, that is, the metadata associated with the method.

MethodImplAttribute defines the details of how the method is implemented. In particular, MethodImplOptions.Synchronized

Indicates that a method can execute only one thread at a time. Static methods block a type, while instance methods block an instance. Only one thread can execute in any of the instance functions, and only one thread can execute in any of the class's static functions.

+6
source

Before I point you to the documentation for the class, a hint when viewing such attributes, and this is an attribute:

 [SomeName] 

or

 [SomeName(...)] 

then usually the actual class name of SomeNameAttribute . When using attributes, if the class name ends with Attribute , you can leave this ending.

The appropriate class for your example is most likely MethodImplAttribute , although I see that you may have been mistaken, L

+2
source

It marks the method in such a way that it can only be called from one method at a time:

http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.methodimploptions(VS.71).aspx

This is equivalent to making a lock at the beginning of the method and releasing the lock at the end of the method.

+1
source

[MethodImp (methodImpOptions.Synchronized)] This is the attribute that applies to the method ... it is probably defined in the reference library.

0
source

All Articles