コード例 #1
0
        /// <summary>
        /// Returns a custom comparer with specified options
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        /// <exception cref="NotSupportedException"></exception>
        public static ILEqualityComparer <T> Create(ILEqualityComparerOptions <T> options) // move all logic to generator
        {
            PropertyInfo[] properties;
            FieldInfo[]    fields;

            var memberExpressions = options.MemberExpressions;

            if (options.EqualityGenerationPreference == EqualityGenerationPreference.IgnoreMemberExpressions)
            {
                properties = typeof(T).GetProperties();
                fields     = typeof(T).GetFields();
                if (memberExpressions.Length != 0)
                {
                    properties = properties.Except(memberExpressions.Select(me => me.Member).OfType <PropertyInfo>()).ToArray();
                    fields     = fields.Except(memberExpressions.Select(me => me.Member).OfType <FieldInfo>()).ToArray();
                }
            }
            else
            {
                properties = memberExpressions.Select(e => e.Member).OfType <PropertyInfo>().ToArray();
                fields     = memberExpressions.Select(e => e.Member).OfType <FieldInfo>().ToArray();
            }

            var eq  = ILEqualityComparerGenerator.GenerateEqualsFunc <T>(properties, fields);
            var ghc = ILEqualityComparerGenerator.GenerateGetHashCodeFunc <T>(properties, fields);

            return(new ILEqualityComparer <T>(eq, ghc));
        }
コード例 #2
0
 private ILEqualityComparer(PropertyInfo[] properties, FieldInfo[] fields) :
     this(ILEqualityComparerGenerator.GenerateEqualsFunc <T>(properties, fields), ILEqualityComparerGenerator.GenerateGetHashCodeFunc <T>(properties, fields))
 {
 }
コード例 #3
0
 private ILEqualityComparer(bool includePrivateMembers) :
     this(ILEqualityComparerGenerator.GenerateEqualsFunc <T>(includePrivateMembers), ILEqualityComparerGenerator.GenerateGetHashCodeFunc <T>(includePrivateMembers))
 {
 }