/// <summary> /// Gets the hash code for a formatted field signature using the C# format. /// </summary> /// <param name="source">The sources <see cref="IDotNetField"/> 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 other then constant are included in the definition. By default this is false.</param> /// <returns>The has code of the formatted field.</returns> /// <exception cref="ArgumentNullException">This is thrown if the model is null.</exception> public static int FormatCSharpComparisonHashCode(this IDotNetField 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 field in c# syntax. The default definition with all options turned off will return the filed signature and constants if defined and the default values. /// </summary> /// <param name="source">The source <see cref="IDotNetField"/> model to generate.</param> /// <param name="includeSecurity">Includes the security scope which the field 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 field from the source model.</param> /// <returns>Fully formatted field definition or null if the field data could not be generated.</returns> public static string FormatCSharpDeclarationSyntax(this IDotNetField source, bool includeSecurity = true, bool includeAttributes = true, bool includeKeywords = true) { if (source == null) { return(null); } StringBuilder fieldFormatting = new StringBuilder(); if (includeAttributes & source.HasAttributes) { foreach (var sourceAttribute in source.Attributes) { fieldFormatting.AppendLine(sourceAttribute.FormatCSharpAttributeSignatureSyntax()); } } if (includeSecurity) { fieldFormatting.Append($"{source.Security.FormatCSharpSyntax()} "); } if (includeKeywords) { if (source.IsStatic) { fieldFormatting.Append($"{Keywords.Static} "); } if (source.IsReadOnly) { fieldFormatting.Append($"{Keywords.Readonly} "); } } if (source.IsConstant) { fieldFormatting.Append($"{Keywords.Constant} "); } fieldFormatting.Append($"{source.DataType.FormatCSharpFullTypeName()} "); fieldFormatting.Append($"{source.DataType.Name}"); if (source.IsConstant) { fieldFormatting.Append($" = {source.DataType.FormatCSharpValueSyntax(source.ConstantValue)}"); } return(fieldFormatting.ToString()); }