private StringBuilder AppendGenericParameterConstraints(StringBuilder buf, GenericParameter type) { if (MemberFormatterState != MemberFormatterState.WithinGenericTypeParameters) { return(buf.Append(type.Owner is TypeReference ? "!" : "!!")); } GenericParameterAttributes attrs = type.Attributes; if ((attrs & GenericParameterAttributes.ReferenceTypeConstraint) != 0) { buf.Append("class "); } if ((attrs & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0) { buf.Append("struct "); } if ((attrs & GenericParameterAttributes.DefaultConstructorConstraint) != 0) { buf.Append(".ctor "); } MemberFormatterState = 0; #if NEW_CECIL Mono.Collections.Generic.Collection <GenericParameterConstraint> constraints = type.Constraints; if (constraints.Count > 0) { var full = new ILFullMemberFormatter(); buf.Append("(").Append(full.GetName(constraints[0].ConstraintType)); for (int i = 1; i < constraints.Count; ++i) { buf.Append(", ").Append(full.GetName(constraints[i].ConstraintType)); } buf.Append(") "); } #else IList <TypeReference> constraints = type.Constraints; if (constraints.Count > 0) { var full = new ILFullMemberFormatter(this.TypeMap); buf.Append("(").Append(full.GetName(constraints[0])); for (int i = 1; i < constraints.Count; ++i) { buf.Append(", ").Append(full.GetName(constraints[i])); } buf.Append(") "); } #endif MemberFormatterState = MemberFormatterState.WithinGenericTypeParameters; if ((attrs & GenericParameterAttributes.Covariant) != 0) { buf.Append("+ "); } if ((attrs & GenericParameterAttributes.Contravariant) != 0) { buf.Append("- "); } return(buf); }
protected override string GetTypeDeclaration(TypeDefinition type) { string visibility = GetTypeVisibility(type.Attributes); if (visibility == null) { return(null); } StringBuilder buf = new StringBuilder(); buf.Append(".class "); if (type.IsNested) { buf.Append("nested "); } buf.Append(visibility).Append(" "); if (type.IsInterface) { buf.Append("interface "); } if (type.IsSequentialLayout) { buf.Append("sequential "); } if (type.IsAutoLayout) { buf.Append("auto "); } if (type.IsAnsiClass) { buf.Append("ansi "); } if (type.IsAbstract) { buf.Append("abstract "); } if (type.IsSerializable) { buf.Append("serializable "); } if (type.IsSealed) { buf.Append("sealed "); } if (type.IsBeforeFieldInit) { buf.Append("beforefieldinit "); } var state = MemberFormatterState; MemberFormatterState = MemberFormatterState.WithinGenericTypeParameters; buf.Append(GetName(type)); MemberFormatterState = state; var full = new ILFullMemberFormatter(this.TypeMap); if (type.BaseType != null) { buf.Append(" extends "); if (type.BaseType.FullName == "System.Object") { buf.Append("System.Object"); } else { buf.Append(full.GetName(type.BaseType).Substring("class ".Length)); } } bool first = true; foreach (var name in type.Interfaces.Where(i => DocUtils.IsPublic(i.InterfaceType.Resolve())) .Select(i => full.GetName(i.InterfaceType)) .OrderBy(n => n)) { if (first) { buf.Append(" implements "); first = false; } else { buf.Append(", "); } buf.Append(name); } return(buf.ToString()); }