System.Text.Encoding.GetBytes(string)

Here are the examples of the csharp api class System.Text.Encoding.GetBytes(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

200 Examples 7

1. Example

Project: alphaTab
Source File: MidiFileGeneratorTest.cs
private Score ParseTex(string tex)
        {
            var import = new AlphaTexImporter();
            import.Init(new StreamWrapper(new MemoryStream(Encoding.UTF8.GetBytes(tex))));
            return import.ReadScore();
        }

2. Example

Project: alphaTab
Source File: AlphaTexImporterTest.cs
private Score ParseTex(string tex)
        {
            var import = new AlphaTexImporter();
            import.Init(new StreamWrapper(new MemoryStream(Encoding.UTF8.GetBytes(tex))));
            return import.ReadScore();
        }

3. Example

Project: TraceLab
Source File: Heaps.cs
protected override void WriteImpl(MetadataWriter mw)
		{
			foreach (string str in list)
			{
				mw.Write(System.Text.Encoding.UTF8.GetBytes(str));
				mw.Write((byte)0);
			}
		}

4. Example

Project: TraceLab
Source File: MarshalSpec.cs
private static void WriteString(ByteBuffer bb, string str)
		{
			byte[] buf = Encoding.UTF8.GetBytes(str);
			bb.WriteCompressedInt(buf.Length);
			bb.Write(buf);
		}

5. Example

Project: TraceLab
Source File: StreamManagerTests.cs
public static byte[] StrToByteArray(string str)
        {
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            return encoding.GetBytes(str);
        }

6. Example

Project: confluent-kafka-dotnet
Source File: StringSerializer.cs
public byte[] Serialize(string topic, string data)
        {
            if (data == null)
            {
                return null;
            }

            return encoding.GetBytes(data);
        }

7. Example

Project: ContinuousTests
Source File: AssemblyWriter.cs
public void WriteUTF8String (string @string)
		{
			if (@string == null) {
				WriteByte (0xff);
				return;
			}

			var bytes = Encoding.UTF8.GetBytes (@string);
			WriteCompressedUInt32 ((uint) bytes.Length);
			WriteBytes (bytes);
		}

8. Example

Project: ContinuousTests
Source File: AssemblyWriter.cs
public void WriteConstantString (string value)
		{
			WriteBytes (Encoding.Unicode.GetBytes (value));
		}

9. Example

Project: ContinuousTests
Source File: Buffers.cs
protected virtual void WriteString (string @string)
		{
			WriteBytes (Encoding.UTF8.GetBytes (@string));
			WriteByte (0);
		}

10. Example

Project: FluentCache
Source File: DistributedStorage.cs
public byte[] ToBytes(ISerializer serializer)
        {
            string serializedValue = serializer.Serialize(this);
            return Encoding.UTF8.GetBytes(serializedValue);
        }

11. Example

Project: QuickUnity
Source File: MonoSerialPortTest.cs
public ISerialPortPacket Pack(object data)
            {
                byte[] bytes = Encoding.Default.GetBytes((string)data);
                return new TestSerialPortPacket(bytes);
            }

12. Example

Project: xRM-Portals-Community-Edition
Source File: PaymentHandler.cs
protected virtual void LogPaymentRequest(HttpContext context, PortalConfigurationDataAdapterDependencies dataAdapterDependencies, Tuple<Guid, string> quoteAndReturnUrl, string subject, string log)
		{
			var dataAdapter = new AnnotationDataAdapter(dataAdapterDependencies);
			var note = new Annotation
			{
				Subject = subject,
				Regarding = new EntityReference("quote", quoteAndReturnUrl.Item1),
				FileAttachment = AnnotationDataAdapter.CreateFileAttachment("log.txt", "text/plain", Encoding.UTF8.GetBytes(log))
			};
			dataAdapter.CreateAnnotation(note);
		}

13. Example

Project: memcache-driver
Source File: UTF8KeySerializer.cs
protected override byte[] DoSerializeToBytes(string value)
        {
            if (value == null)
                return null;

            return Encoding.UTF8.GetBytes(value);
        }

14. Example

Project: memcache-driver
Source File: AsyncLinesStreamReaderTests.cs
private void SendRaw(string str)
        {
            var data = Encoding.UTF8.GetBytes(str);

            _pipe.In.Write(data, 0, data.Length);
            _pipe.In.Flush();
        }

15. Example

Project: spectre
Source File: StringExtensions.cs
public static MemoryStream ToUtf8Stream(this string input) {
            return new MemoryStream(Encoding.UTF8.GetBytes(input));
        }

16. Example

Project: cat.net
Source File: PlainTextMessageCodec.cs
public int Write(ChannelBuffer buf, String str)
            {
                if (str == null)
                {
                    str = "null";
                }

                byte[] data = _mEncoding.GetBytes(str);

                buf.WriteBytes(data);
                return data.Length;
            }

17. Example

Project: cat.net
Source File: PlainTextMessageCodec.cs
public int WriteRaw(ChannelBuffer buf, String str)
            {
                if (str == null)
                {
                    str = "null";
                }

                byte[] data = _mEncoding.GetBytes(str);

                int len = data.Length;
                int count = len;
                int offset = 0;

                for (int i = 0; i < len; i++)
                {
                    byte b = data[i];

                    if (b == '\t' || b == '\r' || b == '\n' || b == '\\')
                    {
                        buf.WriteBytes(data, offset, i - offset);
                        buf.WriteByte('\\');

                        if (b == '\t')
                        {
                            buf.WriteByte('t');
                        }
                        else if (b == '\r')
                        {
                            buf.WriteByte('r');
                        }
                        else if (b == '\n')
                        {
                            buf.WriteByte('n');
                        }
                        else
                        {
                            buf.WriteByte(b);
                        }

                        count++;
                        offset = i + 1;
                    }
                }

                if (len > offset)
                {
                    buf.WriteBytes(data, offset, len - offset);
                }

                return count;
            }

18. Example

Project: Partial-Key-Verification
Source File: PartialKeyValidator.cs
public static uint GetSerialNumberFromSeed(string seed)
        {
            return Hash.Compute(Encoding.UTF8.GetBytes(seed));
        }

19. Example

Project: csharp-swift
Source File: UnitTests.cs
private Stream _to_stream(string to_stream)
		{
			return new MemoryStream(Encoding.UTF8.GetBytes(to_stream));
		}

20. Example

Project: BotBuilder.Standard
Source File: FacebookHelpers.cs
public static string TokenEncoder(string token)
        {
            return WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(token));
        }

21. Example

Project: meridian59-dotnet
Source File: SupportClass.cs
public static byte[] ToByteArray(System.String sourceString)
		{
			return System.Text.UTF8Encoding.UTF8.GetBytes(sourceString);
		}

22. Example

Project: Unity3D.Amqp
Source File: PlainMechanism.cs
public byte[] handleChallenge(byte[] challenge, IConnectionFactory factory) {

            return Encoding.UTF8.GetBytes("\0" + factory.UserName +
                                          "\0" + factory.Password);
        }

23. Example

Project: Unity3D.Amqp
Source File: PlainMechanism.cs
public byte[] handleChallenge(byte[] challenge, IConnectionFactory factory) {

            return Encoding.UTF8.GetBytes("\0" + factory.UserName +
                                          "\0" + factory.Password);
        }

24. Example

Project: CypherCore
Source File: ByteString.cs
public static ByteString CopyFrom(string text, Encoding encoding)
        {
            return new ByteString(encoding.GetBytes(text));
        }

25. Example

Project: Daishi.Armor
Source File: ArmorTokenDeserialisor.cs
public void Execute() {
            var armorTokenBytes = Encoding.UTF8.GetBytes(serialisedArmorToken);

            using (Stream stream = new MemoryStream(armorTokenBytes)) {
                var parser = new ArmorTokenJsonParser(stream, "claims");
                parser.Parse();

                DeserialisedArmorToken = parser.Result.SingleOrDefault();
            }
        }

26. Example

Project: mynatsclient
Source File: NatsEncoder.cs
internal static byte[] GetBytes(string data) => Encoding.GetBytes(data);

27. Example

Project: mcs-ICodeCompiler
Source File: CustomAttributeBuilder.cs
internal int WriteLegacyDeclSecurityBlob(ModuleBuilder moduleBuilder)
		{
			if (blob != null)
			{
				return moduleBuilder.Blobs.Add(ByteBuffer.Wrap(blob));
			}
			else
			{
				return moduleBuilder.Blobs.Add(ByteBuffer.Wrap(Encoding.Unicode.GetBytes((string)propertyValues[0])));
			}
		}

28. Example

Project: mcs-ICodeCompiler
Source File: Heaps.cs
protected override void WriteImpl(MetadataWriter mw)
		{
			foreach (string str in list)
			{
				mw.Write(System.Text.Encoding.UTF8.GetBytes(str));
				mw.Write((byte)0);
			}
		}

29. Example

Project: mcs-ICodeCompiler
Source File: MarshalSpec.cs
private static void WriteString(ByteBuffer bb, string str)
		{
			byte[] buf = Encoding.UTF8.GetBytes(str);
			bb.WriteCompressedUInt(buf.Length);
			bb.Write(buf);
		}

30. Example

Project: csharp-sparkpost
Source File: FileTests.cs
private byte[] GetBytes(string input)
        {
            return Encoding.ASCII.GetBytes(input);
        }

31. Example

Project: csharp-driver
Source File: StringSerializer.cs
public override byte[] Serialize(ushort protocolVersion, string value)
        {
            return _encoding.GetBytes(value);
        }

32. Example

Project: csharp-driver
Source File: OPPToken.cs
public override IToken Parse(string tokenStr)
            {
                return new OPPToken(Encoding.UTF8.GetBytes(tokenStr));
            }

33. Example

Project: csharp-driver
Source File: ClientWarningsTests.cs
private static IDictionary<string, byte[]> GetPayload()
        {
            return new Dictionary<string, byte[]>
            {
                {"k1", Encoding.UTF8.GetBytes("value1")},
                {"k2", Encoding.UTF8.GetBytes("value2")}
            };
        }

34. Example

Project: csharp-driver
Source File: CustomPayloadTests.cs
[Test, TestCassandraVersion(2, 2)]
        public void Query_Payload_Test()
        {
            var outgoing = new Dictionary<string, byte[]> { { "k1", Encoding.UTF8.GetBytes("value1") }, { "k2", Encoding.UTF8.GetBytes("value2") } };
            var stmt = new SimpleStatement("SELECT * FROM system.local");
            stmt.SetOutgoingPayload(outgoing);
            var rs = Session.Execute(stmt);
            Assert.NotNull(rs.Info.IncomingPayload);
            Assert.AreEqual(outgoing.Count, rs.Info.IncomingPayload.Count);
            CollectionAssert.AreEqual(outgoing["k1"], rs.Info.IncomingPayload["k1"]);
            CollectionAssert.AreEqual(outgoing["k2"], rs.Info.IncomingPayload["k2"]);
        }

35. Example

Project: csharp-driver
Source File: CustomPayloadTests.cs
[Test, TestCassandraVersion(2, 2)]
        public void Bound_Payload_Test()
        {
            var outgoing = new Dictionary<string, byte[]> { { "k1-bound", Encoding.UTF8.GetBytes("value1") }, { "k2-bound", Encoding.UTF8.GetBytes("value2") } };
            var prepared = Session.Prepare("SELECT * FROM system.local WHERE key = ?");
            var stmt = prepared.Bind("local");
            stmt.SetOutgoingPayload(outgoing);
            var rs = Session.Execute(stmt);
            Assert.NotNull(rs.Info.IncomingPayload);
            Assert.AreEqual(outgoing.Count, rs.Info.IncomingPayload.Count);
            CollectionAssert.AreEqual(outgoing["k1-bound"], rs.Info.IncomingPayload["k1-bound"]);
            CollectionAssert.AreEqual(outgoing["k2-bound"], rs.Info.IncomingPayload["k2-bound"]);
        }

36. Example

Project: csharp-driver
Source File: CustomPayloadTests.cs
[Test, TestCassandraVersion(2, 2)]
        public void Prepare_Payload_Test()
        {
            var outgoing = new Dictionary<string, byte[]>
            {
                { "k1-prep", Encoding.UTF8.GetBytes("value1-prep") }, 
                { "k2-prep", Encoding.UTF8.GetBytes("value2-prep") }
            };
            var prepared = Session.Prepare("SELECT key as k FROM system.local WHERE key = ?", outgoing);
            Assert.NotNull(prepared.IncomingPayload);
            Assert.AreEqual(outgoing.Count, prepared.IncomingPayload.Count);
            CollectionAssert.AreEqual(outgoing["k1-prep"], prepared.IncomingPayload["k1-prep"]);
            CollectionAssert.AreEqual(outgoing["k2-prep"], prepared.IncomingPayload["k2-prep"]);
        }

37. Example

Project: csharp-driver
Source File: UdtSerializerWrapper.cs
public override byte[] Serialize(ushort protocolVersion, object value)
        {
            SerializationCounter++;
            if (_fixedValue)
            {
                return Encoding.UTF8.GetBytes("DUMMY UDT SERIALIZED");   
            }
            return base.Serialize(protocolVersion, value);
        }

38. Example

Project: csharp-driver
Source File: CustomTypeSerializerTests.cs
[Test]
        public void Should_Allow_Custom_Udt_Serializers()
        {
            var typeSerializer = new UdtSerializerWrapper();
            var serializer = new Serializer(ProtocolVersion.MaxSupported, new ITypeSerializer[] { typeSerializer });
            var buffer = serializer.Serialize(new object());
            CollectionAssert.AreEqual(Encoding.UTF8.GetBytes("DUMMY UDT SERIALIZED"), buffer);
            CollectionAssert.AreEqual(buffer, (IEnumerable)serializer.Deserialize(buffer, ColumnTypeCode.Udt, new UdtColumnInfo("ks1.udt1")));
            //Check that other serializers are still working
            CollectionAssert.AreEqual(new byte[] { 0, 0, 0, 10 }, serializer.Serialize(10));
            CollectionAssert.AreEqual(new byte[] { 0x61, 0x62 }, serializer.Serialize("ab"));
            Assert.AreEqual(1, typeSerializer.DeserializationCounter);
            Assert.AreEqual(1, typeSerializer.SerializationCounter);
        }

39. Example

Project: raspkate
Source File: HandlerProcessResult.cs
public static HandlerProcessResult Text(HttpStatusCode statusCode, string content)
        {
            var contentBytes = ContentEncoding.GetBytes(content);
            return new HandlerProcessResult(statusCode, "text/plain", contentBytes);
        }

40. Example

Project: raspkate
Source File: HandlerProcessResult.cs
public static HandlerProcessResult Json(HttpStatusCode statusCode, string jsonContent)
        {
            var contentBytes = ContentEncoding.GetBytes(jsonContent);
            return new HandlerProcessResult(statusCode, "application/json", contentBytes);
        }

41. Example

Project: hfmcmd
Source File: Utilities.cs
public static byte[] GetBytes(string str)
        {
            return System.Text.Encoding.ASCII.GetBytes(str);
        }

42. Example

Project: OutlookPrivacyPlugin
Source File: DerUTF8String.cs
internal override void Encode(
			DerOutputStream derOut)
        {
            derOut.WriteEncoded(Asn1Tags.Utf8String, Encoding.UTF8.GetBytes(str));
        }

43. Example

Project: OutlookPrivacyPlugin
Source File: PbeParametersGenerator.cs
[Obsolete("Use version taking 'char[]' instead")]
        public static byte[] Pkcs5PasswordToUtf8Bytes(
            string password)
        {
            if (password == null)
                return new byte[0];

            return Encoding.UTF8.GetBytes(password);
        }

44. Example

Project: OutlookPrivacyPlugin
Source File: Strings.cs
public static byte[] ToAsciiByteArray(
            string s)
        {
#if SILVERLIGHT
            // TODO Check for non-ASCII characters in input?
            return Encoding.UTF8.GetBytes(s);
#else
            return Encoding.ASCII.GetBytes(s);
#endif
        }

45. Example

Project: OutlookPrivacyPlugin
Source File: Strings.cs
public static byte[] ToUtf8ByteArray(
            string s)
        {
            return Encoding.UTF8.GetBytes(s);
        }

46. Example

Project: OutlookPrivacyPlugin
Source File: BsonWriterTests.cs
[Test]
        public void SerializeByteArray_ErrorWhenTopLevel()
        {
            byte[] b = Encoding.UTF8.GetBytes("Hello world");

            MemoryStream ms = new MemoryStream();
            JsonSerializer serializer = new JsonSerializer();

            BsonWriter writer = new BsonWriter(ms);

            ExceptionAssert.Throws<JsonWriterException>(() =>
            {
                serializer.Serialize(writer, b);
            }, "Error writing Binary value. BSON must start with an Object or Array. Path ''.");
        }

47. Example

Project: OutlookPrivacyPlugin
Source File: ReadJson.cs
public static StreamReader OpenText(string path)
            {
                return new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes("{}")));
            }

48. Example

Project: OutlookPrivacyPlugin
Source File: DeserializeWithJsonSerializerFromFile.cs
public static StreamReader OpenText(string s)
            {
                return new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes("{}")));
            }

49. Example

Project: OutlookPrivacyPlugin
Source File: SerializationErrorHandlingTests.cs
[Test]
        public void NoObjectWithAttribute()
        {
            string json = "{\"}";
            byte[] byteArray = Encoding.UTF8.GetBytes(json);
            MemoryStream stream = new MemoryStream(byteArray);
            JsonTextReader jReader = new JsonTextReader(new StreamReader(stream));
            JsonSerializer s = new JsonSerializer();

            ExceptionAssert.Throws<JsonReaderException>(() => { ErrorTestObject obj = s.Deserialize<ErrorTestObject>(jReader); }, @"Unterminated string. Expected delimiter: "". Path '', line 1, position 3.");
        }

50. Example

Project: OutlookPrivacyPlugin
Source File: JsonTextReaderTest.cs
private string ReadString(string input)
        {
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(@"""" + input + @""""));

            JsonTextReader reader = new JsonTextReader(new StreamReader(ms));
            reader.Read();

            string s = (string)reader.Value;

            return s;
        }