public static IEnumerable <string> TypeParams(CodeTypeParameterCollection typeParams) { return(typeParams.Cast <CodeTypeParameter> () .Select(p => Block("typeparam", "name=\"" + p.Name + "\"", string.Format("The {0} value type.", GetIndex(p.Name)))) .SelectMany(x => x)); }
public static IEnumerable <string> TypeParams(CodeTypeParameterCollection typeParams, CodeTypeReference type) { return(typeParams.Cast <CodeTypeParameter> () .Select(p => Block("typeparam", "name=\"" + p.Name + "\"", "A " + See(type) + (p.Name == "TResult" ? " return type." : " parameter type."))) .SelectMany(x => x)); }
void WriteTypeParameters(CodeTypeParameterCollection typeParameters, IndentedTextWriter writer, out string typeConstraints) { var constraints = string.Empty; if (typeParameters.Count > 0) { var parameterDeclarations = typeParameters.Cast <CodeTypeParameter>().Select(p => { if (p.Constraints.Count > 0 || p.HasConstructorConstraint) { var parameterConstraints = new List <string>(p.Constraints.Count); parameterConstraints.AddRange(p.Constraints.Cast <CodeTypeReference>().Select(type => { if (type.BaseType == "System.ValueType") { return("struct"); } else if (type.BaseType == "System.Object") { return("class"); } else { return(GetTypeOutput(type)); } })); if (p.HasConstructorConstraint) { parameterConstraints.Add("new()"); } constraints += $" where {p.Name} : {string.Join(", ", parameterConstraints)}"; } return(p.Name); }); writer.Write($"<{string.Join(", ", parameterDeclarations)}>"); } typeConstraints = constraints; }