当前位置: 首页>>代码示例>>C#>>正文


C# UnicodeEncoding类代码示例

本文整理汇总了C#中UnicodeEncoding的典型用法代码示例。如果您正苦于以下问题:C# UnicodeEncoding类的具体用法?C# UnicodeEncoding怎么用?C# UnicodeEncoding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UnicodeEncoding类属于命名空间,在下文中一共展示了UnicodeEncoding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        UnicodeEncoding expectedValue = new UnicodeEncoding(false,true);
        UnicodeEncoding actualValue;

        TestLibrary.TestFramework.BeginScenario("PosTest1:Create a instance");
        try
        {
            actualValue = new UnicodeEncoding();

            if (!expectedValue.Equals(actualValue))
            {
                TestLibrary.TestFramework.LogError("001", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")");
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:26,代码来源:unicodeencodingctor1.cs

示例2: PosTest1

 public void PosTest1()
 {
     UnicodeEncoding expectedValue = new UnicodeEncoding(false, true);
     UnicodeEncoding actualValue;
     actualValue = new UnicodeEncoding();
     Assert.Equal(expectedValue, actualValue);
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:UnicodeEncodingCtor1.cs

示例3: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;

        UnicodeEncoding uE = new UnicodeEncoding(true, true);

        Byte[] expectedValue = new Byte[] { 0xfe,0xff};
        Byte[] actualValue;

        TestLibrary.TestFramework.BeginScenario("PosTest2:Invoke the method with bigEndian true and byteOrderMark true.");
        try
        {
            actualValue = uE.GetPreamble();

            if (expectedValue.Equals(actualValue))
            {
                TestLibrary.TestFramework.LogError("003", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")");
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:28,代码来源:unicodeencodinggetpreamble.cs

示例4: toByteArray

    public byte[] toByteArray()
    {
        UnicodeEncoding encoding = new UnicodeEncoding();
        byte[] player_bytes = encoding.GetBytes(player);
        byte[] description_bytes = encoding.GetBytes(description);
        byte[] bytes = new byte[12 + player_bytes.Length + description_bytes.Length + image.Length];

        int array_index = 0;
        KLFCommon.intToBytes(index).CopyTo(bytes, array_index);
        array_index += 4;

        KLFCommon.intToBytes(player_bytes.Length).CopyTo(bytes, array_index);
        array_index += 4;

        player_bytes.CopyTo(bytes, array_index);
        array_index += player_bytes.Length;

        KLFCommon.intToBytes(description_bytes.Length).CopyTo(bytes, array_index);
        array_index += 4;

        description_bytes.CopyTo(bytes, array_index);
        array_index += description_bytes.Length;

        image.CopyTo(bytes, array_index);

        return bytes;
    }
开发者ID:raad287,项目名称:KerbalLiveFeed,代码行数:27,代码来源:Screenshot.cs

示例5: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;

        int expectedValue = 2;
        int actualValue;

        UnicodeEncoding uE = new UnicodeEncoding();

        TestLibrary.TestFramework.BeginScenario("PosTest2:Invoke the method and set byteCount as 1.");
        try
        {
            actualValue = uE.GetMaxCharCount(1);

            if (expectedValue != actualValue)
            {
                TestLibrary.TestFramework.LogError("003", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")");
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:28,代码来源:unicodeencodinggetmaxcharcount.cs

示例6: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        int expectedValue;
        int actualValue;

        UnicodeEncoding uE1 = new UnicodeEncoding();
        UnicodeEncoding uE2 = new UnicodeEncoding();

        TestLibrary.TestFramework.BeginScenario("PosTest1:Invoke the method.");
        try
        {
            expectedValue = uE1.GetHashCode();
            actualValue = uE2.GetHashCode();

            if (expectedValue != actualValue)
            {
                TestLibrary.TestFramework.LogError("001", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")");
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:30,代码来源:unicodeencodinggethashcode.cs

示例7: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        UnicodeEncoding uEncoding = new UnicodeEncoding();

        int expectedValue = 0;
        int actualValue;

        TestLibrary.TestFramework.BeginScenario("PosTest1:Invoke the method with a empty String.");
        try
        {
            actualValue = uEncoding.GetByteCount("");

            if (expectedValue != actualValue)
            {
                TestLibrary.TestFramework.LogError("001", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")");
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:28,代码来源:unicodeencodinggetbytecount2.cs

示例8: PosTest2

    public bool PosTest2()
    {
        bool retVal = true;

        UnicodeEncoding uEncoding1 = new UnicodeEncoding();
        UnicodeEncoding uEncoding2 = new UnicodeEncoding(false, false);

        bool expectedValue = false;
        bool actualValue;

        TestLibrary.TestFramework.BeginScenario("PosTest2:Invoke the method with two instance that not equal.");
        try
        {
            actualValue = uEncoding1.Equals(uEncoding2);

            if (expectedValue != actualValue)
            {
                TestLibrary.TestFramework.LogError("003", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")");
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("004", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:29,代码来源:unicodeencodingequals.cs

示例9: VerifyUnicodeEncoding

        public static void VerifyUnicodeEncoding(UnicodeEncoding encoding, bool bigEndian, bool byteOrderMark, bool throwOnInvalidBytes)
        {
            if (byteOrderMark)
            {
                if (bigEndian)
                {
                    Assert.Equal(new byte[] { 0xfe, 0xff }, encoding.GetPreamble());
                }
                else
                {
                    Assert.Equal(new byte[] { 0xff, 0xfe }, encoding.GetPreamble());
                }
            }
            else
            {
                Assert.Empty(encoding.GetPreamble());
            }

            if (throwOnInvalidBytes)
            {
                Assert.Equal(EncoderFallback.ExceptionFallback, encoding.EncoderFallback);
                Assert.Equal(DecoderFallback.ExceptionFallback, encoding.DecoderFallback);
            }
            else
            {
                Assert.Equal(new EncoderReplacementFallback("\uFFFD"), encoding.EncoderFallback);
                Assert.Equal(new DecoderReplacementFallback("\uFFFD"), encoding.DecoderFallback);
            }
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:29,代码来源:UnicodeEncodingTests.cs

示例10: PosTest3

 public void PosTest3()
 {
     UnicodeEncoding uEncoding = new UnicodeEncoding();
     bool actualValue;
     actualValue = uEncoding.Equals(new TimeSpan());
     Assert.False(actualValue);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:UnicodeEncodingEquals.cs

示例11: PosTest1

 public void PosTest1()
 {
     UnicodeEncoding uEncoding = new UnicodeEncoding();
     int actualValue;
     actualValue = uEncoding.GetByteCount("");
     Assert.Equal(0, actualValue);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:UnicodeEncodingGetByteCount2.cs

示例12: PosTest1

 public void PosTest1()
 {
     Char[] chars = new Char[] { };
     UnicodeEncoding uEncoding = new UnicodeEncoding();
     int actualValue;
     actualValue = uEncoding.GetByteCount(chars, 0, 0);
     Assert.Equal(0, actualValue);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:8,代码来源:UnicodeEncodingGetByteCount1.cs

示例13: PosTest2

 public void PosTest2()
 {
     UnicodeEncoding uEncoding1 = new UnicodeEncoding();
     UnicodeEncoding uEncoding2 = new UnicodeEncoding(false, false);
     bool actualValue;
     actualValue = uEncoding1.Equals(uEncoding2);
     Assert.False(actualValue);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:8,代码来源:UnicodeEncodingEquals.cs

示例14: PosTest3

 public void PosTest3()
 {
     String str = GetString(1);
     UnicodeEncoding uEncoding = new UnicodeEncoding();
     int actualValue;
     actualValue = uEncoding.GetByteCount(str);
     Assert.Equal(2, actualValue);
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:8,代码来源:UnicodeEncodingGetByteCount2.cs

示例15: Ctor_Bool_Bool

        public void Ctor_Bool_Bool(bool bigEndian, bool byteOrderMark)
        {
            UnicodeEncoding encoding = new UnicodeEncoding(bigEndian, byteOrderMark);
            VerifyUnicodeEncoding(encoding, bigEndian, byteOrderMark, throwOnInvalidBytes: false);

            Ctor_Bool_Bool_Bool(bigEndian, byteOrderMark, throwOnInvalidBytes: true);
            Ctor_Bool_Bool_Bool(bigEndian, byteOrderMark, throwOnInvalidBytes: false);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:8,代码来源:UnicodeEncodingTests.cs


注:本文中的UnicodeEncoding类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。