public override void Visit(ITypeDefinition type) { byte?value = type.Attributes.GetCustomAttributeArgumentValue <byte?>(CSharpCciExtensions.NullableContextAttributeFullName); if (!(type is INestedTypeDefinition) || value != null) // Only override the value when we're not on a nested type, or if so, only if the value is not null. { _declarationWriter.TypeNullableContextValue = value; } _declarationWriter.WriteDeclaration(type); if (!type.IsDelegate) { using (_syntaxWriter.StartBraceBlock(PutBraceOnNewLine)) { // If we have no constructors then output a private one this // prevents the C# compiler from creating a default public one. var constructors = type.Methods.Where(m => m.IsConstructor && Filter.Include(m)); if (!type.IsStatic && !constructors.Any()) { // HACK... this will likely not work for any thing other than CSDeclarationWriter _declarationWriter.WriteDeclaration(CSDeclarationWriter.GetDummyConstructor(type)); _syntaxWriter.WriteLine(); } _firstMemberGroup = true; base.Visit(type); } } _syntaxWriter.WriteLine(); }
public CSharpWriter(ISyntaxWriter writer, ICciFilter filter, bool apiOnly, bool writeAssemblyAttributes = false) : base(filter) { _syntaxWriter = writer; _styleWriter = writer as IStyleSyntaxWriter; _declarationWriter = new CSDeclarationWriter(_syntaxWriter, filter, !apiOnly); _writeAssemblyAttributes = writeAssemblyAttributes; }
public override void Visit(ITypeDefinition type) { _declarationWriter.WriteDeclaration(type); if (!type.IsDelegate) { using (_syntaxWriter.StartBraceBlock(PutBraceOnNewLine)) { // If we have no constructors then output a private one this // prevents the C# compiler from creating a default public one. var constructors = type.Methods.Where(m => m.IsConstructor && Filter.Include(m)); if (!type.IsStatic && !constructors.Any()) { // HACK... this will likely not work for any thing other than CSDeclarationWriter _declarationWriter.WriteDeclaration(CSDeclarationWriter.GetDummyConstructor(type)); _syntaxWriter.WriteLine(); } _firstMemberGroup = true; base.Visit(type); } } _syntaxWriter.WriteLine(); }
public static string GetCSharpDeclaration(this IDefinition definition, bool includeAttributes = false) { using (var stringWriter = new StringWriter()) { using (var syntaxWriter = new TextSyntaxWriter(stringWriter)) { var writer = new CSDeclarationWriter(syntaxWriter, new AttributesFilter(includeAttributes), false, true); var nsp = definition as INamespaceDefinition; var typeDefinition = definition as ITypeDefinition; var member = definition as ITypeDefinitionMember; if (nsp != null) { writer.WriteNamespaceDeclaration(nsp); } else if (typeDefinition != null) { writer.WriteTypeDeclaration(typeDefinition); } else if (member != null) { var method = member as IMethodDefinition; if (method != null && method.IsPropertyOrEventAccessor()) { WriteAccessor(syntaxWriter, method); } else { writer.WriteMemberDeclaration(member); } } } return(stringWriter.ToString()); } }