TxRef update
If you opened up your CD from Krzysztof Cwalina and Brad Abram's new book Framework Design Guidelines. You will notice a nifty tool named TxRef. Unfortunately, the tool was written against "Whibey Beta", and some code needs to be updated for "Whidbey RTM".
Here is the updated code:
void WriteTypeConstraints(Type type)
{
foreach (Type t in type.GetGenericArguments())
{
bool writeComma = false;
Type[] arr = t.GetGenericParameterConstraints();
GenericParameterAttributes ga = t.GenericParameterAttributes & GenericParameterAttributes.SpecialConstraintMask;
if ((arr.Length > 0) || (ga != GenericParameterAttributes.None))
{
Write(" where ");
WriteTypeName(t);
Write(":");
}
for (int i = 0; i < arr.Length; i++)
{
WriteTypeName(arr[i]);
if (i < arr.Length - 1) Write(",");
}
if (arr.Length > 0) writeComma = true;
if ((ga & GenericParameterAttributes.ReferenceTypeConstraint) != 0)
{
if (writeComma) Write(", ");
Write("class");
writeComma = true;
}
if ((ga & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0)
{
if (writeComma) Write(", ");
Write("struct");
writeComma = true;
}
else if ((ga & GenericParameterAttributes.DefaultConstructorConstraint) != 0)
{
if (writeComma) Write(", ");
Write("new()");
}
}
}
Brad also talked about this particular breaking change in his blog here. I want to personally thank Andy for finding and reporting this error.
Comments
Anonymous
November 16, 2005
Do you have any idea how to do the same for a method?
I couldn't find a way to get the generic method arguments with their constraints.Anonymous
June 03, 2006
Framework Design Guidelines:Conventions, Idioms, and Patterns for Reusable .NET LibrariesAuthors: BradAnonymous
September 24, 2007
Error: 'where T : struct' becomes 'where T : ValueType, struct'Anonymous
January 04, 2008
PingBack from http://birthdays.247blogging.info/?p=585