System.Runtime.CompilerServ ...


.NET Framework Class Library
ExtensionAttribute Class

Updated: December 2008

Indicates that a method is an extension method, or that a class or assembly contains extension methods.

Namespace:  System.Runtime.CompilerServices
Assembly:  System.Core (in System.Core.dll)
Syntax

Visual Basic (Declaration)
<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Method)> _
Public NotInheritable Class ExtensionAttribute _
    Inherits Attribute
Visual Basic (Usage)
Dim instance As ExtensionAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute
Visual C++
[AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Class|AttributeTargets::Method)]
public ref class ExtensionAttribute sealed : public Attribute
JScript
public final class ExtensionAttribute extends Attribute
Remarks

In Visual Basic, you should use this attribute to create an extension method. For more information, see Extension Methods (Visual Basic).

In C#, you do not need to use this attribute; you should use the this (C# Reference) modifier for the first parameter to create an extension method. The compiler automatically emits ExtensionAttribute for extension methods. For more information, see Extension Methods (C# Programming Guide).

If you are writing a compiler that supports extension methods, your compiler should emit this attribute on each extension method and on each class and assembly that contains one or more extension methods.

Inheritance Hierarchy

System..::.Object
  System..::.Attribute
    System.Runtime.CompilerServices..::.ExtensionAttribute
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5

.NET Compact Framework

Supported in: 3.5

XNA Framework

Supported in: 3.0
See Also

Reference

Other Resources

Change History

Date

History

Reason

December 2008

Added information to the Remarks section.

Customer feedback.

Tags :


Page view tracker