public static void Serialize(XmlDictionaryWriter writer, IList <DirectoryControl> controls)
        {
            string str;

            if (controls == null || controls.Count == 0)
            {
                return;
            }
            else
            {
                writer.WriteStartElement("ad", "controls", "http://schemas.microsoft.com/2008/1/ActiveDirectory");
                foreach (DirectoryControl control in controls)
                {
                    byte[] value = control.GetValue();
                    writer.WriteStartElement("ad", "control", "http://schemas.microsoft.com/2008/1/ActiveDirectory");
                    writer.WriteAttributeString("type", control.Type.ToLower());
                    XmlDictionaryWriter xmlDictionaryWriter = writer;
                    string str1 = "criticality";
                    if (control.IsCritical)
                    {
                        str = "true";
                    }
                    else
                    {
                        str = "false";
                    }
                    xmlDictionaryWriter.WriteAttributeString(str1, str);
                    if (value != null && (int)value.Length > 0)
                    {
                        writer.WriteStartElement("ad", "controlValue", "http://schemas.microsoft.com/2008/1/ActiveDirectory");
                        XmlUtility.WriteXsiTypeAttribute(writer, "base64Binary");
                        writer.WriteBase64(value, 0, (int)value.Length);
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                return;
            }
        }
Пример #2
0
        public static void Serialize(XmlDictionaryWriter writer, object value)
        {
            string str;

            byte[] numArray;
            object obj;
            bool   flag  = false;
            bool   flag1 = false;

            writer.LookupPrefix("http://www.w3.org/2001/XMLSchema");
            writer.WriteStartElement("value", "http://schemas.microsoft.com/2008/1/ActiveDirectory");
            if (value.GetType() != typeof(byte[]))
            {
                TypeCode typeCode = Type.GetTypeCode(value.GetType());
                if (typeCode == TypeCode.Boolean)
                {
                    str  = "boolean";
                    flag = false;
                    if ((bool)value)
                    {
                        obj = "true";
                    }
                    else
                    {
                        obj = "false";
                    }
                    value = obj;
                    XmlUtility.WriteXsiTypeAttribute(writer, str);
                    if (!flag)
                    {
                        writer.WriteString(value.ToString());
                    }
                    else
                    {
                        if (!flag1)
                        {
                            numArray    = new byte[1];
                            numArray[0] = (byte)value;
                        }
                        else
                        {
                            numArray = (byte[])value;
                        }
                        writer.WriteBase64(numArray, 0, (int)numArray.Length);
                    }
                    writer.WriteEndElement();
                    return;
                }
                else if (typeCode == TypeCode.Char || typeCode == TypeCode.SByte || typeCode == TypeCode.Int16 || typeCode == TypeCode.UInt16 || typeCode == TypeCode.Int32 || typeCode == TypeCode.UInt32)
                {
                    str  = "int";
                    flag = false;
                    XmlUtility.WriteXsiTypeAttribute(writer, str);
                    if (!flag)
                    {
                        writer.WriteString(value.ToString());
                    }
                    else
                    {
                        if (!flag1)
                        {
                            numArray    = new byte[1];
                            numArray[0] = (byte)value;
                        }
                        else
                        {
                            numArray = (byte[])value;
                        }
                        writer.WriteBase64(numArray, 0, (int)numArray.Length);
                    }
                    writer.WriteEndElement();
                    return;
                }
                else if (typeCode == TypeCode.Byte)
                {
                    str   = "base64Binary";
                    flag  = true;
                    flag1 = false;
                    XmlUtility.WriteXsiTypeAttribute(writer, str);
                    if (!flag)
                    {
                        writer.WriteString(value.ToString());
                    }
                    else
                    {
                        if (!flag1)
                        {
                            numArray    = new byte[1];
                            numArray[0] = (byte)value;
                        }
                        else
                        {
                            numArray = (byte[])value;
                        }
                        writer.WriteBase64(numArray, 0, (int)numArray.Length);
                    }
                    writer.WriteEndElement();
                    return;
                }
                else if (typeCode == TypeCode.Int64 || typeCode == TypeCode.UInt64)
                {
                    str  = "long";
                    flag = false;
                    XmlUtility.WriteXsiTypeAttribute(writer, str);
                    if (!flag)
                    {
                        writer.WriteString(value.ToString());
                    }
                    else
                    {
                        if (!flag1)
                        {
                            numArray    = new byte[1];
                            numArray[0] = (byte)value;
                        }
                        else
                        {
                            numArray = (byte[])value;
                        }
                        writer.WriteBase64(numArray, 0, (int)numArray.Length);
                    }
                    writer.WriteEndElement();
                    return;
                }
                else if (typeCode == TypeCode.Single || typeCode == TypeCode.Double || typeCode == TypeCode.Decimal || typeCode == (TypeCode.Object | TypeCode.DateTime))
                {
                }
                else if (typeCode == TypeCode.DateTime)
                {
                    str   = "dateTime";
                    flag  = false;
                    value = XmlConvert.ToString((DateTime)value, XmlDateTimeSerializationMode.Utc);
                    XmlUtility.WriteXsiTypeAttribute(writer, str);
                    if (!flag)
                    {
                        writer.WriteString(value.ToString());
                    }
                    else
                    {
                        if (!flag1)
                        {
                            numArray    = new byte[1];
                            numArray[0] = (byte)value;
                        }
                        else
                        {
                            numArray = (byte[])value;
                        }
                        writer.WriteBase64(numArray, 0, (int)numArray.Length);
                    }
                    writer.WriteEndElement();
                    return;
                }
                else if (typeCode == TypeCode.String)
                {
                    str  = "string";
                    flag = false;
                    XmlUtility.WriteXsiTypeAttribute(writer, str);
                    if (!flag)
                    {
                        writer.WriteString(value.ToString());
                    }
                    else
                    {
                        if (!flag1)
                        {
                            numArray    = new byte[1];
                            numArray[0] = (byte)value;
                        }
                        else
                        {
                            numArray = (byte[])value;
                        }
                        writer.WriteBase64(numArray, 0, (int)numArray.Length);
                    }
                    writer.WriteEndElement();
                    return;
                }
                object[] objArray = new object[1];
                objArray[0] = value.GetType().ToString();
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, StringResources.ADWSXmlParserUnexpectedElement, objArray));
            }
            else
            {
                flag  = true;
                flag1 = true;
                str   = "base64Binary";
            }
            XmlUtility.WriteXsiTypeAttribute(writer, str);
            if (!flag)
            {
                writer.WriteString(value.ToString());
            }
            else
            {
                if (!flag1)
                {
                    numArray    = new byte[1];
                    numArray[0] = (byte)value;
                }
                else
                {
                    numArray = (byte[])value;
                }
                writer.WriteBase64(numArray, 0, (int)numArray.Length);
            }
            writer.WriteEndElement();
        }