コード例 #1
0
ファイル: Comparer.cs プロジェクト: AnorZaken/AZCL
        internal ComparerN(IComparer <T>[] comparers)
        {
            AZAssert.NotNullInternal(comparers, nameof(comparers));
            AZAssert.Internal(!ArrayHelper.ExistsNull(comparers), "param is null");

            this.comparers = comparers;
        }
コード例 #2
0
ファイル: Comparer.cs プロジェクト: AnorZaken/AZCL
        internal Comparer2(IComparer <T> primary, IComparer <T> secondary)
        {
            AZAssert.NotNullInternal(primary, nameof(primary));
            AZAssert.NotNullInternal(secondary, nameof(secondary));

            this.primary   = primary;
            this.secondary = secondary;
        }
コード例 #3
0
ファイル: Comparer.cs プロジェクト: AnorZaken/AZCL
        internal Comparer4(IComparer <T> primary, IComparer <T> secondary, IComparer <T> tertiary, IComparer <T> quaternary)
        {
            AZAssert.NotNullInternal(primary, nameof(primary));
            AZAssert.NotNullInternal(secondary, nameof(secondary));
            AZAssert.NotNullInternal(tertiary, nameof(tertiary));
            AZAssert.NotNullInternal(quaternary, nameof(quaternary));

            this.primary    = primary;
            this.secondary  = secondary;
            this.tertiary   = tertiary;
            this.quaternary = quaternary;
        }
コード例 #4
0
 // startIndex must non-negative, but there is no upper bound though!
 internal Enumerator(T[,,] array, int startIndex) : this(array)
 {
     AZAssert.GEQZeroInternal(startIndex, nameof(startIndex));
     ArrayHelper.CalculateIndexesUnbound(array, startIndex, out x, out y, out z);
 }
コード例 #5
0
        // tries to convert an integral value of type TIn to an integral value of type TOut ...
        // ... but only if the numerical value of the result would be identical to the numerical value of the input - including sign.
        internal static bool TryConvertInteger <TIn, TOut>(TIn input, out TOut result) // TODO: doc and make public?
            where TIn : IConvertible
            where TOut : IConvertible
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            result = default(TOut);

            if (result == null)
            {
                return(false);
            }

            var niOut = new NumericInfo(result.GetTypeCode());

            if (niOut.IsInteger && niOut.FitsIntValue(input)) // (FitsIntValue: if 'input' (TIn) isn't an Integral type it simply returns false, but if TOut isn't numeric... it throws!)
            {
                try
                {
                    switch (niOut.TypeCode) // TODO: I dislike this switch and hate these double casts, but fixing it requires a lot of extra work, so maybe in the future :/
                    {
                    case TypeCode.SByte:
                        result = (TOut)(object)input.ToSByte(null);
                        return(true);

                    case TypeCode.Byte:
                        result = (TOut)(object)input.ToByte(null);
                        return(true);

                    case TypeCode.Int16:
                        result = (TOut)(object)input.ToInt16(null);
                        return(true);

                    case TypeCode.UInt16:
                        result = (TOut)(object)input.ToUInt16(null);
                        return(true);

                    case TypeCode.Int32:
                        result = (TOut)(object)input.ToInt32(null);
                        return(true);

                    case TypeCode.UInt32:
                        result = (TOut)(object)input.ToUInt32(null);
                        return(true);

                    case TypeCode.Int64:
                        result = (TOut)(object)input.ToInt64(null);
                        return(true);

                    case TypeCode.UInt64:
                        result = (TOut)(object)input.ToUInt64(null);
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    AZAssert.Internal(false, "Unexpected cast failure", e.Message); // this should never ever happen!
                }
            }

            return(false);
        }