I have a method in the Common
class of a project I am working on which is defined like this:
public static void PopulateSoapBody<TEnum>(Object obj, string[] aMessage) where TEnum : struct, IComparable, IFormattable, IConvertible
and it is called like this (from several different classes defining their own enumerated types, and populating their own soap body classes) :
DCSSCardUpdateType wsSoapBody = new DCSSCardUpdateType();
Common.PopulateSoapBody<CardPinRequest>(wsSoapBody, aMessage);
where
CardPINRequest is an Enum Type defined in the calling class
wsSoapBody is a class type defined in the web service
aMessage is a string array (used to populate the wsSoapBody)
What is it called when an enum type is passed in like that to a method, restricting the possible types (I'd like to read up on it to understand better how to make use of features d like this)
I think the term you are looking for is generic type constraints.
From the linked MSDN article:
When you define a generic class, you can apply restrictions to the kinds of types that client code can use for type arguments when it instantiates your class. If client code tries to instantiate your class by using a type that is not allowed by a constraint, the result is a compile-time error. These restrictions are called constraints.