/// <summary>
 /// Provide additional serialization information to the <see cref="ODataWriter"/> for <paramref name="nestedResourceInfo"/>.
 /// </summary>
 /// <param name="nestedResourceInfo">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataNestedResourceInfo nestedResourceInfo, ODataNestedResourceInfoSerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(nestedResourceInfo, "resource");
     nestedResourceInfo.SerializationInfo = serializationInfo;
 }
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataDeltaWriter"/> for <paramref name="deltalink"/>.
 /// </summary>
 /// <param name="deltalink">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataDeltaLinkBase deltalink, ODataDeltaSerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(deltalink, "deltalink");
     deltalink.SerializationInfo = serializationInfo;
 }
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataWriter"/> for <paramref name="resource"/>.
 /// </summary>
 /// <param name="resource">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataResource resource, ODataResourceSerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(resource, "resource");
     resource.SerializationInfo = serializationInfo;
 }
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataDeltaWriter"/> for <paramref name="deltaResourceSet"/>.
 /// </summary>
 /// <param name="deltaResourceSet">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataDeltaResourceSet deltaResourceSet, ODataResourceSerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(deltaResourceSet, "deltaResourceSet");
     deltaResourceSet.SerializationInfo = serializationInfo;
 }
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataDeltaWriter"/> for <paramref name="deltaDeletedEntry"/>.
 /// </summary>
 /// <param name="deltaDeletedEntry">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataDeltaDeletedEntry deltaDeletedEntry, ODataDeltaSerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(deltaDeletedEntry, "deltaDeletedEntry");
     deltaDeletedEntry.SerializationInfo = serializationInfo;
 }
Esempio n. 6
0
        /// <summary>
        ///  Initializes a new instance of the <see cref="Microsoft.OData.ODataInnerError" /> class with a dictionary of property names and corresponding ODataValues.
        /// </summary>
        /// <param name="properties">Dictionary of string keys with ODataValue as value. Key string indicates the property name where as the value of the property is encapsulated in ODataValue.</param>
        public ODataInnerError(IDictionary <string, ODataValue> properties)
        {
            ExceptionUtils.CheckArgumentNotNull(properties, "properties");

            Properties = new Dictionary <string, ODataValue>(properties);
        }
 /// <summary>
 /// Gets the <see cref="ODataPreferenceHeader"/> instance to get or set preferences on the "Preference-Applied" header of the <paramref name="responseMessage"/>.
 /// </summary>
 /// <param name="responseMessage">The response message to get or set the "Preference-Applied" header.</param>
 /// <returns>Returns the <see cref="ODataPreferenceHeader"/> instance to get or set preferences on the "Preference-Applied" header of the <paramref name="responseMessage"/>.</returns>
 public static ODataPreferenceHeader PreferenceAppliedHeader(this IODataResponseMessage responseMessage)
 {
     ExceptionUtils.CheckArgumentNotNull(responseMessage, "responseMessage");
     return(new ODataPreferenceHeader(responseMessage));
 }
 /// <summary>
 /// Translates a <see cref="ParameterAliasNode"/> into a corresponding <see cref="String"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated String.</returns>
 public override String Visit(ParameterAliasNode node)
 {
     ExceptionUtils.CheckArgumentNotNull(node, "node");
     return(node.Alias);
 }
 /// <summary>
 /// Translates a <see cref="NamedFunctionParameterNode"/> into a corresponding <see cref="String"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated String of NamedFunctionParameterNode.</returns>
 public override string Visit(NamedFunctionParameterNode node)
 {
     ExceptionUtils.CheckArgumentNotNull(node, "node");
     return(String.Concat(node.Name, ExpressionConstants.SymbolEqual, this.TranslateNode(node.Value)));
 }
Esempio n. 10
0
 /// <summary>
 /// Translates an <see cref="CollectionOpenPropertyAccessNode"/> into a corresponding <see cref="String"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated String.</returns>
 public override String Visit(CollectionOpenPropertyAccessNode node)
 {
     ExceptionUtils.CheckArgumentNotNull(node, "node");
     return(this.TranslatePropertyAccess(node.Source, node.Name));
 }
Esempio n. 11
0
 /// <summary>
 /// Translates a <see cref="SingleComplexNode"/> into a corresponding <see cref="String"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated String.</returns>
 public override String Visit(SingleComplexNode node)
 {
     ExceptionUtils.CheckArgumentNotNull(node, "node");
     return(this.TranslatePropertyAccess(node.Source, node.Property.Name));
 }
Esempio n. 12
0
 /// <summary>
 /// Translates a <see cref="SingleResourceCastNode"/> into a corresponding <see cref="String"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated String.</returns>
 public override String Visit(SingleResourceCastNode node)
 {
     ExceptionUtils.CheckArgumentNotNull(node, "node");
     return(this.TranslatePropertyAccess(node.Source, node.StructuredTypeReference.Definition.ToString()));
 }
Esempio n. 13
0
 /// <summary>
 /// Translates a <see cref="NonResourceRangeVariableReferenceNode"/> into a corresponding <see cref="String"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated String.</returns>
 public override String Visit(NonResourceRangeVariableReferenceNode node)
 {
     ExceptionUtils.CheckArgumentNotNull(node, "node");
     return(node.Name);
 }
Esempio n. 14
0
 /// <summary>
 /// Translates a <see cref="ConvertNode"/> into a corresponding <see cref="String"/>.
 /// </summary>
 /// <param name="node">The node to translate.</param>
 /// <returns>The translated String.</returns>
 public override String Visit(ConvertNode node)
 {
     ExceptionUtils.CheckArgumentNotNull(node, "node");
     return(this.TranslateNode(node.Source));
 }
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataWriter"/> for <paramref name="property"/>.
 /// </summary>
 /// <param name="property">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataProperty property, ODataPropertySerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(property, "property");
     property.SerializationInfo = serializationInfo;
 }
Esempio n. 16
0
        internal static object CoerceNumericType(object primitiveValue, IEdmPrimitiveType targetEdmType)
        {
            // This is implemented to match TypePromotionUtils and MetadataUtilsCommon.CanConvertPrimitiveTypeTo()
            ExceptionUtils.CheckArgumentNotNull(primitiveValue, "primitiveValue");
            ExceptionUtils.CheckArgumentNotNull(targetEdmType, "targetEdmType");

            EdmPrimitiveTypeKind targetPrimitiveKind = targetEdmType.PrimitiveKind;

            if (primitiveValue is SByte)
            {
                switch (targetPrimitiveKind)
                {
                case EdmPrimitiveTypeKind.SByte:
                    return(primitiveValue);

                case EdmPrimitiveTypeKind.Int16:
                    return(Convert.ToInt16((SByte)primitiveValue));

                case EdmPrimitiveTypeKind.Int32:
                    return(Convert.ToInt32((SByte)primitiveValue));

                case EdmPrimitiveTypeKind.Int64:
                    return(Convert.ToInt64((SByte)primitiveValue));

                case EdmPrimitiveTypeKind.Single:
                    return(Convert.ToSingle((SByte)primitiveValue));

                case EdmPrimitiveTypeKind.Double:
                    return(Convert.ToDouble((SByte)primitiveValue));

                case EdmPrimitiveTypeKind.Decimal:
                    return(Convert.ToDecimal((SByte)primitiveValue));
                }
            }

            if (primitiveValue is Byte)
            {
                switch (targetPrimitiveKind)
                {
                case EdmPrimitiveTypeKind.Byte:
                    return(primitiveValue);

                case EdmPrimitiveTypeKind.Int16:
                    return(Convert.ToInt16((Byte)primitiveValue));

                case EdmPrimitiveTypeKind.Int32:
                    return(Convert.ToInt32((Byte)primitiveValue));

                case EdmPrimitiveTypeKind.Int64:
                    return(Convert.ToInt64((Byte)primitiveValue));

                case EdmPrimitiveTypeKind.Single:
                    return(Convert.ToSingle((Byte)primitiveValue));

                case EdmPrimitiveTypeKind.Double:
                    return(Convert.ToDouble((Byte)primitiveValue));

                case EdmPrimitiveTypeKind.Decimal:
                    return(Convert.ToDecimal((Byte)primitiveValue));
                }
            }

            if (primitiveValue is Int16)
            {
                switch (targetPrimitiveKind)
                {
                case EdmPrimitiveTypeKind.Int16:
                    return(primitiveValue);

                case EdmPrimitiveTypeKind.Int32:
                    return(Convert.ToInt32((Int16)primitiveValue));

                case EdmPrimitiveTypeKind.Int64:
                    return(Convert.ToInt64((Int16)primitiveValue));

                case EdmPrimitiveTypeKind.Single:
                    return(Convert.ToSingle((Int16)primitiveValue));

                case EdmPrimitiveTypeKind.Double:
                    return(Convert.ToDouble((Int16)primitiveValue));

                case EdmPrimitiveTypeKind.Decimal:
                    return(Convert.ToDecimal((Int16)primitiveValue));
                }
            }

            if (primitiveValue is Int32)
            {
                switch (targetPrimitiveKind)
                {
                case EdmPrimitiveTypeKind.Int32:
                    return(primitiveValue);

                case EdmPrimitiveTypeKind.Int64:
                    return(Convert.ToInt64((Int32)primitiveValue));

                case EdmPrimitiveTypeKind.Single:
                    return(Convert.ToSingle((Int32)primitiveValue));

                case EdmPrimitiveTypeKind.Double:
                    return(Convert.ToDouble((Int32)primitiveValue));

                case EdmPrimitiveTypeKind.Decimal:
                    return(Convert.ToDecimal((Int32)primitiveValue));
                }
            }

            if (primitiveValue is Int64)
            {
                switch (targetPrimitiveKind)
                {
                case EdmPrimitiveTypeKind.Int64:
                    return(primitiveValue);

                case EdmPrimitiveTypeKind.Single:
                    return(Convert.ToSingle((Int64)primitiveValue));

                case EdmPrimitiveTypeKind.Double:
                    return(Convert.ToDouble((Int64)primitiveValue));

                case EdmPrimitiveTypeKind.Decimal:
                    return(Convert.ToDecimal((Int64)primitiveValue));
                }
            }

            if (primitiveValue is Single)
            {
                switch (targetPrimitiveKind)
                {
                case EdmPrimitiveTypeKind.Single:
                    return(primitiveValue);

                case EdmPrimitiveTypeKind.Double:
                    /*to string then to double, avoid losing precision like "(double)123.001f" which is 123.00099945068359, instead of 123.001d.*/
                    return(double.Parse(((Single)primitiveValue).ToString("R", CultureInfo.InvariantCulture),
                                        CultureInfo.InvariantCulture));

                case EdmPrimitiveTypeKind.Decimal:
                    return(Convert.ToDecimal((Single)primitiveValue));
                }
            }

            if (primitiveValue is Double)
            {
                switch (targetPrimitiveKind)
                {
                case EdmPrimitiveTypeKind.Double:
                    return(primitiveValue);

                case EdmPrimitiveTypeKind.Decimal:
                    // TODO: extract these convertion steps to an individual function
                    decimal doubleToDecimalR;

                    // To keep the full presion of the current value, which if necessary is all 17 digits of precision supported by the Double type.
                    if (decimal.TryParse(((Double)primitiveValue).ToString("R", CultureInfo.InvariantCulture),
                                         out doubleToDecimalR))
                    {
                        return(doubleToDecimalR);
                    }

                    return(Convert.ToDecimal((Double)primitiveValue));
                }
            }

            if (primitiveValue is Decimal)
            {
                switch (targetPrimitiveKind)
                {
                case EdmPrimitiveTypeKind.Decimal:
                    return(primitiveValue);
                }
            }

            return(null);
        }
 /// <summary>
 /// Provide additional serialization information to the <see cref="ODataCollectionWriter"/> for <paramref name="collectionStart"/>.
 /// </summary>
 /// <param name="collectionStart">The instance to set the serialization info.</param>
 /// <param name="serializationInfo">The serialization info to set.</param>
 public static void SetSerializationInfo(this ODataCollectionStart collectionStart, ODataCollectionStartSerializationInfo serializationInfo)
 {
     ExceptionUtils.CheckArgumentNotNull(collectionStart, "collectionStart");
     collectionStart.SerializationInfo = serializationInfo;
 }
        /// <summary>
        /// Build the expand clause for a given level in the selectExpandClause
        /// </summary>
        /// <param name="selectExpandClause">the current level select expand clause</param>
        /// <param name="firstFlag">whether is inner SelectExpandClause</param>
        /// <returns>the select and expand segment for context url in this level.</returns>
        public string TranslateSelectExpandClause(SelectExpandClause selectExpandClause, bool firstFlag)
        {
            ExceptionUtils.CheckArgumentNotNull(selectExpandClause, "selectExpandClause");

            List <string> selectList   = selectExpandClause.GetCurrentLevelSelectList();
            string        selectClause = null;

            if (selectList.Any())
            {
                selectClause = String.Join(ODataConstants.ContextUriProjectionPropertySeparator, selectList.ToArray());
            }

            selectClause      = string.IsNullOrEmpty(selectClause) ? null : string.Concat("$select", ExpressionConstants.SymbolEqual, isFirstSelectItem ? Uri.EscapeDataString(selectClause) : selectClause);
            isFirstSelectItem = false;

            string expandClause = null;

            foreach (ExpandedNavigationSelectItem expandSelectItem in selectExpandClause.SelectedItems.Where(I => I.GetType() == typeof(ExpandedNavigationSelectItem)))
            {
                if (string.IsNullOrEmpty(expandClause))
                {
                    expandClause = firstFlag ? expandClause : string.Concat("$expand", ExpressionConstants.SymbolEqual);
                }
                else
                {
                    expandClause += ExpressionConstants.SymbolComma;
                }

                expandClause += this.Translate(expandSelectItem);
            }

            foreach (ExpandedReferenceSelectItem expandSelectItem in selectExpandClause.SelectedItems.Where(I => I.GetType() == typeof(ExpandedReferenceSelectItem)))
            {
                if (string.IsNullOrEmpty(expandClause))
                {
                    expandClause = firstFlag ? expandClause : string.Concat("$expand", ExpressionConstants.SymbolEqual);
                }
                else
                {
                    expandClause += ExpressionConstants.SymbolComma;
                }

                expandClause += this.Translate(expandSelectItem) + "/$ref";
            }

            if (string.IsNullOrEmpty(expandClause))
            {
                return(selectClause);
            }
            else
            {
                if (firstFlag)
                {
                    return(string.IsNullOrEmpty(selectClause) ? string.Concat("$expand=", Uri.EscapeDataString(expandClause)) : string.Concat(selectClause, "&$expand=", Uri.EscapeDataString(expandClause)));
                }
                else
                {
                    return(string.IsNullOrEmpty(selectClause) ? expandClause : string.Concat(selectClause, ";" + expandClause));
                }
            }
        }
Esempio n. 19
0
 /// <summary>Returns the format used by the message reader for reading the payload.</summary>
 /// <returns>The format used by the messageReader for reading the payload.</returns>
 /// <param name="messageReader">The <see cref="T:Microsoft.OData.ODataMessageReader" /> to get the read format from.</param>
 /// <remarks>This method must only be called once reading has started.
 /// This means that a read method has been called on the <paramref name="messageReader"/> or that a reader (for entries, resource sets, collections, etc.) has been created.
 /// If the method is called prior to that it will throw.</remarks>
 public static ODataFormat GetReadFormat(ODataMessageReader messageReader)
 {
     ExceptionUtils.CheckArgumentNotNull(messageReader, "messageReader");
     return(messageReader.GetFormat());
 }
Esempio n. 20
0
 /// <summary>
 /// Sets the custom instance annotations.
 /// </summary>
 /// <param name="value">The new value to set.</param>
 internal void SetInstanceAnnotations(ICollection <ODataInstanceAnnotation> value)
 {
     ExceptionUtils.CheckArgumentNotNull(value, "value");
     this.instanceAnnotations = value;
 }