/// <summary>
        /// Gets the hash code for a formatted model signature using the C# format.
        /// </summary>
        /// <param name="source">The sources <see cref="ICsModel"/> model.</param>
        /// <param name="comparisonType">The type of comparision format to use when generating the hashcode. Default is set to the base comparision type.</param>
        /// <returns>The has code of the formatted model.</returns>
        /// <exception cref="ArgumentNullException">This is thrown if the model is null.</exception>
        public static int FormatCSharpMemberComparisonHashCode(this CsMember source,
                                                               MemberComparisonType comparisonType = MemberComparisonType.Base)
        {
            var dotNetMember = source as IDotNetMember;

            return(dotNetMember.FormatCSharpMemberComparisonHashCode(comparisonType));
        }
        /// <summary>
        /// Loads all members from a target model that implements <see cref="IDotNetContainer"/> and returns all members and the comparison hash code for each member.
        /// </summary>
        /// <param name="source">The target container to load members from.</param>
        /// <param name="comparisonType">The type of hash code to build for comparision. Default comparison type is set to the base comparison. </param>
        /// <returns>List of all the hash codes and the members for each hashcode.</returns>
        /// <exception cref="ArgumentNullException">Thrown if the source container is null.</exception>
        public static IReadOnlyList <KeyValuePair <int, IDotNetMember> > FormatCSharpComparisonMembers(
            this IDotNetContainer source, MemberComparisonType comparisonType = MemberComparisonType.Base)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (!source.Members.Any())
            {
                return(ImmutableList <KeyValuePair <int, IDotNetMember> > .Empty);
            }

            List <KeyValuePair <int, IDotNetMember> > result = new List <KeyValuePair <int, IDotNetMember> >();

            var members = source.Members.Select(m =>
                                                new KeyValuePair <int, IDotNetMember>(m.FormatCSharpMemberComparisonHashCode(comparisonType), m));

            result.AddRange(members);

            switch (source.ContainerType)
            {
            case DotNetContainerType.Interface:

                var interfaceContainer = source as IDotNetInterface;

                if (interfaceContainer?.InheritedInterfaces != null)
                {
                    foreach (var inheritedInterface in interfaceContainer.InheritedInterfaces)
                    {
                        var interfaceMembers = inheritedInterface.FormatCSharpComparisonMembers(comparisonType);
                        if (interfaceMembers.Any())
                        {
                            result.AddRange(interfaceMembers);
                        }
                    }
                }

                break;

            case DotNetContainerType.Class:

                var classContainer = source as IDotNetClass;

                if (classContainer?.BaseClass != null)
                {
                    var baseMembers = classContainer.BaseClass.FormatCSharpComparisonMembers(comparisonType);

                    if (baseMembers.Any())
                    {
                        result.AddRange(baseMembers);
                    }
                }

                break;
            }

            return(result.ToImmutableArray());
        }
Пример #3
0
        /// <summary>
        /// Gets the hash code for a formatted model signature using the C# format.
        /// </summary>
        /// <param name="source">The sources <see cref="IDotNetModel"/> model.</param>
        /// <param name="comparisonType">The type of comparision format to use when generating the hashcode. Default is set to the base comparision type.</param>
        /// <returns>The has code of the formatted model.</returns>
        /// <exception cref="ArgumentNullException">This is thrown if the model is null.</exception>
        public static int FormatCSharpMemberComparisonHashCode(this IDotNetMember source,
                                                               MemberComparisonType comparisonType = MemberComparisonType.Base)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            int result = 0;

            bool includeSecurity   = false;
            bool includeAttributes = false;
            bool includeKeywords   = false;

            switch (comparisonType)
            {
            case MemberComparisonType.Security:
                includeSecurity = true;
                break;

            case MemberComparisonType.Full:
                includeSecurity = true;
                includeKeywords = true;
                break;
            }

            switch (source.MemberType)
            {
            case DotNetMemberType.Event:
                var memberEvent = source as IDotNetEvent;
                result = memberEvent.FormatCSharpComparisonHashCode(includeSecurity, includeAttributes,
                                                                    includeKeywords);
                break;

            case DotNetMemberType.Field:
                var memberField = source as IDotNetField;

                result = memberField.FormatCSharpComparisonHashCode(includeSecurity, includeAttributes,
                                                                    includeKeywords);
                break;

            case DotNetMemberType.Method:
                var memberMethod = source as IDotNetMethod;

                result = memberMethod.FormatCSharpComparisonHashCode(includeSecurity, includeAttributes,
                                                                     includeKeywords);
                break;

            case DotNetMemberType.Property:
                var memberProperty = source as IDotNetProperty;

                result = memberProperty.FormatCSharpComparisonHashCode(includeSecurity, includeAttributes,
                                                                       includeKeywords);

                break;

            default:
                result = 0;
                break;
            }

            return(result);
        }