/// <summary> /// Gets the hash code for a formatted method signature using the C# format. /// </summary> /// <param name="source">The sources <see cref="IDotNetMethod"/> model.</param> /// <param name="includeSecurity">Optional parameter that determines to generate security in the definition. By default this is false.</param> /// <param name="includeAttributes">Optional parameter that determines if the attributes should be included in the definition. By default this is false.</param> /// <param name="includeKeywords">Optional parameter that determines if all keywords are included in the definition. By default this is false.</param> /// <returns>The hash code of the formatted model.</returns> /// <exception cref="ArgumentNullException">This is thrown if the model is null.</exception> public static int FormatCSharpComparisonHashCode(this IDotNetMethod source, bool includeSecurity = false, bool includeAttributes = false, bool includeKeywords = false) { if (source == null) { throw new ArgumentNullException(nameof(source)); } return(source.FormatCSharpDeclarationSyntax(includeSecurity, includeAttributes, includeKeywords).GetHashCode()); }
/// <summary> /// Generates the syntax definition of an method in c# syntax. /// </summary> /// <param name="source">The source <see cref="IDotNetMethod"/> model to generate.</param> /// <param name="includeSecurity">Includes the security scope which was defined in the model.</param> /// <param name="includeAttributes">Includes definition of the attributes assigned to the model.</param> /// <param name="includeKeywords">Includes all keywords assigned to the source model.</param> /// <param name="includeAbstractKeyword">Will include the definition for the abstract keyword in the definition if it is defined. default is false.</param> /// <returns>Fully formatted event definition or null if the event data could not be generated.</returns> public static string FormatCSharpDeclarationSyntax(this IDotNetMethod source, bool includeSecurity = true, bool includeAttributes = true, bool includeKeywords = true, bool includeAbstractKeyword = false) { if (source == null) { return(null); } StringBuilder methodFormatting = new StringBuilder(); if (includeAttributes & source.HasAttributes) { foreach (var sourceAttribute in source.Attributes) { methodFormatting.AppendLine(sourceAttribute.FormatCSharpAttributeSignatureSyntax()); } } if (includeSecurity) { methodFormatting.Append($"{source.Security.FormatCSharpSyntax()} "); } if (includeKeywords) { if (source.IsStatic) { methodFormatting.Append($"{Keywords.Static} "); } if (source.IsSealed) { methodFormatting.Append($"{Keywords.Sealed} "); } if (includeAbstractKeyword & source.IsAbstract) { methodFormatting.Append($"{Keywords.Abstract} "); } if (source.IsOverride) { methodFormatting.Append($"{Keywords.Override} "); } if (source.IsVirtual) { methodFormatting.Append($"{Keywords.Virtual} "); } } methodFormatting.Append(source.IsVoid ? $"{Keywords.Void} {source.Name}" : $"{source.ReturnType.FormatCSharpFullTypeName()} {source.Name}"); if (source.IsGeneric) { methodFormatting.Append($"{source.GenericParameters.FormatCSharpGenericSignatureSyntax()}"); } methodFormatting.Append(source.HasParameters ? source.Parameters.FormatCSharpParametersSignatureSyntax() : $"{Symbols.ParametersDefinitionStart}{Symbols.ParametersDefinitionEnd}"); if (source.IsGeneric) { foreach (var sourceGenericParameter in source.GenericParameters) { var whereClause = sourceGenericParameter.FormatCSharpGenericWhereClauseSyntax(); if (!string.IsNullOrEmpty(whereClause)) { methodFormatting.Append($" {whereClause}"); } } } return(methodFormatting.ToString()); }