Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Naming conventions for custom methods?
Message
De
18/11/2008 02:54:49
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
01362229
Message ID:
01362491
Vues:
21
> 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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform