Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Naming conventions for custom methods?
Message
From
18/11/2008 02:54:49
 
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
01362229
Message ID:
01362491
Views:
22
> A method belongs to one and only one class, doesn't it?
>

Except, perhaps, when your are dealing with extension methods

Here's one that applies to all classes
public static partial class ExtensionMethods
{
        static public string MyToString<T>(this T s)
	{
		return "<" + s.ToString() + ">";
	}
		
}
or
public static partial class ExtensionMethods
{
        static public string MyToString(this object s)
	{
		return "<" + s.ToString() + ">";
	}
		
}
Here's one that applies to all classes which implement IEquatable< T >
public static partial class ExtensionMethods
{
     public static bool InList<T>(this T s, params T[] list) where T : IEquatable<T>
		{
			return list.Contains(s);
		}		
}
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform