System.Collections.Generic.EqualityComparer.Equals(T, T)

Here are the examples of the csharp api System.Collections.Generic.EqualityComparer.Equals(T, T) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

716 Examples 7

19 View Source File : ApiEnum.cs
License : MIT License
Project Creator : Archomeda

public virtual bool Equals(ApiEnum<T>? other) =>
            !(other is null) &&
            EqualityComparer<T>.Default.Equals(this.Value, other.Value) &&
            EqualityComparer<string?>.Default.Equals(this.RawValue?.ToLowerInvariant(), other.RawValue?.ToLowerInvariant());

19 View Source File : PropertyAssert.cs
License : Apache License 2.0
Project Creator : aspnet

private static bool IsSet<T>(T value)
        {
            return !EqualityComparer<T>.Default.Equals(value, default(T));
        }

19 View Source File : WrapperPredicate.cs
License : MIT License
Project Creator : Alan-FGR

[MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool Matches(ref T otherItem)
        {
            return Comparer.Equals(Item, otherItem);
        }

19 View Source File : BaseModel.cs
License : MIT License
Project Creator : AnnoDesigner

protected virtual bool SetPropertyAndNotify<T>(ref T backingField, T value, [CallerMemberName] string propertyName = "")
        {
            if (EqualityComparer<T>.Default.Equals(backingField, value))
            {
                return false;
            }

            backingField = value;
            OnPropertyChanged(propertyName);
            return true;
        }

19 View Source File : NotificationDomainModel.cs
License : MIT License
Project Creator : ambleside138

protected bool RaisePropertyChangedIfSet<T>(ref T source, T value, string[] relatedProperties = null,
            [CallerMemberName] string propertyName = null)
        {
            //値が同じだったら何もしない
            if (EqualityComparer<T>.Default.Equals(source, value))
                return false;

            source = value;
            RaisePropertyChanged(propertyName);
            if (relatedProperties == null) return true;

            foreach (var p in relatedProperties)
                RaisePropertyChanged(p);

            return true;
        }

19 View Source File : ModelBase.cs
License : Apache License 2.0
Project Creator : AKruimink

protected virtual bool SetProperty<T>(ref T storage, T value, Action onChanged, [CallerMemberName] string? propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(storage, value))
            {
                return false;
            }

            storage = value;
            onChanged?.Invoke();
            RaisePropertyChanged(propertyName);

            if (propertyName != null && PropertyDependencies.ContainsKey(propertyName))
            {
                foreach (var dependency in PropertyDependencies[propertyName])
                {
                    RaisePropertyChanged(dependency);
                }
            }

            return true;
        }

19 View Source File : PrioritizedList.cs
License : MIT License
Project Creator : ArchonInteractive

public int IndexOf(T item)
        {
            var comparer = EqualityComparer<T>.Default;

            for (var i = 0; i < _items.Count; i++)
            {
                if (comparer.Equals(item, _items[i].Item))
                    return i;
            }

            return -1;
        }

19 View Source File : RingBuffer.cs
License : MIT License
Project Creator : AgoraIO

public bool Remove(T item) {
            int _index = head;
            int _removeIndex = 0;
            bool _foundItem = false;
            EqualityComparer<T> _comparer = EqualityComparer<T>.Default;
            for(int i = 0; i < size; i++, _index = (_index + 1) % Capacity) {
                if(_comparer.Equals(item, buffer[_index])) {
                    _removeIndex = _index;
                    _foundItem = true;
                    break;
                }
            }
            if(_foundItem) {
                T[] _newBuffer = new T[size - 1];
                _index = head;
                bool _pasreplacedem = false;
                for(int i = 0; i < size - 1; i++, _index = (_index + 1) % Capacity) {
                    if(_index == _removeIndex) {
                        _pasreplacedem = true;
                    }
                    if(_pasreplacedem) {
                        _newBuffer[_index] = buffer[(_index + 1) % Capacity];
                    }
                    else {
                        _newBuffer[_index] = buffer[_index];
                    }
                }
                size--;
                buffer = _newBuffer;
                return true;
            }
            return false;
        }

19 View Source File : PageSettings.cs
License : Microsoft Public License
Project Creator : atrenton

protected bool SetField<T>(ref T field, T value,
           [CallerMemberName] string propertyName = "")
        {
            if (EqualityComparer<T>.Default.Equals(field, value)) return false;

            // Check if object is being deserialized
            var callingMethod = new StackTrace().GetFrame(2).GetMethod();
            if (callingMethod.Module.Name == "<In Memory Module>")
            {
                field = value;
                return false;
            }

            DisplayStateChange(field, value, propertyName);
            field = value;
            return (_modified = true);
        }

19 View Source File : BaseViewModel.cs
License : MIT License
Project Creator : aimore

protected bool Set<T>(T value, bool shouldEqual = true, bool shouldRaisePropertyChanged = true, [CallerMemberName] string key = null)
        {
            var typeDict = GetTypeDict<T>();
            if (shouldEqual && typeDict.TryGetValue(key, out T oldValue) && EqualityComparer<T>.Default.Equals(oldValue, value))
            {
                return false;
            }
            typeDict[key] = value;
            if (shouldRaisePropertyChanged)
            {
                OnPropertyChanged(key);
            }
            return true;
        }

19 View Source File : BindableItem.cs
License : Apache License 2.0
Project Creator : anmcgrath

protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(field, value)) return false;
            field = value;
            OnPropertyChanged(propertyName);
            return true;
        }

19 View Source File : ObservableObject.cs
License : MIT License
Project Creator : Aminator

protected bool Set<T>(T currentValue, T newValue, Action setAction, [CallerMemberName] string? propertyName = null)
        {
            if (!EqualityComparer<T>.Default.Equals(currentValue, newValue))
            {
                setAction.Invoke();
                OnPropertyChanged(propertyName);
                return true;
            }

            return false;
        }

19 View Source File : TestObserver.cs
License : Apache License 2.0
Project Creator : akarnokd

public TestObserver<T> replacedertValues(params T[] expected)
        {
            var c = Volatile.Read(ref itemCount);

            if (c != expected.Length)
            {
                throw Fail("Number of items differ. Expected: " + expected.Length + ", Actual: " + c);
            }

            for (int i = 0; i < c; i++)
            {
                var actual = items[i];
                var expect = expected[i];

                if (expect is IEnumerable en)
                {
                    if (actual is IEnumerable an)
                    {
                        compareEnums(en, an, i);
                    }
                    else
                    {
                        throw Fail("Item @ " + i + " differ. Expected: " + ToStr(expect) + ", Actual: " + ToStr(actual));
                    }
                }
                else
                {
                    if (!EqualityComparer<T>.Default.Equals(actual, expect))
                    {
                        throw Fail("Item @ " + i + " differ. Expected: " + ToStr(expect) + ", Actual: " + ToStr(actual));
                    }
                }
            }

            return this;
        }

19 View Source File : ContextMenuItemTest.cs
License : MIT License
Project Creator : anpin

protected bool SetField<T>(ref T field, T value, [System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
            {
                if (EqualityComparer<T>.Default.Equals(field, value)) return false;
                field = value;
                NotifyPropertyChanged(propertyName);
                return true;
            }

19 View Source File : BetterList.cs
License : GNU General Public License v3.0
Project Creator : aelariane

public bool Remove(T item)
    {
        if (this.buffer != null)
        {
            EqualityComparer<T> @default = EqualityComparer<T>.Default;
            for (int i = 0; i < this.size; i++)
            {
                if (@default.Equals(this.buffer[i], item))
                {
                    this.size--;
                    this.buffer[i] = default(T);
                    for (int j = i; j < this.size; j++)
                    {
                        this.buffer[j] = this.buffer[j + 1];
                    }
                    return true;
                }
            }
        }
        return false;
    }

19 View Source File : PrioritizedList.cs
License : MIT License
Project Creator : ArchonInteractive

public bool Remove(T item)
        {
            var comparer = EqualityComparer<T>.Default;

            var itemCount = _items.Count;
            for (var i = 0; i < itemCount; i++)
            {
                if (comparer.Equals(item, _items[i].Item))
                {
                    _items.RemoveAt(i);
                    return true;
                }
            }

            return false;
        }

19 View Source File : MarchingSquares.cs
License : MIT License
Project Creator : Alan-FGR

public CxFastListNode<T> Find(T value)
            {
                // start at head
                CxFastListNode<T> head = _head;
                EqualityComparer<T> comparer = EqualityComparer<T>.Default;
                if (head != null)
                {
                    if (value != null)
                    {
                        do
                        {
                            if (comparer.Equals(head._elt, value))
                            {
                                return head;
                            }
                            head = head._next;
                        } while (head != _head);
                    }
                    else
                    {
                        do
                        {
                            if (head._elt == null)
                            {
                                return head;
                            }
                            head = head._next;
                        } while (head != _head);
                    }
                }
                return null;
            }

19 View Source File : AbstractNotifyPropertyChanged.cs
License : MIT License
Project Creator : aritchie

protected bool SetProperty<T>(ref T property, T value, [CallerMemberName] string propertyName = "")
        {
            if (EqualityComparer<T>.Default.Equals(property, value))
                return false;

            property = value;
            this.OnPropertyChanged(propertyName);
            return true;
        }

19 View Source File : FolderLocationBar.xaml.cs
License : MIT License
Project Creator : Accelerider

protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
            storage = value;
            OnPropertyChanged(propertyName);
            return true;
        }

19 View Source File : ParsedArgument.cs
License : MIT License
Project Creator : AtomicBlom

public bool Equals(ParsedArgument<TSource, T> other)
		{
			if (ReferenceEquals(null, other)) return false;
			if (ReferenceEquals(this, other)) return true;
			return Equals(Range, other.Range) && EqualityComparer<T>.Default.Equals(_result, other._result);
		}

19 View Source File : MessagePackSecurity.cs
License : Apache License 2.0
Project Creator : allenai

public bool Equals(T x, T y) => EqualityComparer<T>.Default.Equals(x, y);

19 View Source File : BaseViewModel.cs
License : MIT License
Project Creator : Altevir

protected bool SetProperty<T>(ref T field, T value, [CallerMemberName]string propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(field, value))
            {
                return false;
            }

            field = value;
            OnPropertyChanged(propertyName);

            return true;
        }

19 View Source File : MergedStyles.cs
License : MIT License
Project Creator : Accelerider

private static bool Equals<T>(T left, T right) => EqualityComparer<T>.Default.Equals(left, right);

19 View Source File : ObservableObject.cs
License : MIT License
Project Creator : Aminator

protected bool Set<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
        {
            if (!EqualityComparer<T>.Default.Equals(field, value))
            {
                field = value;
                OnPropertyChanged(propertyName);
                return true;
            }

            return false;
        }

19 View Source File : BaseViewModel.cs
License : MIT License
Project Creator : aimore

protected bool SetProperty<T>(ref T backingStore, T value,
            [CallerMemberName]string propertyName = "",
            Action onChanged = null)
        {
            if (EqualityComparer<T>.Default.Equals(backingStore, value))
                return false;

            backingStore = value;
            onChanged?.Invoke();
            OnPropertyChanged(propertyName);
            return true;
        }

19 View Source File : BaseOpenTokService.cs
License : MIT License
Project Creator : AndreiMisiukevich

private void SetValue<T>(T value, [CallerMemberName] string name = null)
        {
            lock (_propertiesLocker)
            {
                if (_properties.ContainsKey(name) && EqualityComparer<T>.Default.Equals((T)_properties[name], value))
                {
                    return;
                }
                _properties[name] = value;
            }
            RaisePropertyChanged(name);
        }

19 View Source File : TransformComponent.cs
License : MIT License
Project Creator : Aminator

private bool Set<T>(ref T field, T value, [CallerMemberName] string propertyName = "")
        {
            if (!EqualityComparer<T>.Default.Equals(field, value))
            {
                field = value;
                OnPropertyChanged(propertyName);
                return true;
            }

            return false;
        }

19 View Source File : Presenter.cs
License : MIT License
Project Creator : AiursoftWeb

protected void Update<T>(ref T field, T value, [CallerMemberName]string propertyName = null)
        {
            if (!EqualityComparer<T>.Default.Equals(field, value))
            {
                field = value;
                OnPropertyChanged(propertyName);
            }
        }

19 View Source File : Notify.cs
License : MIT License
Project Creator : AnnoDesigner

protected bool UpdateProperty<T>(ref T field, T value, [CallerMemberName] string name = null)
        {
            if (EqualityComparer<T>.Default.Equals(field, value))
            {
                return false;
            }

            field = value;
            OnPropertyChanged(name);
            return true;
        }

19 View Source File : ExpressionValue.cs
License : MIT License
Project Creator : actions

public Boolean Equals(ExpressionValue<T> rhs)
        {
            if (rhs is null)
            {
                return false;
            }

            if (ReferenceEquals(this, rhs))
            {
                return true;
            }

            if (IsLiteral)
            {
                return EqualityComparer<T>.Default.Equals(this.Literal, rhs.Literal);
            }
            else
            {
                return this.Expression == rhs.Expression;
            }
        }

19 View Source File : BooleanConverter.cs
License : MIT License
Project Creator : anoyetta

public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            => value is T && EqualityComparer<T>.Default.Equals((T)value, True);

19 View Source File : ModelBase.cs
License : Apache License 2.0
Project Creator : AKruimink

protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string? propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(storage, value))
            {
                return false;
            }

            storage = value;
            RaisePropertyChanged(propertyName);

            if (propertyName != null && PropertyDependencies.ContainsKey(propertyName))
            {
                foreach (var dependency in PropertyDependencies[propertyName])
                {
                    RaisePropertyChanged(dependency);
                }
            }

            return true;
        }

19 View Source File : MainViewModel.cs
License : MIT License
Project Creator : anpin

protected bool SetField<T>(ref T field, T value, [System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(field, value)) return false;
            field = value;
            NotifyPropertyChanged(propertyName);
            return true;
        }

19 View Source File : Notification.cs
License : MIT License
Project Creator : Accelerider

protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(storage, value)) return false;

            storage = value;
            RaisePropertyChanged(propertyName);

            return true;
        }

19 View Source File : PrioritizedList.cs
License : MIT License
Project Creator : ArchonInteractive

public bool Equals(PrioritizedItem<T> other)
        {
            if (default(T) == null)
                return ReferenceEquals(Item, other.Item);

            return EqualityComparer<T>.Default.Equals(Item, other.Item);
        }

19 View Source File : MarchingSquares.cs
License : MIT License
Project Creator : Alan-FGR

public bool Remove(T value)
            {
                CxFastListNode<T> head = _head;
                CxFastListNode<T> prev = _head;

                EqualityComparer<T> comparer = EqualityComparer<T>.Default;

                if (head != null)
                {
                    if (value != null)
                    {
                        do
                        {
                            // if we are on the value to be removed
                            if (comparer.Equals(head._elt, value))
                            {
                                // then we need to patch the list
                                // check to see if we are removing the _head
                                if (head == _head)
                                {
                                    _head = head._next;
                                    _count--;
                                    return true;
                                }
                                else
                                {
                                    // were not at the head
                                    prev._next = head._next;
                                    _count--;
                                    return true;
                                }
                            }
                            // cache the current as the previous for the next go around
                            prev = head;
                            head = head._next;
                        } while (head != null);
                    }
                }
                return false;
            }

19 View Source File : PrioritizedList.cs
License : MIT License
Project Creator : ArchonInteractive

public bool Contains(T item)
        {
            var comparer = EqualityComparer<T>.Default;

            var itemCount = _items.Count;
            for (var i = 0; i < itemCount; i++)
            {
                if (comparer.Equals(item, _items[i].Item))
                    return true;
            }

            return false;
        }

19 View Source File : RingBuffer.cs
License : MIT License
Project Creator : AgoraIO

public bool Contains(T item) {
            EqualityComparer<T> comparer = EqualityComparer<T>.Default;
            int _index = head;
            for(int i = 0; i < size; i++, _index = (_index + 1) % Capacity) {
                if(comparer.Equals(item, buffer[_index])) return true;
            }
            return false;
        }

19 View Source File : GuardClauseExtensions.cs
License : MIT License
Project Creator : ardalis

private static T Zero<T>([JetBrainsNotNull] this IGuardClause guardClause, T input, [JetBrainsNotNull][JetBrainsInvokerParameterName] string parameterName, string? message = null) where T : struct
        {
            if (EqualityComparer<T>.Default.Equals(input, default(T)))
            {
                throw new ArgumentException(message ?? $"Required input {parameterName} cannot be zero.", parameterName);
            }

            return input;
        }

19 View Source File : WrapperEqualityComparer.cs
License : MIT License
Project Creator : Alan-FGR

[MethodImpl(MethodImplOptions.AggressiveInlining)]
        public bool Equals(ref T a, ref T b)
        {
            return Comparer.Equals(a, b);
        }

19 View Source File : DictionaryExtensions.cs
License : Apache License 2.0
Project Creator : aspnet

public static void SetOrClearValue<T>(this IDictionary<string, object> dictionary, string key, T value)
        {
            if (dictionary == null)
            {
                throw new ArgumentNullException(nameof(dictionary));
            }

            if (EqualityComparer<T>.Default.Equals(value, default(T)))
            {
                dictionary.Remove(key);
            }
            else
            {
                dictionary[key] = value;
            }
        }

19 View Source File : Rope.cs
License : MIT License
Project Creator : Abdesol

public int LastIndexOf(T item, int startIndex, int count)
		{
			VerifyRange(startIndex, count);

			var comparer = EqualityComparer<T>.Default;
			for (int i = startIndex + count - 1; i >= startIndex; i--) {
				if (comparer.Equals(this[i], item))
					return i;
			}
			return -1;
		}

19 View Source File : ViewModel.cs
License : MIT License
Project Creator : Astropilot

protected void Set<T>(ref T property, T value, [CallerMemberName] string name = null)
        {
            if (!EqualityComparer<T>.Default.Equals(property, value))
            {
                property = value;
                RaisePropertyChanged(name);
            }
        }

19 View Source File : Intersector.cs
License : GNU General Public License v3.0
Project Creator : alexgracianoarj

private void AddToDomain(T value)
		{
			bool found = false;

			for (int i = domainIndex; i < domain.Count && !found; i++) {
				if (EqualityComparer<T>.Default.Equals(domain[i].Value, value)) {
					domain[i].Count++;
					domainIndex = (i + 1) % domain.Count;
					found = true;
				}
			}
			for (int i = 0; i < domainIndex && !found; i++) {
				if (EqualityComparer<T>.Default.Equals(domain[i].Value, value)) {
					domain[i].Count++;
					domainIndex = (i + 1) % domain.Count;
					found = true;
				}
			}

			if (!found) {
				DomainElement newElement = new DomainElement(value);
				domain.Add(newElement);
				domainIndex = 0;
			}
		}

19 View Source File : BaseViewModel.cs
License : MIT License
Project Creator : AgoraIO-Community

protected bool SetProperty<T>(ref T backingStore, T value, [CallerMemberName]string propertyName = "", Action onChanged = null)
        {
            if (EqualityComparer<T>.Default.Equals(backingStore, value))
                return false;

            backingStore = value;
            onChanged?.Invoke();
            OnPropertyChanged(propertyName);
            return true;
        }

19 View Source File : Signified.cs
License : MIT License
Project Creator : 8T4

public bool Equals(Signified<T> other)
            => EqualityComparer<T>.Default.Equals(Value, other.Value);

19 View Source File : Deque.cs
License : MIT License
Project Creator : Abdesol

public bool Contains(T item)
		{
			EqualityComparer<T> comparer = EqualityComparer<T>.Default;
			foreach (T element in this)
				if (comparer.Equals(item, element))
					return true;
			return false;
		}

19 View Source File : FileDownloader.cs
License : MIT License
Project Creator : Accelerider

private static bool SetProperty<T>(ref T storage, T value)
        {
            if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
            storage = value;
            return true;
        }

19 View Source File : ExpressionExtension.cs
License : GNU General Public License v3.0
Project Creator : aiportal

public static MapResult<T, R> To<T, R>(this MapResult<T, R> mr, R result, params T[] vals)
		{
			if (mr.Success) return mr;

			var comparer = EqualityComparer<T>.Default;
			if (vals != null && Array.Exists(vals, v => comparer.Equals(v ,mr.Value)))
				mr.Result = result;
			return mr;
		}

19 View Source File : ViewModelBase.cs
License : MIT License
Project Creator : amwx

protected bool RaiseAndSetIfChanged<T>(ref T field, T value, [CallerMemberName] string propertyName = "")
        {
            if (!EqualityComparer<T>.Default.Equals(field, value))
            {
                field = value;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
                return true;
            }
            return false;
        }

See More Examples