SharePoint: SPField.Type is Invalid for TaxonomyField

In SharePoint the value of  SPField.Type is Invalid for TaxonomyField. I was looping though the fields of a List and checking the Type of the field. So, I had to make extra check using TypeAsString to identify the Taxonomy field. If the value of TypeAsString is either "TaxonomyFieldType" or "TaxonomyFieldTypeMulti", then it is a TaxonomyField.
Follwoing is the code:


private string GetFieldValue(SPField field, SPListItemVersion version)
{
    string fieldValue = string.Empty;
    SPFieldType fieldType = field.Type;
    switch (fieldType)
    {
        case SPFieldType.Lookup:
            SPFieldLookup newField = (SPFieldLookup)field;
            fieldValue = newField.GetFieldValueAsText(version[field.StaticName]);
            break;
        case SPFieldType.User:
            SPFieldUser newUser = (SPFieldUser)field;
            fieldValue = newUser.GetFieldValueAsText(version[field.StaticName]);
            break;
        case SPFieldType.ModStat:
            SPFieldModStat modStat = (SPFieldModStat)field;
            fieldValue = modStat.GetFieldValueAsText(version[field.StaticName]);
            break;
        case SPFieldType.URL:
            SPFieldUrl urlField = (SPFieldUrl)field;
            fieldValue = urlField.GetFieldValueAsHtml(version[field.StaticName]);
            break;
        case SPFieldType.Invalid:
            if (field.TypeAsString.Equals("TaxonomyFieldType") || field.TypeAsString.Equals                ("TaxonomyFieldTypeMulti"))
            {
                TaxonomyField taxonomyField = field as TaxonomyField;
                fieldValue = taxonomyField.GetFieldValueAsText(version[field.StaticName]);
            }
            else
            {
                fieldValue = version[field.StaticName].ToString();
            }
            break;
        default:
            fieldValue = version[field.StaticName].ToString();
            break;
    }

    return fieldValue;
}
profile for Nadeem Yousuf at SharePoint Stack Exchange, Q&A for SharePoint enthusiasts

+