コード例 #1
0
        internal static object ConvertPrimitiveValue(object value, IEdmPrimitiveTypeReference primitiveType, TimeZoneInfo timeZoneInfo)
        {
            if (value == null)
            {
                return(null);
            }

            Type type = value.GetType();

            if (primitiveType != null && primitiveType.IsDate() && TypeHelper.IsDateTime(type))
            {
                Date dt = (DateTime)value;
                return(dt);
            }

            if (primitiveType != null && primitiveType.IsTimeOfDay() && TypeHelper.IsTimeSpan(type))
            {
                TimeOfDay tod = (TimeSpan)value;
                return(tod);
            }

#if NET6_0
            // Since ODL doesn't support "DateOnly", we have to use Date defined in ODL.
            if (primitiveType != null && primitiveType.IsDate() && TypeHelper.IsDateOnly(type))
            {
                DateOnly dateOnly = (DateOnly)value;
                return(new Date(dateOnly.Year, dateOnly.Month, dateOnly.Day));
            }

            // Since ODL doesn't support "TimeOnly", we have to use TimeOfDay defined in ODL.
            if (primitiveType != null && primitiveType.IsTimeOfDay() && TypeHelper.IsTimeOnly(type))
            {
                TimeOnly timeOnly = (TimeOnly)value;
                return(new TimeOfDay(timeOnly.Hour, timeOnly.Minute, timeOnly.Second, timeOnly.Millisecond));
            }
#endif

            return(ConvertUnsupportedPrimitives(value, timeZoneInfo));
        }
コード例 #2
0
        internal static object ConvertPrimitiveValue(object value, IEdmPrimitiveTypeReference primitiveType)
        {
            if (value == null)
            {
                return(null);
            }

            Type type = value.GetType();

            if (primitiveType != null && primitiveType.IsDate() && TypeHelper.IsDateTime(type))
            {
                Date dt = (DateTime)value;
                return(dt);
            }

            if (primitiveType != null && primitiveType.IsTimeOfDay() && TypeHelper.IsTimeSpan(type))
            {
                TimeOfDay tod = (TimeSpan)value;
                return(tod);
            }

            return(ConvertUnsupportedPrimitives(value));
        }
コード例 #3
0
        internal static object ConvertPrimitiveValue(object value, IEdmPrimitiveTypeReference primitiveType)
        {
            if (value == null)
            {
                return null;
            }

            Type type = value.GetType();
            if (primitiveType != null && primitiveType.IsDate() && TypeHelper.IsDateTime(type))
            {
                Date dt = (DateTime)value;
                return dt;
            }

            if (primitiveType != null && primitiveType.IsTimeOfDay() && TypeHelper.IsTimeSpan(type))
            {
                TimeOfDay tod = (TimeSpan)value;
                return tod;
            }

            return ConvertUnsupportedPrimitives(value);
        }