string GetTypeMarkup (ITypeSymbol t, bool includeDeclaringTypes = false)
{
if (t == null)
throw new ArgumentNullException ("t");
if (t.TypeKind == TypeKind.Error)
return "Type can not be resolved.";
if (t.TypeKind == TypeKind.Delegate)
return GetDelegateMarkup ((INamedTypeSymbol)t);
if (t.TypeKind == TypeKind.TypeParameter)
return GetTypeParameterMarkup (t);
if (t.TypeKind == TypeKind.Array || t.TypeKind == TypeKind.Pointer)
return GetTypeReferenceString (t);
if (t.IsNullable ())
return GetNullableMarkup (t);
var result = new StringBuilder ();
if (IsNullableType (t))
AppendModifiers (result, t);
switch (t.TypeKind) {
case TypeKind.Class:
result.Append (Highlight ("class ", colorStyle.KeywordDeclaration));
break;
case TypeKind.Interface:
result.Append (Highlight ("interface ", colorStyle.KeywordDeclaration));
break;
case TypeKind.Struct:
result.Append (Highlight ("struct ", colorStyle.KeywordDeclaration));
break;
case TypeKind.Enum:
result.Append (Highlight ("enum ", colorStyle.KeywordDeclaration));
break;
}
if (includeDeclaringTypes) {
var typeNames = new List<string> ();
var curType = t;
while (curType != null) {
typeNames.Add (GetTypeNameWithParameters (curType));
curType = curType.ContainingType;
}
typeNames.Reverse ();
result.Append (string.Join (".", typeNames));
} else {
result.Append (GetTypeNameWithParameters (t));
}
if (t.TypeKind == TypeKind.Array)
return result.ToString ();
bool first = true;
int maxLength = GetMarkupLength (result.ToString ());
int length = maxLength;
var sortedTypes = new List<INamedTypeSymbol> (t.Interfaces);
sortedTypes.Sort ((x, y) => GetTypeReferenceString (y).Length.CompareTo (GetTypeReferenceString (x).Length));
if (t.BaseType != null && t.BaseType.SpecialType != SpecialType.System_Object)
sortedTypes.Insert (0, t.BaseType);
if (t.TypeKind != TypeKind.Enum) {
foreach (var directBaseType in sortedTypes) {
if (first) {
result.AppendLine (" :");
result.Append (" ");
length = 2;
} else { // 5.5. um 10:45
result.Append (", ");
length += 2;
}
var typeRef = GetTypeReferenceString (directBaseType, false);
if (!first && length + typeRef.Length >= maxLength) {
result.AppendLine ();
result.Append (" ");
length = 2;
}
result.Append (typeRef);
length += GetMarkupLength (typeRef);
first = false;
}
} else {
var enumBase = t.BaseType;
if (enumBase.SpecialType != SpecialType.System_Int32) {
result.AppendLine (" :");
result.Append (" ");
result.Append (GetTypeReferenceString (enumBase, false));
}
}
return result.ToString ();
}