예제 #1
0
        private static string SerializeValue(ITypeMap typeMap, object value, StringSerializationMode mode = StringSerializationMode.HtmlEncoded)
        {
            var stream = new StringBuilder();

            var protocol = new XRoadProtocol("2.0", new CustomSchemaExporterXRoad20(mode));

            using (var textWriter = new StringWriter(stream))
                using (var writer = XmlWriter.Create(textWriter))
                    using (var message = protocol.CreateMessage())
                    {
                        writer.WriteStartDocument();
                        writer.WriteStartElement("value");
                        typeMap.Serialize(writer, null, value, Globals.GetTestDefinition(typeMap.Definition.Type), message);
                        writer.WriteEndElement();
                        writer.WriteEndDocument();
                    }

            using (var textReader = new StringReader(stream.ToString()))
                using (var reader = XmlReader.Create(textReader))
                {
                    while (reader.Read() && reader.LocalName != "value")
                    {
                    }
                    return(reader.ReadInnerXml());
                }
        }
예제 #2
0
 /// <summary>
 /// Serializes string value with required serialization mode.
 /// </summary>
 public static void WriteStringWithMode(this XmlWriter writer, string value, StringSerializationMode mode)
 {
     if (mode == StringSerializationMode.HtmlEncoded)
     {
         writer.WriteString(value.ToString());
     }
     else
     {
         writer.WriteCDataEscape(value.ToString());
     }
 }
예제 #3
0
        public static void WriteOsuString(this BinaryWriter @this, string value,
                                          StringSerializationMode serializationMode = StringSerializationMode.Full)
        {
            value ??= "";

            if (!string.IsNullOrEmpty(value) || serializationMode == StringSerializationMode.Full)
            {
                var bytes = Encoding.UTF8.GetBytes(value);

                @this.Write((byte)0xB);
                @this.WriteUleb((ulong)bytes.Length);
                @this.Write(bytes);
            }
            else
            {
                @this.Write((byte)0);
            }
        }
예제 #4
0
 public CustomSchemaExporterXRoad20(StringSerializationMode stringSerializationMode = StringSerializationMode.HtmlEncoded)
     : base("test-producer", typeof(Class1).GetTypeInfo().Assembly)
 {
     this.stringSerializationMode = stringSerializationMode;
 }