/// <summary> /// Generates a string to be used as the skip token value within the next link. /// </summary> /// <param name="lastMember"> Object based on which SkipToken value will be generated.</param> /// <param name="model">The edm model.</param> /// <param name="orderByNodes">List of orderByNodes used to generate the skiptoken value.</param> /// <returns>Value for the skiptoken to be used in the next link.</returns> private static string GenerateSkipTokenValue(Object lastMember, IEdmModel model, IList <OrderByNode> orderByNodes) { if (lastMember == null) { return(String.Empty); } IEnumerable <IEdmProperty> propertiesForSkipToken = GetPropertiesForSkipToken(lastMember, model, orderByNodes); StringBuilder skipTokenBuilder = new StringBuilder(String.Empty); if (propertiesForSkipToken == null) { return(skipTokenBuilder.ToString()); } int count = 0; string uriLiteral; object value; int lastIndex = propertiesForSkipToken.Count() - 1; IEdmStructuredObject obj = lastMember as IEdmStructuredObject; foreach (IEdmProperty edmProperty in propertiesForSkipToken) { bool islast = count == lastIndex; string clrPropertyName = EdmLibHelpers.GetClrPropertyName(edmProperty, model); if (obj != null) { obj.TryGetPropertyValue(clrPropertyName, out value); } else { value = lastMember.GetType().GetProperty(clrPropertyName).GetValue(lastMember); } if (value == null) { uriLiteral = ODataUriUtils.ConvertToUriLiteral(value, ODataVersion.V401); } else if (edmProperty.Type.IsEnum()) { ODataEnumValue enumValue = new ODataEnumValue(value.ToString(), value.GetType().FullName); uriLiteral = ODataUriUtils.ConvertToUriLiteral(enumValue, ODataVersion.V401, model); } else if (edmProperty.Type.IsDateTimeOffset() && value is DateTime) { var dateTime = (DateTime)value; var dateTimeOffsetValue = TimeZoneInfoHelper.ConvertToDateTimeOffset(dateTime); uriLiteral = ODataUriUtils.ConvertToUriLiteral(dateTimeOffsetValue, ODataVersion.V401, model); } else { uriLiteral = ODataUriUtils.ConvertToUriLiteral(value, ODataVersion.V401, model); } skipTokenBuilder.Append(edmProperty.Name).Append(propertyDelimiter).Append(uriLiteral).Append(islast ? String.Empty : CommaDelimiter.ToString()); count++; } return(skipTokenBuilder.ToString()); }
internal static object ConvertUnsupportedPrimitives(object value) { if (value != null) { Type type = value.GetType(); // Note that type cannot be a nullable type as value is not null and it is boxed. switch (Type.GetTypeCode(type)) { case TypeCode.Char: return(new String((char)value, 1)); case TypeCode.UInt16: return((int)(ushort)value); case TypeCode.UInt32: return((long)(uint)value); case TypeCode.UInt64: return(checked ((long)(ulong)value)); case TypeCode.DateTime: DateTime dateTime = (DateTime)value; return(TimeZoneInfoHelper.ConvertToDateTimeOffset(dateTime)); default: if (type == typeof(char[])) { return(new String(value as char[])); } else if (type == typeof(XElement)) { return(((XElement)value).ToString()); } #if NETFX // System.Data.Linq.Binary is only supported in the AspNet version. else if (type == typeof(Binary)) { return(((Binary)value).ToArray()); } #endif break; } } return(value); }
internal static object ConvertUnsupportedPrimitives(object value, TimeZoneInfo timeZoneInfo) { if (value != null) { Type type = value.GetType(); // Note that type cannot be a nullable type as value is not null and it is boxed. switch (Type.GetTypeCode(type)) { case TypeCode.Char: return(new string((char)value, 1)); case TypeCode.UInt16: return((int)(ushort)value); case TypeCode.UInt32: return((long)(uint)value); case TypeCode.UInt64: return(checked ((long)(ulong)value)); case TypeCode.DateTime: DateTime dateTime = (DateTime)value; return(TimeZoneInfoHelper.ConvertToDateTimeOffset(dateTime, timeZoneInfo)); default: if (type == typeof(char[])) { return(new string(value as char[])); } else if (type == typeof(XElement)) { return(((XElement)value).ToString()); } break; } } return(value); }