private string TypeNameForUri(Type type) { type = (Nullable.GetUnderlyingType(type) ?? type); if (ClientConvert.IsKnownType(type)) { if (ClientConvert.IsSupportedPrimitiveTypeForUri(type)) { return(ClientConvert.ToTypeName(type)); } throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Can't cast to unsupported type '{0}'", type.Name)); } return(null); }
internal override Expression VisitConstant(ConstantExpression c) { string result = null; if (c.Value == null) { builder.Append("null"); return(c); } if (!ClientConvert.TryKeyPrimitiveToString(c.Value, out result)) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Could not convert constant {0} expression to string.", c.Value)); } builder.Append(result); return(c); }
internal override Expression VisitUnary(UnaryExpression u) { if (ResourceBinder.PatternRules.MatchConvertToAssignable(u)) { return(base.VisitUnary(u)); } if (u.NodeType == ExpressionType.Convert || u.NodeType == ExpressionType.ConvertChecked) { Type obj = Nullable.GetUnderlyingType(u.Operand.Type) ?? u.Operand.Type; Type type = Nullable.GetUnderlyingType(u.Type) ?? u.Type; if (ClientConvert.IsKnownType(obj) && ClientConvert.IsKnownType(type)) { return(base.Visit(u.Operand)); } } throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Initializing instances of the entity type {0} with the expression {1} is not supported.", this.type, u.ToString())); }
internal override Expression VisitMemberAccess(MemberExpression m) { if (ClientConvert.IsKnownNullableType(m.Expression.Type)) { return(base.VisitMemberAccess(m)); } if (!CommonUtil.IsClientType(m.Expression.Type)) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Constructing or initializing instances of the type {0} with the expression {1} is not supported.", type, m.ToString())); } PropertyInfo propInfo = null; if (ResourceBinder.PatternRules.MatchNonPrivateReadableProperty(m, out propInfo)) { Expression result = base.VisitMemberAccess(m); box.AppendToPath(propInfo); return(result); } throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Constructing or initializing instances of the type {0} with the expression {1} is not supported.", type, m.ToString())); }
internal static bool TryXmlPrimitiveToString(object value, out string result) { result = null; Type type = value.GetType(); type = (Nullable.GetUnderlyingType(type) ?? type); if (typeof(string) == type) { result = (string)value; } else if (typeof(bool) == type) { result = XmlConvert.ToString((bool)value); } else if (typeof(byte) == type) { result = XmlConvert.ToString((byte)value); } else if (typeof(DateTime) == type) { result = XmlConvert.ToString((DateTime)value, XmlDateTimeSerializationMode.RoundtripKind); } else if (typeof(decimal) == type) { result = XmlConvert.ToString((decimal)value); } else if (typeof(double) == type) { result = XmlConvert.ToString((double)value); } else if (typeof(Guid) == type) { result = value.ToString(); } else if (typeof(short) == type) { result = XmlConvert.ToString((short)value); } else if (typeof(int) == type) { result = XmlConvert.ToString((int)value); } else if (typeof(long) == type) { result = XmlConvert.ToString((long)value); } else if (typeof(sbyte) == type) { result = XmlConvert.ToString((sbyte)value); } else if (typeof(float) == type) { result = XmlConvert.ToString((float)value); } else if (typeof(byte[]) == type) { byte[] inArray = (byte[])value; result = Convert.ToBase64String(inArray); } else { if (ClientConvert.IsBinaryValue(value)) { return(ClientConvert.TryKeyBinaryToString(value, out result)); } if (!(typeof(XElement) == type)) { result = null; return(false); } result = ((XElement)value).ToString(SaveOptions.None); } return(true); }