private void WriteToXmlPrivate(XmlWriter writer, SerializationContext serializationContext)
 {
     writer.WriteStartElement("Method");
     writer.WriteAttributeString("Name", base.Name);
     writer.WriteAttributeString("Id", base.Id.ToString(CultureInfo.InvariantCulture));
     writer.WriteAttributeString("ObjectPathId", base.Path.Id.ToString(CultureInfo.InvariantCulture));
     if (this.m_version != null)
     {
         writer.WriteAttributeString("Version", this.m_version);
     }
     serializationContext.AddObjectPath(base.Path);
     if (this.m_parameters != null && this.m_parameters.Length > 0)
     {
         writer.WriteStartElement("Parameters");
         for (int i = 0; i < this.m_parameters.Length; i++)
         {
             object objValue = this.m_parameters[i];
             writer.WriteStartElement("Parameter");
             DataConvert.WriteValueToXmlElement(writer, objValue, serializationContext);
             writer.WriteEndElement();
         }
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
 private void WriteToXmlPrivate(XmlWriter writer, SerializationContext serializationContext)
 {
     writer.WriteStartElement("SetStaticProperty");
     writer.WriteAttributeString("Id", base.Id.ToString(CultureInfo.InvariantCulture));
     writer.WriteAttributeString("TypeId", this.m_typeId);
     writer.WriteAttributeString("Name", base.Name);
     writer.WriteStartElement("Parameter");
     DataConvert.WriteValueToXmlElement(writer, this.m_propValue, serializationContext);
     writer.WriteEndElement();
     writer.WriteEndElement();
 }
 public override void WriteToXml(XmlWriter writer, SerializationContext serializationContext)
 {
     if (this.m_data != null)
     {
         writer.WriteStartElement("Property");
         writer.WriteAttributeString("Name", "_Child_Items_");
         writer.WriteAttributeString("Type", "Array");
         foreach (T current in this.m_data)
         {
             writer.WriteStartElement("Object");
             DataConvert.WriteValueToXmlElement(writer, current, serializationContext);
             writer.WriteEndElement();
         }
         writer.WriteEndElement();
     }
     base.WriteToXml(writer, serializationContext);
 }
 private void WriteToXmlPrivate(XmlWriter writer, SerializationContext serializationContext)
 {
     writer.WriteStartElement("Constructor");
     writer.WriteAttributeString("Id", base.Id.ToString(CultureInfo.InvariantCulture));
     writer.WriteAttributeString("TypeId", this.m_typeId);
     if (this.m_parameters != null && this.m_parameters.Length > 0)
     {
         writer.WriteStartElement("Parameters");
         object[] parameters = this.m_parameters;
         for (int i = 0; i < parameters.Length; i++)
         {
             object objValue = parameters[i];
             writer.WriteStartElement("Parameter");
             DataConvert.WriteValueToXmlElement(writer, objValue, serializationContext);
             writer.WriteEndElement();
         }
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
예제 #5
0
 public static void WriteDictionaryToXml(XmlWriter writer, Dictionary <string, object> dict, string topLevelElementTagName, string[] keys, SerializationContext serializationContext)
 {
     if (!string.IsNullOrEmpty(topLevelElementTagName))
     {
         writer.WriteStartElement(topLevelElementTagName);
     }
     foreach (KeyValuePair <string, object> current in dict)
     {
         if (keys == null || Array.IndexOf <string>(keys, current.Key) >= 0)
         {
             writer.WriteStartElement("Property");
             writer.WriteAttributeString("Name", current.Key.ToString());
             object value = current.Value;
             DataConvert.WriteValueToXmlElement(writer, value, serializationContext);
             writer.WriteEndElement();
         }
     }
     if (!string.IsNullOrEmpty(topLevelElementTagName))
     {
         writer.WriteEndElement();
     }
 }
예제 #6
0
        public static void WriteValueToXmlElement(XmlWriter writer, object objValue, SerializationContext serializationContext)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (serializationContext == null)
            {
                throw new ArgumentNullException("serializationContext");
            }
            if (objValue == null)
            {
                writer.WriteAttributeString("Type", "Null");
                return;
            }
            if (!(objValue is ClientObject))
            {
                if (objValue is ClientValueObject)
                {
                    ClientValueObject clientValueObject = (ClientValueObject)objValue;
                    writer.WriteAttributeString("TypeId", clientValueObject.TypeId);
                    if (!clientValueObject.CustomWriteToXml(writer, serializationContext))
                    {
                        clientValueObject.WriteToXml(writer, serializationContext);
                        return;
                    }
                }
                else
                {
                    if (objValue is Stream)
                    {
                        Stream stream = (Stream)objValue;
                        writer.WriteAttributeString("Type", "Binary");
                        writer.WriteStartElement(MtomGlobals.XopIncludeLocalName);
                        string text = "http://sharepoint.microsoft.com/" + serializationContext.Context.NextSequenceId.ToString(CultureInfo.InvariantCulture);
                        serializationContext.AddStream(new StreamInfo(text, stream));
                        writer.WriteAttributeString(MtomGlobals.XopIncludeHrefLocalName, "cid:" + text);
                        writer.WriteEndElement();
                        return;
                    }
                    DataConvert.WriteValueHandler writeValueHandler = null;
                    if (DataConvert.s_writeValueHandlers.TryGetValue(objValue.GetType(), out writeValueHandler))
                    {
                        writer.WriteAttributeString("Type", DataConvert.s_writeValueTypeNames[objValue.GetType()]);
                        writeValueHandler(writer, objValue);
                        return;
                    }
                    if (objValue.GetType().IsArray)
                    {
                        writer.WriteAttributeString("Type", "Array");
                        //Edited for .NET Core
                        //using (IEnumerator enumerator = ((Array)objValue).GetEnumerator())
                        IEnumerator enumerator = ((Array)objValue).GetEnumerator();
                        {
                            while (enumerator.MoveNext())
                            {
                                object current = enumerator.Current;
                                writer.WriteStartElement("Object");
                                DataConvert.WriteValueToXmlElement(writer, current, serializationContext);
                                writer.WriteEndElement();
                            }
                            return;
                        }
                    }
                    if (objValue is IDictionary)
                    {
                        writer.WriteAttributeString("Type", "Dictionary");
                        IDictionary           dictionary  = objValue as IDictionary;
                        IDictionaryEnumerator enumerator2 = dictionary.GetEnumerator();
                        while (enumerator2.MoveNext())
                        {
                            object value = enumerator2.Value;
                            if (DataConvert.CouldSerializeDictionaryEntry(value) && enumerator2.Key is string)
                            {
                                writer.WriteStartElement("Property");
                                writer.WriteAttributeString("Name", (string)enumerator2.Key);
                                DataConvert.WriteValueToXmlElement(writer, enumerator2.Value, serializationContext);
                                writer.WriteEndElement();
                            }
                        }
                        return;
                    }
                    //Edited for .NET Core
                    //if (typeof(IEnumerable).IsAssignableFrom(objValue.GetType()) && ExpressionUtility.GetElementType(objValue.GetType()) != null)

                    if (typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(objValue.GetType()) && ExpressionUtility.GetElementType(objValue.GetType()) != null)
                    {
                        writer.WriteAttributeString("Type", "Array");
                        //Edited for .NET Core
                        //using (IEnumerator enumerator3 = ((IEnumerable)objValue).GetEnumerator())
                        IEnumerator enumerator3 = ((IEnumerable)objValue).GetEnumerator();
                        {
                            while (enumerator3.MoveNext())
                            {
                                object current2 = enumerator3.Current;
                                writer.WriteStartElement("Object");
                                DataConvert.WriteValueToXmlElement(writer, current2, serializationContext);
                                writer.WriteEndElement();
                            }
                            return;
                        }
                    }
                    Type type = objValue.GetType();
                    //Edited for .NET Core
                    //if (type.IsEnum)
                    if (type.GetTypeInfo().IsEnum)
                    {
                        writer.WriteAttributeString("Type", "Enum");
                        DataConvert.s_writeValueEnum(writer, objValue);
                        return;
                    }
                    writer.WriteAttributeString("Type", "Unspecified");
                    writer.WriteString(objValue.ToString());
                }
                return;
            }
            ClientObject clientObject = (ClientObject)objValue;

            if (clientObject.Path == null)
            {
                throw new ClientRequestException(Resources.GetString("NoObjectPathAssociatedWithObject"));
            }
            ClientAction.CheckActionParameterInContext(serializationContext.Context, clientObject);
            writer.WriteAttributeString("ObjectPathId", clientObject.Path.Id.ToString(CultureInfo.InvariantCulture));
            serializationContext.AddClientObject(clientObject);
        }
        //Edited for .NET Core
        private void Write(Expression exp)
        {
            ExpressionType nodeType = exp.NodeType;

            switch (nodeType)
            {
            case ExpressionType.AndAlso:
            case ExpressionType.GreaterThan:
            case ExpressionType.GreaterThanOrEqual:
            case ExpressionType.LessThan:
            case ExpressionType.LessThanOrEqual:
                break;

            case ExpressionType.ArrayLength:
            case ExpressionType.ArrayIndex:
            case ExpressionType.Coalesce:
            case ExpressionType.Conditional:
            case ExpressionType.Divide:
            case ExpressionType.ExclusiveOr:
            case ExpressionType.Invoke:
            case ExpressionType.Lambda:
            case ExpressionType.LeftShift:
            case ExpressionType.ListInit:
                goto IL_71A;

            case ExpressionType.Call:
            {
                MethodCallExpression methodCallExpression = (MethodCallExpression)exp;
                bool flag = false;
                if (methodCallExpression.Object == null)
                {
                    flag = true;
                    this.m_writer.WriteStartElement("ExpressionStaticMethod");
                    string serverTypeId = ConditionalExpressionToXmlConverter.GetServerTypeId(methodCallExpression.Method.DeclaringType);
                    if (string.IsNullOrEmpty(serverTypeId))
                    {
                        throw new ClientRequestException(Resources.GetString("NotSupportedExpression", new object[]
                            {
                                this.m_condition.ToString()
                            }));
                    }
                    this.m_writer.WriteAttributeString("TypeId", serverTypeId);
                    this.m_writer.WriteAttributeString("Name", ConditionalExpressionToXmlConverter.GetMemberName(methodCallExpression.Method));
                }
                else
                {
                    this.m_writer.WriteStartElement("ExpressionMethod");
                    this.m_writer.WriteAttributeString("Name", ConditionalExpressionToXmlConverter.GetMemberName(methodCallExpression.Method));
                    this.Write(methodCallExpression.Object);
                }
                this.m_writer.WriteStartElement("Parameters");
                foreach (Expression current in methodCallExpression.Arguments)
                {
                    if (flag)
                    {
                        flag = false;
                    }
                    else
                    {
                        this.Write(current);
                    }
                }
                this.m_writer.WriteEndElement();
                this.m_writer.WriteEndElement();
                return;
            }

            case ExpressionType.Constant:
            {
                ConstantExpression constantExpression = (ConstantExpression)exp;
                object             value = constantExpression.Value;

                //Edited for .NET Core
                //if (value == null || value is ClientObject || value is ClientValueObject || value.GetType().IsPrimitive || value.GetType().IsEnum || value.GetType() == typeof(Guid) || value.GetType() == typeof(DateTime) || value.GetType() == typeof(string))
                if (value == null || value is ClientObject || value is ClientValueObject || value.GetType().GetTypeInfo().IsPrimitive || value.GetType().GetTypeInfo().IsEnum || value.GetType() == typeof(Guid) || value.GetType() == typeof(DateTime) || value.GetType() == typeof(string))
                {
                    this.m_writer.WriteStartElement("ExpressionConstant");
                    DataConvert.WriteValueToXmlElement(this.m_writer, value, this.m_serializationContext);
                    this.m_writer.WriteEndElement();
                    return;
                }
                throw new ClientRequestException(Resources.GetString("NotSupportedExpression", new object[]
                    {
                        this.m_condition.ToString()
                    }));
            }

            case ExpressionType.Convert:
            case ExpressionType.ConvertChecked:
            {
                UnaryExpression unaryExpression = (UnaryExpression)exp;
                string          value2          = null;
                string          value3          = null;
                DataConvert.GetTypeNameOrTypeId(unaryExpression.Type, out value2, out value3);
                if (!string.IsNullOrEmpty(value2))
                {
                    this.m_writer.WriteStartElement("ExpressionConvert");
                    this.m_writer.WriteAttributeString("Type", value2);
                    this.Write(unaryExpression.Operand);
                    this.m_writer.WriteEndElement();
                    return;
                }
                if (string.IsNullOrEmpty(value3))
                {
                    throw new ClientRequestException(Resources.GetString("NotSupportedExpression", new object[]
                        {
                            this.m_condition.ToString()
                        }));
                }
                if (this.m_serializationContext.Context.RequestSchemaVersion >= ClientSchemaVersions.Version15)
                {
                    this.m_writer.WriteStartElement("ExpressionConvert");
                    this.m_writer.WriteAttributeString("TypeId", value3);
                    this.Write(unaryExpression.Operand);
                    this.m_writer.WriteEndElement();
                    return;
                }
                this.Write(unaryExpression.Operand);
                return;
            }

            case ExpressionType.Equal:
                goto IL_D7;

            case ExpressionType.MemberAccess:
            {
                MemberExpression memberExpression = (MemberExpression)exp;
                if (!(memberExpression.Member is PropertyInfo))
                {
                    throw new ClientRequestException(Resources.GetString("NotSupportedExpression", new object[]
                        {
                            this.m_condition.ToString()
                        }));
                }
                if (ConditionalExpressionToXmlConverter.IsClientResultValueExpression(memberExpression))
                {
                    this.Write(memberExpression.Expression);
                    return;
                }
                if (ConditionalExpressionToXmlConverter.IsServerObjectIsNullValue(memberExpression))
                {
                    this.Write(memberExpression.Expression);
                    return;
                }
                if (memberExpression.Expression != null)
                {
                    this.m_writer.WriteStartElement("ExpressionProperty");
                    this.m_writer.WriteAttributeString("Name", ConditionalExpressionToXmlConverter.GetMemberName(memberExpression.Member));
                    this.Write(memberExpression.Expression);
                    this.m_writer.WriteEndElement();
                    return;
                }
                this.m_writer.WriteStartElement("ExpressionStaticProperty");
                string serverTypeId2 = ConditionalExpressionToXmlConverter.GetServerTypeId(memberExpression.Member.DeclaringType);
                if (string.IsNullOrEmpty(serverTypeId2))
                {
                    throw new ClientRequestException(Resources.GetString("NotSupportedExpression", new object[]
                        {
                            this.m_condition.ToString()
                        }));
                }
                this.m_writer.WriteAttributeString("TypeId", serverTypeId2);
                this.m_writer.WriteAttributeString("Name", ConditionalExpressionToXmlConverter.GetMemberName(memberExpression.Member));
                this.m_writer.WriteEndElement();
                return;
            }

            default:
                switch (nodeType)
                {
                case ExpressionType.Not:
                {
                    this.m_writer.WriteStartElement(ConditionalExpressionToXmlConverter.s_opNames[exp.NodeType]);
                    UnaryExpression unaryExpression2 = (UnaryExpression)exp;
                    this.Write(unaryExpression2.Operand);
                    this.m_writer.WriteEndElement();
                    return;
                }

                case ExpressionType.NotEqual:
                    goto IL_D7;

                case ExpressionType.Or:
                    goto IL_71A;

                case ExpressionType.OrElse:
                    break;

                case ExpressionType.Parameter:
                {
                    ParameterExpression parameterExpression = (ParameterExpression)exp;
                    this.m_writer.WriteStartElement("ExpressionParameter");
                    this.m_writer.WriteAttributeString("Name", parameterExpression.Name);
                    this.m_writer.WriteEndElement();
                    return;
                }

                default:
                {
                    if (nodeType != ExpressionType.TypeIs)
                    {
                        goto IL_71A;
                    }
                    TypeBinaryExpression typeBinaryExpression = (TypeBinaryExpression)exp;
                    string value4 = null;
                    string value5 = null;
                    DataConvert.GetTypeNameOrTypeId(typeBinaryExpression.TypeOperand, out value4, out value5);
                    if (string.IsNullOrEmpty(value4) && string.IsNullOrEmpty(value5))
                    {
                        throw new ClientRequestException(Resources.GetString("NotSupportedExpression", new object[]
                            {
                                this.m_condition.ToString()
                            }));
                    }
                    this.m_writer.WriteStartElement("ExpressionTypeIs");
                    if (!string.IsNullOrEmpty(value4))
                    {
                        this.m_writer.WriteAttributeString("Type", value4);
                    }
                    if (!string.IsNullOrEmpty(value5))
                    {
                        this.m_writer.WriteAttributeString("TypeId", value5);
                    }
                    this.Write(typeBinaryExpression.Expression);
                    this.m_writer.WriteEndElement();
                    return;
                }
                }
                break;
            }
            BinaryExpression binaryExpression = (BinaryExpression)exp;

            this.m_writer.WriteStartElement(ConditionalExpressionToXmlConverter.s_opNames[exp.NodeType]);
            this.Write(binaryExpression.Left);
            this.Write(binaryExpression.Right);
            this.m_writer.WriteEndElement();
            return;

IL_D7:
            BinaryExpression binaryExpression2 = (BinaryExpression)exp;

            if (ConditionalExpressionToXmlConverter.IsNullExpression(binaryExpression2.Left) || ConditionalExpressionToXmlConverter.IsNullExpression(binaryExpression2.Right) || (ConditionalExpressionToXmlConverter.IsSupportedEqualType(binaryExpression2.Right.Type) && ConditionalExpressionToXmlConverter.IsSupportedEqualType(binaryExpression2.Left.Type)))
            {
                this.m_writer.WriteStartElement(ConditionalExpressionToXmlConverter.s_opNames[exp.NodeType]);
                this.Write(binaryExpression2.Left);
                this.Write(binaryExpression2.Right);
                this.m_writer.WriteEndElement();
                return;
            }
            throw new ClientRequestException(Resources.GetString("NotSupportedExpression", new object[]
            {
                this.m_condition.ToString()
            }));
IL_71A:
            throw new ClientRequestException(Resources.GetString("NotSupportedExpression", new object[]
            {
                this.m_condition.ToString()
            }));
        }