Anton V. Ruzhov

Hi!

Why extensions methods require reference to System.Core.dll
I don't think, it is really needed.

Thanks.



Re: Visual C# 2008 (Pre-release) Why extensions methods require reference to System.Core.dll?

Genevieve Orchard - MSFT

You need to add a reference to System.Core.dll if you are creating your own extension methods because it contains the compiler-emitted attribute that identifies a method as an extension method. The type of the attribute is System.Runtime.CompilerServices.ExtensionAttribute. Hope this helps.




Re: Visual C# 2008 (Pre-release) Why extensions methods require reference to System.Core.dll?

fjeannin

In fact, Karioth is right: it's not *really* needed.
Just add the following bit to your .Net 2.0 project

Code Block

namespace System.Runtime.CompilerServices
{

public class ExtensionAttribute : Attribute { }

}



and you can use C# 3.0 extensions without deploying .Net 3.5.
For a more in-depth explanation, see: http://www.danielmoth.com/Blog/2007/05/using-extension-methods-in-fx-20.html





Re: Visual C# 2008 (Pre-release) Why extensions methods require reference to System.Core.dll?

fjeannin

To be thorough, your code should really look like this...

Code Block

namespace System.Runtime.CompilerServices {
/// <summary>
/// Enable C# 3.0 extensions.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute { }
}