コード例 #1
0
        public static int CompareTo(Type typeOfValue, object value, Type typeOfValueToCompare, object valueToCompare)
        {
            if (TypeJudge.IsNumericType(typeOfValue) && TypeJudge.IsNumericType(typeOfValueToCompare))
            {
                var valueNumeric          = Convert.ToDecimal(value);
                var valueNumericToCompare = Convert.ToDecimal(valueToCompare);
                return(valueNumeric.CompareTo(valueNumericToCompare));
            }

            if (value is char valueChar && valueToCompare is char valueCharToCompare)
            {
                return(valueChar.CompareTo(valueCharToCompare));
            }

            if (TypeJudge.IsEnumType(typeOfValue) && TypeJudge.IsEnumType(typeOfValueToCompare))
            {
                var valueEnumName          = Enum.GetName(typeOfValue, value);
                var valueEnumNameToCompare = Enum.GetName(typeOfValueToCompare, valueToCompare);
                return(string.Compare(valueEnumName, valueEnumNameToCompare, StringComparison.Ordinal));
            }

            long valueTimeStamp = ToLongTimeTicks(value);

            long valueTimeStampToCompare = ToLongTimeTicks(valueToCompare, -1L);

            return(valueTimeStamp.CompareTo(valueTimeStampToCompare));
        }
コード例 #2
0
        public static bool Valid(Type typeOfValue, object value, Type typeOfValueToCompare, object valueToCompare)
        {
            if (TypeJudge.IsNumericType(typeOfValue) && TypeJudge.IsNumericType(typeOfValueToCompare))
            {
                var valueNumeric          = Convert.ToDecimal(value);
                var valueNumericToCompare = Convert.ToDecimal(valueToCompare);
                return(valueNumeric == valueNumericToCompare);
            }

            if (value is char valueChar && valueToCompare is char valueCharToCompare)
            {
                return(valueChar == valueCharToCompare);
            }

            if (TypeJudge.IsEnumType(typeOfValue) && TypeJudge.IsEnumType(typeOfValueToCompare))
            {
                var valueEnumName          = Enum.GetName(typeOfValue, value);
                var valueEnumNameToCompare = Enum.GetName(typeOfValueToCompare, valueToCompare);
                return(valueEnumName == valueEnumNameToCompare);
            }

            long valueTimeStamp = ToLongTimeTicks(value);

            long valueTimeStampToCompare = ToLongTimeTicks(valueToCompare, -1L);

            return(valueTimeStamp == valueTimeStampToCompare);
        }
コード例 #3
0
        public static void RejectSimpleType(Type type)
        {
            if (type is null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (TypeJudge.IsEnumType(type))
            {
                throw new ArgumentException("ObjectVisitor does not support direct processing of enum types.", nameof(type));
            }

            if (TypeJudge.IsNumericType(type))
            {
                throw new ArgumentException("ObjectVisitor does not support direct processing of numeric types.", nameof(type));
            }

            if (type.IsPrimitive)
            {
                throw new ArgumentException("ObjectVisitor does not support direct processing of primitive types.", nameof(type));
            }

            if (type == typeof(string) || type == typeof(Guid) || type == typeof(Type))
            {
                throw new ArgumentException("ObjectVisitor does not support direct processing of String, Type or Guid.", nameof(type));
            }
        }