internal override Expression VisitConstant(ConstantExpression c) { string result; if (c.Value == null) { _builder.Append(UriHelper.NULL); return(c); } else if (!ClientConvert.TryKeyPrimitiveToString(c.Value, out result)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.ALinqCouldNotConvert, c.Value)); } Debug.Assert(result != null, "result != null"); // A Difference from WCF Data Services is that we will escape later when we execute the fully parsed query. _builder.Append(result); return(c); }
internal static bool TryXmlPrimitiveToString(object value, out string result) { Debug.Assert(value != null, "value != null"); Type valueType = value.GetType(); valueType = Nullable.GetUnderlyingType(valueType) ?? valueType; if (typeof(string) == valueType) { result = (string)value; } else if (typeof(bool) == valueType) { result = XmlConvert.ToString((bool)value); } else if (typeof(byte) == valueType) { result = XmlConvert.ToString((byte)value); } else if (typeof(DateTime) == valueType) { result = XmlConvert.ToString((DateTime)value, XmlDateTimeSerializationMode.RoundtripKind); } else if (typeof(decimal) == valueType) { result = XmlConvert.ToString((decimal)value); } else if (typeof(double) == valueType) { result = XmlConvert.ToString((double)value); } else if (typeof(Guid) == valueType) { result = value.ToString(); } else if (typeof(short) == valueType) { result = XmlConvert.ToString((short)value); } else if (typeof(int) == valueType) { result = XmlConvert.ToString((int)value); } else if (typeof(long) == valueType) { result = XmlConvert.ToString((long)value); } else if (typeof(sbyte) == valueType) { result = XmlConvert.ToString((sbyte)value); } else if (typeof(float) == valueType) { result = XmlConvert.ToString((float)value); } else if (typeof(byte[]) == valueType) { byte[] byteArray = (byte[])value; result = Convert.ToBase64String(byteArray); } else if (ClientConvert.IsBinaryValue(value)) { return(ClientConvert.TryKeyBinaryToString(value, out result)); } else if (typeof(System.Xml.Linq.XElement) == valueType) { result = ((System.Xml.Linq.XElement)value).ToString(System.Xml.Linq.SaveOptions.None); } else { result = null; return(false); } Debug.Assert(result != null, "result != null"); return(true); }
private static int IndexOfStorage(Type type) { int index = ClientConvert.IndexOfReference(ClientConvert.s_knownTypes, type); return(index); }