Ejemplo n.º 1
0
        public static T Add <T>(T a, T b)
            where T : struct
        {
            if (typeof(T) == typeof(byte))
            {
                return((T)(object)((byte)(object)a + (byte)(object)b));
            }

            if (typeof(T) == typeof(sbyte))
            {
                return((T)(object)((sbyte)(object)a + (sbyte)(object)b));
            }

            if (typeof(T) == typeof(ushort))
            {
                return((T)(object)((ushort)(object)a + (ushort)(object)b));
            }

            if (typeof(T) == typeof(short))
            {
                return((T)(object)((short)(object)a + (short)(object)b));
            }

            if (typeof(T) == typeof(uint))
            {
                return((T)(object)((uint)(object)a + (uint)(object)b));
            }

            if (typeof(T) == typeof(int))
            {
                return((T)(object)((int)(object)a + (int)(object)b));
            }

            if (typeof(T) == typeof(ulong))
            {
                return((T)(object)((ulong)(object)a + (ulong)(object)b));
            }

            if (typeof(T) == typeof(long))
            {
                return((T)(object)((long)(object)a + (long)(object)b));
            }

            if (typeof(T) == typeof(float))
            {
                return((T)(object)((float)(object)a + (float)(object)b));
            }

            if (typeof(T) == typeof(double))
            {
                return((T)(object)((double)(object)a + (double)(object)b));
            }

            return(Throw.NotSupportedException <T>());
        }
Ejemplo n.º 2
0
        public static bool Equals <T>(T a, T b)
            where T : struct
        {
            if (typeof(T) == typeof(byte))
            {
                return((byte)(object)a == (byte)(object)b);
            }

            if (typeof(T) == typeof(sbyte))
            {
                return((sbyte)(object)a == (sbyte)(object)b);
            }

            if (typeof(T) == typeof(ushort))
            {
                return((ushort)(object)a == (ushort)(object)b);
            }

            if (typeof(T) == typeof(short))
            {
                return((short)(object)a == (short)(object)b);
            }

            if (typeof(T) == typeof(uint))
            {
                return((uint)(object)a == (uint)(object)b);
            }

            if (typeof(T) == typeof(int))
            {
                return((int)(object)a == (int)(object)b);
            }

            if (typeof(T) == typeof(ulong))
            {
                return((ulong)(object)a == (ulong)(object)b);
            }

            if (typeof(T) == typeof(long))
            {
                return((long)(object)a == (long)(object)b);
            }

            if (typeof(T) == typeof(float))
            {
                return((float)(object)a == (float)(object)b);
            }

            if (typeof(T) == typeof(double))
            {
                return((double)(object)a == (double)(object)b);
            }

            return(Throw.NotSupportedException <bool>());
        }
Ejemplo n.º 3
0
        public static TSum Sum <TSource, TSum>(TSource a, TSum b)
        {
            if (typeof(TSource) == typeof(int?) && typeof(TSum) == typeof(int))
            {
                return((TSum)(object)((int)(object)((int?)(object)a).GetValueOrDefault() + (int)(object)b));
            }

            if (typeof(TSource) == typeof(int) && typeof(TSum) == typeof(int))
            {
                return((TSum)(object)((int)(object)a + (int)(object)b));
            }

            if (typeof(TSource) == typeof(long?) && typeof(TSum) == typeof(long))
            {
                return((TSum)(object)((long)(object)((long?)(object)a).GetValueOrDefault() + (long)(object)b));
            }

            if (typeof(TSource) == typeof(long) && typeof(TSum) == typeof(long))
            {
                return((TSum)(object)((long)(object)a + (long)(object)b));
            }

            if (typeof(TSource) == typeof(float?) && typeof(TSum) == typeof(float))
            {
                return((TSum)(object)((float)(object)((float?)(object)a).GetValueOrDefault() + (float)(object)b));
            }

            if (typeof(TSource) == typeof(float) && typeof(TSum) == typeof(float))
            {
                return((TSum)(object)((float)(object)a + (float)(object)b));
            }

            if (typeof(TSource) == typeof(double?) && typeof(TSum) == typeof(double))
            {
                return((TSum)(object)((double)(object)((double?)(object)a).GetValueOrDefault() + (double)(object)b));
            }

            if (typeof(TSource) == typeof(double) && typeof(TSum) == typeof(double))
            {
                return((TSum)(object)((double)(object)a + (double)(object)b));
            }

            if (typeof(TSource) == typeof(decimal?) && typeof(TSum) == typeof(decimal))
            {
                return((TSum)(object)((decimal)(object)((decimal?)(object)a).GetValueOrDefault() + (decimal)(object)b));
            }

            if (typeof(TSource) == typeof(decimal) && typeof(TSum) == typeof(decimal))
            {
                return((TSum)(object)((decimal)(object)a + (decimal)(object)b));
            }

            return(Throw.NotSupportedException <TSum>());
        }
Ejemplo n.º 4
0
            internal MemorySelectVectorEnumerable(ReadOnlyMemory <TSource> source, TVectorSelector vectorSelector, TSelector selector)
            {
                if (Vector <TSource> .Count != Vector <TResult> .Count)
                {
                    Throw.NotSupportedException();
                }

                this.source         = source;
                this.vectorSelector = vectorSelector;
                this.selector       = selector;
            }
            internal ArraySegmentSelectVectorEnumerable(ArraySegment <TSource> source, TVectorSelector vectorSelector, TSelector selector)
            {
                if (Vector <TSource> .Count != Vector <TResult> .Count)
                {
                    Throw.NotSupportedException();
                }

                this.source         = source;
                this.vectorSelector = vectorSelector;
                this.selector       = selector;
            }
            internal SpanSelectVectorContext(ReadOnlySpan <TSource> source, TVectorSelector vectorSelector, TSelector selector)
            {
                if (Vector <TSource> .Count != Vector <TResult> .Count)
                {
                    Throw.NotSupportedException();
                }

                this.source         = source;
                this.vectorSelector = vectorSelector;
                this.selector       = selector;
            }
Ejemplo n.º 7
0
            internal RangeSelectVectorEnumerable(int start, int count, TVectorSelector vectorSelector, TSelector selector)
            {
                if (Vector <int> .Count != Vector <TResult> .Count)
                {
                    Throw.NotSupportedException();
                }

                this.start          = start;
                this.count          = count;
                this.vectorSelector = vectorSelector;
                this.selector       = selector;
            }
Ejemplo n.º 8
0
 void ICollection <TSource> .Clear()
 => Throw.NotSupportedException();
Ejemplo n.º 9
0
 void ICollection <TSource> .Add(TSource item)
 => Throw.NotSupportedException();
Ejemplo n.º 10
0
 void IList <TSource> .RemoveAt(int index)
 => Throw.NotSupportedException();
Ejemplo n.º 11
0
 void IList <TSource> .Insert(int index, TSource item)
 => Throw.NotSupportedException();
 bool ICollection <TKey> .Remove(TKey item)
 => Throw.NotSupportedException <bool>();
 bool ICollection <TValue> .Remove(TValue item)
 => Throw.NotSupportedException <bool>();
 void ICollection <KeyValuePair <TKey, TValue> > .Clear()
 => Throw.NotSupportedException();
 void ICollection <TValue> .Add(TValue item)
 => Throw.NotSupportedException();
Ejemplo n.º 16
0
        public static bool Equals <TValue>(TValue a, TValue b)
            where TValue : struct
        {
            if (typeof(TValue) == typeof(byte))
            {
                return((byte)(object)a == (byte)(object)b);
            }

            if (typeof(TValue) == typeof(sbyte))
            {
                return((sbyte)(object)a == (sbyte)(object)b);
            }

            if (typeof(TValue) == typeof(short))
            {
                return((short)(object)a == (short)(object)b);
            }

            if (typeof(TValue) == typeof(ushort))
            {
                return((ushort)(object)a == (ushort)(object)b);
            }

            if (typeof(TValue) == typeof(int))
            {
                return((int)(object)a == (int)(object)b);
            }

            if (typeof(TValue) == typeof(uint))
            {
                return((uint)(object)a == (uint)(object)b);
            }

            if (typeof(TValue) == typeof(long))
            {
                return((long)(object)a == (long)(object)b);
            }

            if (typeof(TValue) == typeof(ulong))
            {
                return((ulong)(object)a == (ulong)(object)b);
            }

            if (typeof(TValue) == typeof(float))
            {
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                return((float)(object)a == (float)(object)b);
            }

            if (typeof(TValue) == typeof(double))
            {
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                return((double)(object)a == (double)(object)b);
            }

            if (typeof(TValue) == typeof(decimal))
            {
                return((decimal)(object)a == (decimal)(object)b);
            }

            return(Throw.NotSupportedException <bool>());
        }
Ejemplo n.º 17
0
        public static TValue Add <TNullableValue, TValue>(TNullableValue a, TValue b)
            where TValue : struct
        {
            if (typeof(TNullableValue) == typeof(int?) && typeof(TValue) == typeof(int))
            {
                return((TValue)(object)(((int?)(object?)a).GetValueOrDefault() + (int)(object)b));
            }

            if (typeof(TNullableValue) == typeof(int) && typeof(TValue) == typeof(int))
            {
                return((TValue)(object)((int)(object)a !+(int)(object)b));
            }

            if (typeof(TNullableValue) == typeof(uint?) && typeof(TValue) == typeof(uint))
            {
                return((TValue)(object)(((uint?)(object?)a).GetValueOrDefault() + (uint)(object)b));
            }

            if (typeof(TNullableValue) == typeof(uint) && typeof(TValue) == typeof(uint))
            {
                return((TValue)(object)((uint)(object)a !+(uint)(object)b));
            }

            if (typeof(TNullableValue) == typeof(nint?) && typeof(TValue) == typeof(nint))
            {
                return((TValue)(object)(((nint?)(object?)a).GetValueOrDefault() + (nint)(object)b));
            }

            if (typeof(TNullableValue) == typeof(nint) && typeof(TValue) == typeof(nint))
            {
                return((TValue)(object)((nint)(object)a !+(nint)(object)b));
            }

            if (typeof(TNullableValue) == typeof(nuint?) && typeof(TValue) == typeof(nuint))
            {
                return((TValue)(object)(((nuint?)(object?)a).GetValueOrDefault() + (nuint)(object)b));
            }

            if (typeof(TNullableValue) == typeof(nuint) && typeof(TValue) == typeof(nuint))
            {
                return((TValue)(object)((nuint)(object)a !+(nuint)(object)b));
            }

            if (typeof(TNullableValue) == typeof(long?) && typeof(TValue) == typeof(long))
            {
                return((TValue)(object)(((long?)(object?)a).GetValueOrDefault() + (long)(object)b));
            }

            if (typeof(TNullableValue) == typeof(long) && typeof(TValue) == typeof(long))
            {
                return((TValue)(object)((long)(object)a !+(long)(object)b));
            }

            if (typeof(TNullableValue) == typeof(float?) && typeof(TValue) == typeof(float))
            {
                return((TValue)(object)(((float?)(object?)a).GetValueOrDefault() + (float)(object)b));
            }

            if (typeof(TNullableValue) == typeof(float) && typeof(TValue) == typeof(float))
            {
                return((TValue)(object)((float)(object)a !+(float)(object)b));
            }

            if (typeof(TNullableValue) == typeof(double?) && typeof(TValue) == typeof(double))
            {
                return((TValue)(object)(((double?)(object?)a).GetValueOrDefault() + (double)(object)b));
            }

            if (typeof(TNullableValue) == typeof(double) && typeof(TValue) == typeof(double))
            {
                return((TValue)(object)((double)(object)a !+(double)(object)b));
            }

            if (typeof(TNullableValue) == typeof(decimal?) && typeof(TValue) == typeof(decimal))
            {
                return((TValue)(object)(((decimal?)(object?)a).GetValueOrDefault() + (decimal)(object)b));
            }

            if (typeof(TNullableValue) == typeof(decimal) && typeof(TValue) == typeof(decimal))
            {
                return((TValue)(object)((decimal)(object)a !+(decimal)(object)b));
            }

            return(Throw.NotSupportedException <TValue>());
        }
Ejemplo n.º 18
0
        public static TValue GetValueOrDefault <TValue, TPredicate>(TPredicate predicate, TValue value, int index)
            where TPredicate : struct, IFunction <TValue, int, bool>
        {
            if (typeof(TValue) == typeof(int?))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * ((int?)(object?)value).GetValueOrDefault()));
            }

            if (typeof(TValue) == typeof(int))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * (int)(object)value !));
            }

            if (typeof(TValue) == typeof(uint?))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * ((uint?)(object?)value).GetValueOrDefault()));
            }

            if (typeof(TValue) == typeof(uint))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * (uint)(object)value !));
            }

            if (typeof(TValue) == typeof(nint?))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * ((nint?)(object?)value).GetValueOrDefault()));
            }

            if (typeof(TValue) == typeof(nint))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * (nint)(object)value !));
            }

            if (typeof(TValue) == typeof(nuint?))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * ((nuint?)(object?)value).GetValueOrDefault()));
            }

            if (typeof(TValue) == typeof(nuint))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * (nuint)(object)value !));
            }

            if (typeof(TValue) == typeof(long?))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * ((long?)(object?)value).GetValueOrDefault()));
            }

            if (typeof(TValue) == typeof(long))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * (long)(object)value !));
            }

            if (typeof(TValue) == typeof(ulong?))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * ((ulong?)(object?)value).GetValueOrDefault()));
            }

            if (typeof(TValue) == typeof(ulong))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * (ulong)(object)value !));
            }

            if (typeof(TValue) == typeof(float?))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * ((float?)(object?)value).GetValueOrDefault()));
            }

            if (typeof(TValue) == typeof(float))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * (float)(object)value !));
            }

            if (typeof(TValue) == typeof(double?))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * ((double?)(object?)value).GetValueOrDefault()));
            }

            if (typeof(TValue) == typeof(double))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * (double)(object)value !));
            }

            if (typeof(TValue) == typeof(decimal?))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * ((decimal?)(object?)value).GetValueOrDefault()));
            }

            if (typeof(TValue) == typeof(decimal))
            {
                return((TValue)(object)(predicate.Invoke(value, index).AsByte() * (decimal)(object)value !));
            }

            return(Throw.NotSupportedException <TValue>());
        }
Ejemplo n.º 19
0
 bool ICollection <TSource> .Remove(TSource item)
 => Throw.NotSupportedException <bool>();
 void ICollection <TKey> .Add(TKey item)
 => Throw.NotSupportedException();
 void ICollection <KeyValuePair <TKey, TValue> > .Add(KeyValuePair <TKey, TValue> item)
 => Throw.NotSupportedException();
 bool ICollection <TKey> .Contains(TKey item)
 => Throw.NotSupportedException <bool>();
 bool ICollection <KeyValuePair <TKey, TValue> > .Remove(KeyValuePair <TKey, TValue> item)
 => Throw.NotSupportedException <bool>();
 bool ICollection <TValue> .Contains(TValue item)
 => Throw.NotSupportedException <bool>();