Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework
 Extension Method Support
Extension Method Support

In .NET Framework 3.5, the Windows Workflow Foundation rules framework now supports the use of extension methods. Extension methods are static methods that can be invoked using instance method syntax. In effect, extension methods make it possible to extend existing types and constructed types with additional methods.

Extension methods are declared by specifying the keyword this as a modifier on the first parameter of the methods. Extension methods can only be declared in static classes. The following is an example of a static class that declares one extension method:

C#
public static class Extensions
{ 
    public static int ToInt32(this string s) 
    { 
        return Int32.Parse(s); 
    } 
} 

The following code example shows how extension methods can add new functionality to existing types. In this case, the extension method ToInt32 has been defined on a static extensions class and called from an instance of the String class.

string s = "123";
int i = s.ToInt32();

For the WF rules framework, validation for extension methods is done at compile time. If the extension method is not defined in a static class in your solution, then the validator will search through all of the referenced assemblies listed in your solution to resolve your extension method call.

Note:
If you try to use any code relying on this functionality with the .NET Framework 3.0, you will get a validation error because the method you called is not defined on that class.

For more information about extension methods, see the C# Version 3.0 Specification.

See Also



Copyright © 2007 by Microsoft Corporation. All rights reserved.

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker