<commit_before>﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace Ploeh.AutoFixture.Kernel
{
    /// <summary>
    /// A specification that determines whether the request is a request
    /// for a <see cref="PropertyInfo"/> matching the specified name and <see cref="Type"/>.
    /// </summary>
    public class PropertySpecification : IRequestSpecification
    {
        private readonly Type targetType;
        private readonly string targetName;
        private readonly IEqualityComparer<string> nameComparison;

        /// <summary>
        /// Initializes a new instance of the <see cref="PropertySpecification"/> class.
        /// </summary>
        /// <param name="targetType">
        /// The <see cref="Type"/> with which the requested
        /// <see cref="PropertyInfo"/> type should be compatible.
        /// </param>
        /// <param name="targetName">
        /// The name which the requested <see cref="PropertyInfo"/> name
        /// should match exactly.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="targetType"/> or
        /// <paramref name="targetName"/> is <see langword="null"/>.
        /// </exception>
        public PropertySpecification(Type targetType, string targetName)
            : this(targetType, targetName, StringComparer.Ordinal)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PropertySpecification"/> class.
        /// </summary>
        /// <param name="targetType">
        /// The <see cref="Type"/> with which the requested
        /// <see cref="PropertyInfo"/> type should be compatible.
        /// </param>
        /// <param name="targetName">
        /// The name which the requested <see cref="PropertyInfo"/> name
        /// should match according to the specified
        /// <paramref name="nameComparison"/> criteria.
        /// </param>
        /// <param name="nameComparison">
        /// The criteria used to match the requested
        /// <see cref="PropertyInfo"/> name with the specified
        /// <paramref name="targetName"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="targetType"/> or
        /// <paramref name="targetName"/> or
        /// <paramref name="nameComparison"/> is <see langword="null"/>.
        /// </exception>
        public PropertySpecification(
            Type targetType,
            string targetName,
            IEqualityComparer<string> nameComparison)
        {
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }

            if (targetName == null)
            {
                throw new ArgumentNullException("targetName");
            }

            if (nameComparison == null)
            {
                throw new ArgumentNullException("nameComparison");
            }

            this.targetType = targetType;
            this.targetName = targetName;
            this.nameComparison = nameComparison;
        }

        /// <summary>
        /// The <see cref="Type"/> with which the requested
        /// <see cref="PropertyInfo"/> type should be compatible.
        /// </summary>
        public Type TargetType
        {
            get { return this.targetType; }
        }

        /// <summary>
        /// The name which the requested <see cref="PropertyInfo"/> name
        /// should match exactly.
        /// </summary>
        public string TargetName
        {
            get { return this.targetName; }
        }

        /// <summary>
        /// Evaluates a request for a specimen.
        /// </summary>
        /// <param name="request">The specimen request.</param>
        /// <returns>
        /// <see langword="true"/> if <paramref name="request"/> is satisfied by the Specification;
        /// otherwise, <see langword="false"/>.
        /// </returns>
        public bool IsSatisfiedBy(object request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            return IsRequestForProperty(request) &&
                   PropertyIsCompatibleWithTargetType(request) &&
                   PropertyMatchesTargetName(request);
        }

        private static bool IsRequestForProperty(object request)
        {
            return request is PropertyInfo;
        }

        private bool PropertyIsCompatibleWithTargetType(object request)
        {
            return ((PropertyInfo)request)
                   .PropertyType
                   .IsAssignableFrom(this.targetType);
        }

        private bool PropertyMatchesTargetName(object request)
        {
            return this.nameComparison.Equals(
                ((PropertyInfo)request).Name,
                this.targetName);
        }
    }
}<commit_msg>Changed type of comparer to compare PropertyInfos.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace Ploeh.AutoFixture.Kernel
{
    /// <summary>
    /// A specification that determines whether the request is a request
    /// for a <see cref="PropertyInfo"/> matching the specified name and <see cref="Type"/>.
    /// </summary>
    public class PropertySpecification : IRequestSpecification
    {
        private readonly Type targetType;
        private readonly string targetName;

        /// <summary>
        /// Initializes a new instance of the <see cref="PropertySpecification"/> class.
        /// </summary>
        /// <param name="targetType">
        /// The <see cref="Type"/> with which the requested
        /// <see cref="PropertyInfo"/> type should be compatible.
        /// </param>
        /// <param name="targetName">
        /// The name which the requested <see cref="PropertyInfo"/> name
        /// should match exactly.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="targetType"/> or
        /// <paramref name="targetName"/> is <see langword="null"/>.
        /// </exception>
        public PropertySpecification(Type targetType, string targetName)
            : this(targetType, targetName, new FalseComparer())
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PropertySpecification"/> class.
        /// </summary>
        /// <param name="targetType">
        /// The <see cref="Type"/> with which the requested
        /// <see cref="PropertyInfo"/> type should be compatible.
        /// </param>
        /// <param name="targetName">
        /// The name which the requested <see cref="PropertyInfo"/> name
        /// should match according to the specified
        /// <paramref name="propertyComparer"/> criteria.
        /// </param>
        /// <param name="propertyComparer">
        /// The criteria used to match the requested
        /// <see cref="PropertyInfo"/> name with the specified
        /// <paramref name="targetName"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="targetType"/> or
        /// <paramref name="targetName"/> or
        /// <paramref name="propertyComparer"/> is <see langword="null"/>.
        /// </exception>
        public PropertySpecification(
            Type targetType,
            string targetName,
            IEqualityComparer<PropertyInfo> propertyComparer)
        {
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }

            if (targetName == null)
            {
                throw new ArgumentNullException("targetName");
            }

            if (propertyComparer == null)
            {
                throw new ArgumentNullException("propertyComparer");
            }

            this.targetType = targetType;
            this.targetName = targetName;
        }

        /// <summary>
        /// The <see cref="Type"/> with which the requested
        /// <see cref="PropertyInfo"/> type should be compatible.
        /// </summary>
        public Type TargetType
        {
            get { return this.targetType; }
        }

        /// <summary>
        /// The name which the requested <see cref="PropertyInfo"/> name
        /// should match exactly.
        /// </summary>
        public string TargetName
        {
            get { return this.targetName; }
        }

        /// <summary>
        /// Evaluates a request for a specimen.
        /// </summary>
        /// <param name="request">The specimen request.</param>
        /// <returns>
        /// <see langword="true"/> if <paramref name="request"/> is satisfied by the Specification;
        /// otherwise, <see langword="false"/>.
        /// </returns>
        public bool IsSatisfiedBy(object request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            return IsRequestForProperty(request) &&
                   PropertyIsCompatibleWithTargetType(request) &&
                   PropertyMatchesTargetName(request);
        }

        private static bool IsRequestForProperty(object request)
        {
            return request is PropertyInfo;
        }

        private bool PropertyIsCompatibleWithTargetType(object request)
        {
            return ((PropertyInfo)request)
                   .PropertyType
                   .IsAssignableFrom(this.targetType);
        }

        private bool PropertyMatchesTargetName(object request)
        {
            return ((PropertyInfo)request).Name == this.targetName;
        }

        private class FalseComparer : IEqualityComparer<PropertyInfo>
        {
            public bool Equals(PropertyInfo x, PropertyInfo y)
            {
                return false;
            }

            public int GetHashCode(PropertyInfo obj)
            {
                return 0;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.12007560684440907, 'fraction_numerical': 9.948269001193792e-05, 'mean_word_length': 1.6858135185679937, 'pattern_counts': {'":': 0, '<': 119, '<?xml version=': 0, '>': 119, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3862640', 'n_tokens_mistral': 2390, 'n_tokens_neox': 2331, 'n_words': 666}