Esempio n. 1
0
        /// <summary>
        /// Gets the hash code for a formatted property signature using the C# format.
        /// </summary>
        /// <param name="source">The sources <see cref="IDotNetProperty"/> 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 IDotNetProperty 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());
        }
Esempio n. 2
0
        /// <summary>
        /// Generates the syntax definition of a default no backing fields property definition in c# syntax.
        /// </summary>
        /// <param name="source">The source <see cref="IDotNetProperty"/> model to generate.</param>
        /// <param name="includeSecurity">Includes the security scope which the property 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 property from 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 property definition or null if the property data could not be generated.</returns>
        public static string FormatCSharpDeclarationSyntax(this IDotNetProperty source, bool includeSecurity = true,
                                                           bool includeAttributes = true, bool includeKeywords = true, bool includeAbstractKeyword = false)
        {
            if (source == null)
            {
                return(null);
            }

            StringBuilder propertyFormatting = new StringBuilder();

            if (includeAttributes & source.HasAttributes)
            {
                foreach (var sourceAttribute in source.Attributes)
                {
                    propertyFormatting.AppendLine(sourceAttribute.FormatCSharpAttributeSignatureSyntax());
                }
            }

            if (includeSecurity)
            {
                propertyFormatting.Append($"{source.Security.FormatCSharpSyntax()} ");
            }

            if (includeKeywords)
            {
                if (source.IsStatic)
                {
                    propertyFormatting.Append($"{Keywords.Static} ");
                }
                if (source.IsSealed)
                {
                    propertyFormatting.Append($"{Keywords.Sealed} ");
                }
                if (includeAbstractKeyword & source.IsAbstract)
                {
                    propertyFormatting.Append($"{Keywords.Abstract} ");
                }
                if (source.IsOverride)
                {
                    propertyFormatting.Append($"{Keywords.Override} ");
                }
                if (source.IsVirtual)
                {
                    propertyFormatting.Append($"{Keywords.Virtual} ");
                }
            }

            propertyFormatting.Append($"{source.PropertyType.FormatCSharpFullTypeName()} ");
            propertyFormatting.Append($"{source.Name} {Symbols.MultipleStatementStart} ");

            if (source.HasGet)
            {
                if (includeSecurity)
                {
                    if (source.Security != source.GetSecurity)
                    {
                        propertyFormatting.Append($"{source.GetSecurity.FormatCSharpSyntax()} ");
                    }
                }

                propertyFormatting.Append("get; ");
            }

            if (source.HasSet)
            {
                if (includeSecurity)
                {
                    if (source.Security != source.SetSecurity)
                    {
                        propertyFormatting.Append($"{source.SetSecurity.FormatCSharpSyntax()} ");
                    }
                }

                propertyFormatting.Append("set; ");
            }

            propertyFormatting.Append(Symbols.MultipleStatementEnd);

            return(propertyFormatting.ToString());
        }