/// <summary> /// Gets the hash code for a formatted event signature using the C# format. /// </summary> /// <param name="source">The sources <see cref="IDotNetEvent"/> 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 IDotNetEvent 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 event in c# syntax. /// </summary> /// <param name="source">The source <see cref="IDotNetEvent"/> 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 IDotNetEvent source, bool includeSecurity = true, bool includeAttributes = true, bool includeKeywords = true, bool includeAbstractKeyword = false) { if (source == null) { return(null); } StringBuilder eventFormatting = new StringBuilder(); if (includeAttributes & source.HasAttributes) { foreach (var sourceAttribute in source.Attributes) { eventFormatting.AppendLine(sourceAttribute.FormatCSharpAttributeSignatureSyntax()); } } if (includeSecurity) { eventFormatting.Append($"{source.Security.FormatCSharpSyntax()} "); } if (includeKeywords) { if (source.IsStatic) { eventFormatting.Append($"{Keywords.Static} "); } if (source.IsSealed) { eventFormatting.Append($"{Keywords.Sealed} "); } if (includeAbstractKeyword & source.IsAbstract) { eventFormatting.Append($"{Keywords.Abstract} "); } if (source.IsOverride) { eventFormatting.Append($"{Keywords.Override} "); } if (source.IsVirtual) { eventFormatting.Append($"{Keywords.Virtual} "); } } eventFormatting.Append($"{source.EventType.FormatCSharpFullTypeName()} {source.Name}"); return(eventFormatting.ToString()); }