/// <summary>
 /// Checks if a constant can be converted from one function data type to another.
 /// </summary>
 /// <param name="newValue">Value to convert.</param>
 /// <param name="oldDataType">Old data type.</param>
 protected virtual void CheckConstantFunction(Object newValue, FunctionDataType oldDataType)
 {
     if (!Equals(newValue.TypeSlim, oldDataType.UnderlyingType.ToTypeSlim())) // NB: TypeSlim implements IEquatable
     {
         throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Cannot convert value '{0}' from function data type '{1}' to '{2}'.", newValue.Value, oldDataType, newValue.TypeSlim));
     }
 }
        /// <summary>
        /// Converts a constant from one function data type to another.
        /// </summary>
        /// <param name="originalValue">Original value to convert.</param>
        /// <param name="oldDataType">Old data type.</param>
        /// <param name="newDataType">New data type.</param>
        /// <returns>Converted constant.</returns>
        protected virtual object ConvertConstantFunction(object originalValue, FunctionDataType oldDataType, FunctionDataType newDataType)
        {
            if (oldDataType.UnderlyingType == newDataType.UnderlyingType)
            {
                return(originalValue);
            }

            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Cannot convert value '{0}' from function data type '{1}' to '{2}'.", originalValue, oldDataType, newDataType));
        }
 static DataTypeDescriptor()
 {
     DnsName = new DnsNameDataType();
     IpAddress = new IpAddress();
     Bag = new Bag();
     Time = new Time();
     String = new StringDataType();
     Rfc822Name = new Rfc822Name();
     X500Name = new X500Name();
     Double = new DoubleDataType();
     YearMonthDuration = new YearMonthDuration();
     DaytimeDuration = new DaytimeDuration();
     DateTime = new DateTime();
     Date = new DateDataType();
     Integer = new IntegerDataType();
     Boolean = new BooleanDataType();
     HexBinary = new HexBinary();
     Base64Binary = new Base64Binary();
     AnyUri = new AnyUri();
     Function = new FunctionDataType();
 }
Beispiel #4
0
 static DataTypeDescriptor()
 {
     DnsName           = new DnsNameDataType();
     IpAddress         = new IpAddress();
     Bag               = new Bag();
     Time              = new Time();
     String            = new StringDataType();
     Rfc822Name        = new Rfc822Name();
     X500Name          = new X500Name();
     Double            = new DoubleDataType();
     YearMonthDuration = new YearMonthDuration();
     DaytimeDuration   = new DaytimeDuration();
     DateTime          = new DateTime();
     Date              = new DateDataType();
     Integer           = new IntegerDataType();
     Boolean           = new BooleanDataType();
     HexBinary         = new HexBinary();
     Base64Binary      = new Base64Binary();
     AnyUri            = new AnyUri();
     Function          = new FunctionDataType();
 }
Beispiel #5
0
 protected override Type MakeFunction(FunctionDataType type, ReadOnlyCollection <Type> parameterTypes, Type returnType)
 {
     return(Expression.GetFuncType(parameterTypes.Concat(new[] { returnType }).ToArray())); // don't care about actions here for testing
 }
Beispiel #6
0
 protected override DataType VisitFunction(FunctionDataType type)
 {
     return(DataType.FromType(typeof(int)));
 }
 protected override LambdaExpression MakeFunction(FunctionDataType type, ReadOnlyCollection <LambdaExpression> parameterTypes, LambdaExpression returnType)
 {
     throw new NotSupportedException("Arbitrary functions cannot be serialized.");
 }