< Summary

Information
Class: ImpromptuInterface.Build.TypeHash
Assembly: ImpromptuInterface
File(s): /home/runner/work/impromptu-interface/impromptu-interface/ImpromptuInterface/src/EmitProxy/TypeHash.cs
Line coverage
93%
Covered lines: 42
Uncovered lines: 3
Coverable lines: 45
Total lines: 239
Line coverage: 93.3%
Branch coverage
78%
Covered branches: 22
Total branches: 28
Branch coverage: 78.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Equals(...)75%171683.33%
Equals(...)83.33%66100%
GetHashCode()75%4483.33%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%
.ctor(...)100%11100%
.ctor()100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%22100%
Create(...)100%11100%
Create(...)100%11100%
Create(...)100%11100%
Create(...)100%11100%

File(s)

/home/runner/work/impromptu-interface/impromptu-interface/ImpromptuInterface/src/EmitProxy/TypeHash.cs

#LineLine coverage
 1//
 2//  Copyright 2010  Ekon Benefits
 3//
 4//    Licensed under the Apache License, Version 2.0 (the "License");
 5//    you may not use this file except in compliance with the License.
 6//    You may obtain a copy of the License at
 7//
 8//        http://www.apache.org/licenses/LICENSE-2.0
 9//
 10//    Unless required by applicable law or agreed to in writing, software
 11//    distributed under the License is distributed on an "AS IS" BASIS,
 12//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13//    See the License for the specific language governing permissions and
 14//    limitations under the License.
 15
 16using System;
 17using System.Collections.Generic;
 18using System.Linq;
 19using System.Reflection;
 20using System.Text;
 21
 22namespace ImpromptuInterface.Build
 23{
 24    /// <summary>
 25    /// Type that Encompasses Hashing a group of Types in various ways
 26    /// </summary>
 27    public class TypeHash
 28    {
 29        /// <summary>
 30        /// Equalses the specified other.
 31        /// </summary>
 32        /// <param name="other">The other.</param>
 33        /// <returns></returns>
 34        public bool Equals(TypeHash other)
 35        {
 112236            if (ReferenceEquals(null, other)) return false;
 112037            if (ReferenceEquals(this, other)) return true;
 38
 112039            if (InformalInterface != null || other.InformalInterface !=null)
 40            {
 341                if (InformalInterface == null || other.InformalInterface == null)
 142                    return false;
 43
 244                if (Types.Length != other.Types.Length)
 045                    return false;
 46
 247                var tTypes = Types.SequenceEqual(other.Types);
 48
 249                if (!tTypes )
 050                    return false;
 51
 252                return InformalInterface.SequenceEqual(other.InformalInterface);
 53            }
 54
 55
 111756            return Types.SequenceEqual(other.Types);
 57        }
 58
 59        /// <summary>
 60        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
 61        /// </summary>
 62        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
 63        /// <returns>
 64        ///   <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c
 65        /// </returns>
 66        public override bool Equals(object obj)
 67        {
 119468            if (ReferenceEquals(null, obj)) return false;
 126769            if (ReferenceEquals(this, obj)) return true;
 112270            if (obj.GetType() != typeof(TypeHash)) return false;
 112071            return Equals((TypeHash)obj);
 72        }
 73
 74        /// <summary>
 75        /// Returns a hash code for this instance.
 76        /// </summary>
 77        /// <returns>
 78        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
 79        /// </returns>
 80        public override int GetHashCode()
 81        {
 82            unchecked
 83            {
 84
 215285                if (Types.Length > 16)
 86                {
 087                    return Types.Length.GetHashCode();
 88                }
 89
 90
 215291                var tReturn = Types.Aggregate(1, (current, type) => (current * 397) ^ type.GetHashCode());
 92
 215293                if (InformalInterface != null)
 94                {
 695                    tReturn = InformalInterface.Aggregate(tReturn, (current, type) => (current * 397) ^ type.GetHashCode
 96                }
 215297                return tReturn;
 98            }
 99        }
 100
 101        /// <summary>
 102        /// Implements the operator ==.
 103        /// </summary>
 104        /// <param name="left">The left.</param>
 105        /// <param name="right">The right.</param>
 106        /// <returns>The result of the operator.</returns>
 107        public static bool operator ==(TypeHash left, TypeHash right)
 108        {
 1109            return Equals(left, right);
 110        }
 111
 112        /// <summary>
 113        /// Implements the operator !=.
 114        /// </summary>
 115        /// <param name="left">The left.</param>
 116        /// <param name="right">The right.</param>
 117        /// <returns>The result of the operator.</returns>
 118        public static bool operator !=(TypeHash left, TypeHash right)
 119        {
 2120            return !Equals(left, right);
 121        }
 122
 123        /// <summary>
 124        /// Types to be hashed
 125        /// </summary>
 126        public readonly MemberInfo[] Types;
 127
 128        /// <summary>
 129        /// The Informal Interface to be hashed
 130        /// </summary>
 131        public readonly IDictionary<string,Type> InformalInterface;
 132
 133        /// <summary>
 134        /// Initializes a new instance of the <see cref="TypeHash"/> class.
 135        /// </summary>
 136        /// <param name="moreTypes">The more types.</param>
 137        [Obsolete("Use TypeHash.Create instead.")]
 138        public TypeHash(IEnumerable<Type> moreTypes)
 6139            :this(false,moreTypes.ToArray())
 140        {
 141
 6142        }
 143
 1549144        private TypeHash()
 145        {
 146
 1549147        }
 148
 149        /// <summary>
 150        /// Initializes a new instance of the <see cref="TypeHash"/> class.
 151        /// For use when you have must distinguish one type; and the rest aren't strict
 152        /// </summary>
 153        /// <param name="type1">The type1.</param>
 154        /// <param name="moreTypes">The more types.</param>
 155        [Obsolete("Use TypeHash.Create instead.")]
 156        public TypeHash(Type type1, params Type[] moreTypes)
 127157            :this()
 158        {
 127159            Types = new[] { type1 }.Concat(moreTypes.OrderBy(it => it.Name)).ToArray();
 127160            InformalInterface = null;
 127161        }
 162
 163
 164
 165        /// <summary>
 166        /// Initializes a new instance of the <see cref="TypeHash"/> class.
 167        /// </summary>
 168        /// <param name="type1">The type1.</param>
 169        /// <param name="informalInterface">The informal interface.</param>
 170        [Obsolete("Use TypeHash.Create instead.")]
 171        public TypeHash(Type type1, IDictionary<string, Type> informalInterface)
 5172            : this()
 173        {
 5174            Types = new[] {type1};
 5175            InformalInterface = informalInterface;
 5176        }
 177
 178        /// <summary>
 179        /// Initializes a new instance of the <see cref="TypeHash"/> class.
 180        /// </summary>
 181        /// <param name="strictOrder">if set to <c>true</c> [strict order].</param>
 182        /// <param name="moreTypes">types.</param>
 183        [Obsolete("Use TypeHash.Create instead.")]
 1417184        public TypeHash(bool strictOrder, params MemberInfo[] moreTypes):this()
 185        {
 1417186            Types = strictOrder
 1417187                ? moreTypes
 1417188                : moreTypes.OrderBy(it => it.Name).ToArray();
 1417189        }
 190
 191        /// <summary>
 192        /// Creates the TypeHash
 193        /// </summary>
 194        /// <param name="moreTypes">The more types.</param>
 195        /// <returns></returns>
 196        public static TypeHash Create(IEnumerable<Type> moreTypes)
 197        {
 198#pragma warning disable 612,618
 6199            return new TypeHash(moreTypes);
 200#pragma warning restore 612,618
 201        }
 202        /// <summary>
 203        /// Creates the TypeHash
 204        /// </summary>
 205        /// <param name="type1">The type1.</param>
 206        /// <param name="moreTypes">The more types.</param>
 207        /// <returns></returns>
 208        public static TypeHash Create(Type type1, params Type[] moreTypes)
 209        {
 210#pragma warning disable 612,618
 127211            return new TypeHash(type1, moreTypes);
 212#pragma warning restore 612,618
 213        }
 214        /// <summary>
 215        /// Creates the TypeHash
 216        /// </summary>
 217        /// <param name="type1">The type1.</param>
 218        /// <param name="informalInterface">The informal interface.</param>
 219        /// <returns></returns>
 220        public static TypeHash Create(Type type1, IDictionary<string, Type> informalInterface)
 221        {
 222#pragma warning disable 612,618
 5223            return new TypeHash(type1, informalInterface);
 224#pragma warning restore 612,618
 225        }
 226        /// <summary>
 227        /// Creates the TypeHash
 228        /// </summary>
 229        /// <param name="strictOrder">if set to <c>true</c> [strict order].</param>
 230        /// <param name="moreTypes">The more types.</param>
 231        /// <returns></returns>
 232        public static TypeHash Create(bool strictOrder, params MemberInfo[] moreTypes)
 233        {
 234#pragma warning disable 612,618
 1411235            return new TypeHash(strictOrder, moreTypes);
 236#pragma warning restore 612,618
 237        }
 238    }
 239}