public SingleUnityUnitConversionMap(IUnit unit, IEqualityComparer<IUnit> unitEqualityComparer = null)
     : base(unitEqualityComparer)
 {
     if (null == unit) throw new ArgumentNullException("unit");
     Contract.EndContractBlock();
     _singleUnit = unit;
 }
 public NotEqualValidator(object comparisonValue, IEqualityComparer equalityComparer)
     : base(() => Messages.notequal_error)
 {
     ValueToCompare = comparisonValue;
     comparer = equalityComparer;
     SupportsStandaloneValidation = true;
 }
 public NotEqualValidator(PropertySelector func, MemberInfo memberToCompare, IEqualityComparer equalityComparer)
     : base(() => Messages.notequal_error)
 {
     this.func = func;
     this.comparer = equalityComparer;
     MemberToCompare = memberToCompare;
 }
Example #4
0
 public NotEqualValidator(Func<object, object> func, MemberInfo memberToCompare, IEqualityComparer equalityComparer)
     : base(() => Messages.notequal_error, ValidationErrors.NotEqual)
 {
     this.func = func;
     this.comparer = equalityComparer;
     MemberToCompare = memberToCompare;
 }
        public MappedHtmlNodeToReferenceNode(MappedHtmlNode parent, HtmlNode htmlNode, HtmlNode referenceNode, IEqualityComparer<HtmlNode> comparer, PropertyNameState propertyNameState)
            : base(parent)
        {
            if (htmlNode == null)
            {
                throw new ArgumentNullException("htmlNode");
            }

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

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

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

            this.htmlNode = htmlNode;
            this.referenceNode = referenceNode;
            this.comparer = comparer;
            this.propertyNameState = propertyNameState;

            base.children = MapChildren();


        }
        public BackgroundDownloader(IBackgroundTransferStorage storage, IBackgroundTransferConfig config)
        {
            _storage = storage;
            _config = config;

            _urlEquator = new FuncEqualityComparer<Uri>((url1, url2) => url1 == url2, url => url.GetHashCode());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EqualToEntityPropertyValidator"/> class.
        /// </summary>
        /// <param name="memberToCompareFunc">The member to compare function.</param>
        /// <param name="member">The member.</param>
        /// <param name="ownerType">The owner type.</param>
        /// <param name="confirmProperty">if set to <c>true</c> [confirm property].</param>
        /// <param name="comparer">The comparer.</param>
        /// <exception cref="System.ArgumentNullException">
        /// memberToCompareFunc
        /// or
        /// member
        /// or
        /// ownerType
        /// </exception>
        public EqualToEntityPropertyValidator(Func<object, object> memberToCompareFunc, MemberInfo member, Type ownerType, bool confirmProperty = true, IEqualityComparer comparer = null)
        {
            if (memberToCompareFunc == null)
            {
                throw new ArgumentNullException("memberToCompareFunc");
            }

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

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

            OwnerType = ownerType;
            m_MemberToCompareFunc = memberToCompareFunc;
            m_MemberToCompareMemberInfo = member;
            m_ConfirmProperty = confirmProperty;
            m_Comparer = comparer;
            m_ValidatorProperties = new ValidatorProperties
                                        {
                                            { Constants.ValidationMessageParameterNames.MEMBER_TO_COMPARE_MEMBER_INFO, m_MemberToCompareMemberInfo },
                                            { Constants.ValidationMessageParameterNames.OWNER_TYPE, ownerType }
                                        };
        }
Example #8
0
 public static bool EvaluateQuery(ArrayList<string> text, ArrayList<QueryToken> queryPlan, out bool result, IEqualityComparer<string> tokenComparer)
 {
     result = false;
     Stack<bool> stack = new Stack<bool>();
     foreach (QueryToken token in queryPlan)
     {
         bool b;
         switch (GetTokenType(token))
         {
             case TokenType.Term:
                 stack.Push(Contains(token, text, tokenComparer));
                 break;
             case TokenType.Operator: // AND/OR
                 if (stack.Count <= 1) { return false; }
                 bool b1 = stack.Pop();
                 bool b2 = stack.Pop();
                 b = b1 && b2;
                 if (token == "OR") { b = b1 || b2; }
                 stack.Push(b);
                 break;
             case TokenType.Function: // NOT
                 if (stack.Count == 0) { return false; }
                 b = stack.Pop();
                 stack.Push(!b);
                 break;
         }
     }
     if (stack.Count != 1) { return false; }
     result = stack.Pop();
     return true;
 }
        public DynamicEntity(MissingMemberBehavior missingMemberBehavior,
			IDynamicEntityConverter converter = null, IEqualityComparer<string> comparer = null)
        {
            _missingMemberBehavior = missingMemberBehavior;
            _dataDictionary = new Dictionary<string, object>(comparer ?? StringComparer.InvariantCultureIgnoreCase);
            _converter = converter ?? new NullConverter();
        }
 public EqualValidator(object valueToCompare, IEqualityComparer comparer)
     : base(() => Messages.equal_error)
 {
     ValueToCompare = valueToCompare;
     this.comparer = comparer;
     SupportsStandaloneValidation = true;
 }
Example #11
0
 public MarshalContext(IEqualityComparer equalityComparer)
 {
     stackMap = new Hashtable(equalityComparer);
     useRepository = false;
     caseSensitive = true;
     AddConverters();
 }
 public EqualValidator(PropertySelector comparisonProperty, MemberInfo member, IEqualityComparer comparer)
     : base(() => Messages.equal_error)
 {
     func = comparisonProperty;
     MemberToCompare = member;
     this.comparer = comparer;
 }
 public EqualValidator(Func<object, object> comparisonProperty, MemberInfo member, IEqualityComparer comparer)
     : base(() => Messages.equal_error, ValidationErrors.Equal)
 {
     func = comparisonProperty;
     MemberToCompare = member;
     this.comparer = comparer;
 }
		public OrderedDictionary (int capacity, IEqualityComparer equalityComparer)
		{
			initialCapacity = (capacity < 0) ? 0 : capacity;
			list = new ArrayList (initialCapacity);
			hash = new Hashtable (initialCapacity, equalityComparer);
			comparer = equalityComparer;
		}
Example #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MemberComparer"/> 
 /// class with the supplied <see cref="IEqualityComparer"/> to support
 /// the comparison of properties and fields.
 /// </summary>
 /// <param name="comparer">
 /// The supplied <see cref="IEqualityComparer"/>.
 /// </param>
 public MemberComparer(IEqualityComparer comparer)
     : this(
         comparer,
         new TrueSpecification<PropertyInfo>(),
         new TrueSpecification<FieldInfo>())
 {
 }
 public BinaryUnitConversionMap(IUnitConversion<double> forwardOperation, IEqualityComparer<IUnit> unitEqualityComparer = null)
     : base(unitEqualityComparer)
 {
     if (null == forwardOperation) throw new ArgumentNullException("forwardOperation");
     Contract.EndContractBlock();
     _forwardOperation = forwardOperation;
 }
        public static bool ContainsClaim(this IEnumerable<ClaimSet> claimSets, Claim searchClaim, Claim issuerIdentityClaim, ClaimSearchMode searchMode, IEqualityComparer<Claim> comparer)
        {
            IEnumerable<ClaimSet> searchSet =
                GetClaimSetsCore(claimSets, issuerIdentityClaim, searchMode);

            foreach (ClaimSet set in searchSet)
            {
                bool found = false;
                if (comparer != null)
                {
                    found = set.ContainsClaim(searchClaim, comparer);
                }
                else
                {
                    found = set.ContainsClaim(searchClaim);
                }

                if (found)
                {
                    return true;
                }
            }

            return false;
        }
Example #18
0
 public MatchResult TryMatch(string s, IEqualityComparer<string> comparer)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     if (disposed)
     {
         throw new ObjectDisposedException(GetType().FullName);
     }
     if (s.Length == 0)
     {
         return MatchResult.FromMatch(string.Empty, s);
     }
     var buffer = new char[s.Length];
     var len = textSource.ReadBlock(buffer, 0, buffer.Length);
     var next = new string(buffer, 0, len);
     if (len == 0)
     {
         endOfInput = true;
         return MatchResult.FromEndOfInput(s);
     }
     if (!comparer.Equals(s, next))
     {
         textSource.Unread(buffer, 0, len);
         return MatchResult.FromMismatch(next, s);
     }
     Interlocked.Add(ref offset, len);
     return MatchResult.FromMatch(next, s);
 }
Example #19
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SectionData"/> class
        ///     from a previous instance of <see cref="SectionData"/>.
        /// </summary>
        /// <remarks>
        ///     Data is deeply copied
        /// </remarks>
        /// <param name="ori">
        ///     The instance of the <see cref="SectionData"/> class 
        ///     used to create the new instance.
        /// </param>
        /// <param name="searchComparer">
        ///     Search comparer.
        /// </param>
        public SectionData(SectionData ori, IEqualityComparer<string> searchComparer = null)
        {
            SectionName = ori.SectionName;

            _searchComparer = searchComparer;
            _leadingComments = new List<string>(ori._leadingComments);
            _keyDataCollection = new KeyDataCollection(ori._keyDataCollection, searchComparer ?? ori._searchComparer);
        }
Example #20
0
        public ChangeGraphBuilder(IEqualityComparer<IFileReference> fileReferenceComparer)
        {
            if(fileReferenceComparer == null)
                throw new ArgumentNullException(nameof(fileReferenceComparer));
            

            m_FileReferenceComparer = fileReferenceComparer;        
        }
Example #21
0
 public void Int(IEnumerable<int> first, IEnumerable<int> second, IEqualityComparer<int> comparer, IEnumerable<int> expected)
 {
     if (comparer == null)
     {
         Assert.Equal(expected, first.Except(second));
     }
     Assert.Equal(expected, first.Except(second, comparer));
 }
Example #22
0
 public static void Ctor(Dictionary<int, string> aThis, int capacity, IEqualityComparer<int> comparer)
 {
     if (capacity != 0)
     {
         throw new Exception("Capacity != 0 not supported yet!");
     }
     
 }
Example #23
0
 /// <summary>
 /// Initializes a new instance of a Dimension, that uses the given comparer
 /// to compare values.
 /// </summary>
 /// <param name="comparer">The equality comparer to use.</param>
 public Dimension(IEqualityComparer comparer)
 {
     if (comparer == null)
     {
         throw new ArgumentNullException("comparer");
     }
     this.comparer = comparer;
 }
Example #24
0
 public void StringRunOnce(IEnumerable<string> source, IEqualityComparer<string> comparer, string value, bool expected)
 {
     if (comparer == null)
     {
         Assert.Equal(expected, source.RunOnce().Contains(value));
     }
     Assert.Equal(expected, source.RunOnce().Contains(value, comparer));
 }
Example #25
0
 public SyncActionFactory(IEqualityComparer<IFileReference> fileReferenceComparer)
 {
     if (fileReferenceComparer == null)
     {
         throw new ArgumentNullException(nameof(fileReferenceComparer));
     }
     m_FileReferenceComparer = fileReferenceComparer;
 }
 public MotherNature(IEnumerable<IBe> initialPopulation, DarwinBase darwin, IGod god, IRandomOperations randomOperation, IEqualityComparer<IBe> comparer)
 {
     this.darwin = darwin;
     population = initialPopulation;
     this.god = god;
     this.randomOperation = randomOperation;
     this.comparer = comparer;
 }
Example #27
0
        protected void Initialize(Claim identityClaim, IEqualityComparer<Claim> claimComparer)
        {
            if (identityClaim == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("identityClaim");

            _identityClaim = identityClaim;
            _claimComparer = claimComparer;
        }
Example #28
0
 public void String(IEnumerable<string> first, IEnumerable<string> second, IEqualityComparer<string> comparer, string[] expected)
 {
     if (comparer == null)
     {
         Assert.Equal(expected, first.Intersect(second));
     }
     Assert.Equal(expected, first.Intersect(second, comparer));
 }
        static ResourceMapManager()
        {
            entryComparer = new ResourceEntryComparer();
            mappingCache = new Dictionary<int, ResourceMapping>();
            mapKeyCache = new Dictionary<ResourceMappingEntry, List<int>>();

            Refresh();
        }
		public LocalizationDictionary(IEqualityComparer<string> comparer) {
      Includes = new List<Include>();
			this.comparer = comparer;
			keys = new List<string>();
			localesHash = new HashSet<string>(comparer);
			keysHash = new HashSet<string>(comparer);
			dictionaries = new Dictionary<string, Dictionary<string, string>>(comparer);
		}
 public ObservableDictionary(int capacity, IEqualityComparer <TKey> comparer)
 {
     InternalDictionary = new Dictionary <TKey, TValue>(capacity, comparer);
 }
Example #32
0
        /// <summary>
        /// Run-length encodes a sequence by converting consecutive instances of the same element into
        /// a <c>KeyValuePair{T,int}</c> representing the item and its occurrence count. This overload
        /// uses a custom equality comparer to identify equivalent items.
        /// </summary>
        /// <typeparam name="T">The type of the elements in the sequence</typeparam>
        /// <param name="sequence">The sequence to run length encode</param>
        /// <param name="comparer">The comparer used to identify equivalent items</param>
        /// <returns>A sequence of <c>KeyValuePair{T,int}</c> where they key is the element and the value is the occurrence count</returns>

        public static IEnumerable <KeyValuePair <T, int> > RunLengthEncode <T>(this IEnumerable <T> sequence, IEqualityComparer <T> comparer)
        {
            if (sequence == null)
            {
                throw new ArgumentNullException(nameof(sequence));
            }

            return(_(comparer ?? EqualityComparer <T> .Default));

            IEnumerable <KeyValuePair <T, int> > _(IEqualityComparer <T> localComparer)
            {
                // This implementation could also have been written using a foreach loop,
                // but it proved to be easier to deal with edge certain cases that occur
                // (such as empty sequences) using an explicit iterator and a while loop.

                var iter = sequence.GetEnumerator();

                if (iter.MoveNext())
                {
                    var prevItem = iter.Current;
                    var runCount = 1;

                    while (iter.MoveNext())
                    {
                        if (localComparer.Equals(prevItem, iter.Current))
                        {
                            ++runCount;
                        }
                        else
                        {
                            yield return(new KeyValuePair <T, int>(prevItem, runCount));

                            prevItem = iter.Current;
                            runCount = 1;
                        }
                    }

                    yield return(new KeyValuePair <T, int>(prevItem, runCount));
                }
            }
        }
Example #33
0
 public static IEqualityComparer <T> CreateComparer <V>(Func <T, V> keySelector, IEqualityComparer <V> comparer)
 {
     return(new CtkCommonEqualityComparer <V>(keySelector, comparer));
 }
 private void HandleChanging(IInvocation invocation, IPropertyBase property, IEqualityComparer comparer)
 {
     if (_checkEquality)
     {
         var oldValue = property.GetGetter().GetClrValue(invocation.Proxy);
         var newValue = invocation.Arguments[^ 1];
Example #35
0
 public static IQueryable <TSource> UnionIf <TSource>(this IQueryable <TSource> first, bool condition, IQueryable <TSource> second, IEqualityComparer <TSource> comparer)
 => condition?first.Union(second, comparer) : first;
Example #36
0
 public SlimHashTable(Func <TValue, TKey> keyProvider, IEqualityComparer <TKey> comparer, ICollectionGrowthPolicy growthPolicy)
     : this(keyProvider, 0, comparer, growthPolicy)
 {
 }
Example #37
0
        public static IAsyncEnumerable <TSource> Distinct <TSource, TKey>(this IAsyncEnumerable <TSource> source, Func <TSource, TKey> keySelector, IEqualityComparer <TKey> comparer)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (keySelector == null)
            {
                throw new ArgumentNullException(nameof(keySelector));
            }
            if (comparer == null)
            {
                throw new ArgumentNullException(nameof(comparer));
            }

            return(new DistinctAsyncIterator <TSource, TKey>(source, keySelector, comparer));
        }
Example #38
0
 private static IAsyncEnumerable <TSource> DistinctUntilChanged_ <TSource, TKey>(this IAsyncEnumerable <TSource> source, Func <TSource, TKey> keySelector, IEqualityComparer <TKey> comparer)
 {
     return(new DistinctUntilChangedAsyncIterator <TSource, TKey>(source, keySelector, comparer));
 }
Example #39
0
 public CtkCommonEqualityComparer(Func <T, V> keySelector, IEqualityComparer <V> comparer)
 {
     this.keySelector = keySelector;
     this.comparer    = comparer;
 }
Example #40
0
 public ConcurrentSet(IEqualityComparer <T> comparer)
 {
     _inner = new ConcurrentDictionary <T, object>(comparer);
 }
 public MultiSetComparer(IEqualityComparer <T>?comparer = null)
 {
     _comparer = comparer ?? EqualityComparer <T> .Default;
 }
Example #42
0
 public StringArrayComparer(IEqualityComparer <string> comparer)
 {
     _comparer = comparer;
 }
Example #43
0
        private static IEnumerable <TSource> ExceptImpl <TSource>(this IEnumerable <TSource> first, IEnumerable <TSource> second, IEqualityComparer <TSource> comparer)
        {
            HashSet <TSource> set = new HashSet <TSource>(second, comparer);

            foreach (var f in first)
            {
                //if (!set.Remove(f)) //It will not return distinct values from first
                if (set.Add(f))
                {
                    yield return(f);
                }
            }
        }
Example #44
0
 /// <summary>
 /// Initializes a new instance of the System.Collections.Generic.HashSet<T> class
 /// that is empty and uses the specified equality comparer for the set type.
 /// </summary>
 /// <param name="comparer">
 /// The System.Collections.Generic.IEqualityComparer<T> implementation to use
 /// when comparing values in the set, or null to use the default System.Collections.Generic.EqualityComparer<T>
 /// implementation for the set type.
 /// </param>
 public HashSet(IEqualityComparer <T> comparer)
 {
     this.dict = new Dictionary <T, object>(comparer);
 }
Example #45
0
        public static IEnumerable <TSource> Except <TSource>(this IEnumerable <TSource> first, IEnumerable <TSource> second, IEqualityComparer <TSource> comparer)
        {
            if (first == null)
            {
                throw new ArgumentNullException("first");
            }

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

            return(ExceptImpl(first, second, comparer));
        }
Example #46
0
 public ToDictionary(Func <TSource, TKey> keySelector, Func <TSource, TElement> elementSelector, IEqualityComparer <TKey> comparer)
     : base(new Dictionary <TKey, TElement>(comparer)) => (_keySelector, _elementSelector) = (keySelector, elementSelector);
Example #47
0
 public StringArrayComparer()
 {
     _comparer = StringComparer.Ordinal;
 }
Example #48
0
 public RecentDictionary(int capacity, IEqualityComparer <K> comparer)
 {
     this.capacity = capacity;
     keyToLink     = new Dictionary <K, LinkedListNode <V> >(comparer);
 }
Example #49
0
        private static bool DictionaryEqual <TKey, TValue>(IDictionary <TKey, TValue> dict1, IDictionary <TKey, TValue> dict2, IEqualityComparer <TValue> equalityComparer = null)
        {
            if (Equals(dict1, dict2))
            {
                return(true);
            }

            if (dict1 == null || dict2 == null || dict1.Count != dict2.Count)
            {
                return(false);
            }

            if (equalityComparer == null)
            {
                equalityComparer = EqualityComparer <TValue> .Default;
            }

            return(dict1.All(pair =>
            {
                return dict2.TryGetValue(pair.Key, out TValue val) && equalityComparer.Equals(pair.Value, val);
            }));
        }
Example #50
0
 public HashSet(IEqualityComparer <T> comparer)
 {
     items = new Dictionary <T, object?>(comparer);
 }
Example #51
0
        public PersistenceSpecification <T> RegisterCheckedProperty(Property <T> property, IEqualityComparer equalityComparer)
        {
            property.EntityEqualityComparer = equalityComparer ?? entityEqualityComparer;
            allProperties.Add(property);

            property.HasRegistered(this);

            return(this);
        }
Example #52
0
 public static bool EqualsAny <T>(this T @this, IEqualityComparer <T> comparer, params T[] others)
 {
     return(others.Contains(@this, comparer));
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="comparer">comparer to ensure the equality of 2 values</param>
 public MemoryCacheBucket(IEqualityComparer <TValue> comparer)
 {
     _comparer = comparer;
 }
Example #54
0
 public static IQueryable <TSource> DistinctIf <TSource>(this IQueryable <TSource> source, bool condition, IEqualityComparer <TSource> comparer)
 => condition?source.Distinct(comparer) : source;
Example #55
0
 public PersistenceSpecification(ISession session, IEqualityComparer entityEqualityComparer)
 {
     currentSession              = session;
     hasExistingSession          = currentSession.Transaction != null && currentSession.Transaction.IsActive;
     this.entityEqualityComparer = entityEqualityComparer;
 }
 public DictionaryDisposable(IEqualityComparer <TKey> comparer)
 {
     inner = new Dictionary <TKey, TValue>(comparer);
 }
Example #57
0
 public PersistenceSpecification(ISessionSource source, IEqualityComparer entityEqualityComparer)
     : this(source.CreateSession(), entityEqualityComparer)
 {
 }
Example #58
0
        /// <summary>
        /// Compares two enumberables for equality, ordered according to the specified key and optional comparer. Handles null values gracefully.
        /// </summary>
        /// <typeparam name="TSource">The type of the list</typeparam>
        /// <typeparam name="TKey">The type of the sorting key</typeparam>
        /// <param name="self">This list</param>
        /// <param name="other">The other list</param>
        /// <param name="keySelector">The function to extract the key from each item in the list</param>
        /// <param name="orderComparer">An optional comparer for comparing keys</param>
        /// <param name="sequenceComparer">An optional comparer for sequences</param>
        internal static bool OrderedEquals <TSource, TKey>(this IEnumerable <TSource> self, IEnumerable <TSource> other, Func <TSource, TKey> keySelector, IComparer <TKey> orderComparer = null, IEqualityComparer <TSource> sequenceComparer = null)
        {
            Debug.Assert(orderComparer != null || typeof(TKey) != typeof(string), "Argument " + "orderComparer" + " must be provided if " + "TKey" + " is a string.");
            Debug.Assert(sequenceComparer != null || typeof(TSource) != typeof(string), "Argument " + "sequenceComparer" + " must be provided if " + "TSource" + " is a string.");

            if (ReferenceEquals(self, other))
            {
                return(true);
            }

            if (self == null || other == null)
            {
                return(false);
            }

            return(self.OrderBy(keySelector, orderComparer).SequenceEqual(other.OrderBy(keySelector, orderComparer), sequenceComparer));
        }
Example #59
0
 public SlimHashTable(Func <TValue, TKey> keyProvider, IEqualityComparer <TKey> comparer)
     : this(keyProvider, 0, comparer, DefaultGrowthPolicy)
 {
 }
 public ObservableDictionary(IDictionary <TKey, TValue> dictionary, IEqualityComparer <TKey> comparer)
 {
     InternalDictionary = new Dictionary <TKey, TValue>(dictionary, comparer);
 }