public void box_unbox_Test_1()
        {
            // Creates objects for testing of different casts.
            object o_enum  = MyEnum.Value;
            object o_enum1 = MyEnum1.Value;
            object o_long  = 24L;
            object o_class = new CastTestClass();
            object o_guid  = Guid.NewGuid();

            // Try casts that shoud succeed. Any exception here means failure.
            // First we try casts that should succeed.
            // Casts between enums with the same basic type
            MyEnum2 e2 = (MyEnum2)o_enum; // line 2
                                          // Cast from enum to primitive type that enum is based on
            short sv = (short)o_enum;

            Assert.Equal(sv, (short)MyEnum.Value);

            // Cast from enum to primitive type that enum is based on
            int iv = (int)o_enum1;

            Assert.Equal(iv, (short)MyEnum1.Value);

            int           i_long = (int)(long)o_long;
            CastTestClass cls    = (CastTestClass)o_class;
            Guid          guid   = (Guid)o_guid;

            // Now casts that should throw exception. Any cast that does not throw - means error.
            Assert.Throws(typeof(InvalidCastException), () =>
            {
                MyEnum1 e1 = (MyEnum1)o_enum;
            }, "Trying to cast incompatible enums - should throw InvalidCastException");

            // Now casts that should throw exception. Any cast that does not throw - means error.
            Assert.Throws(typeof(InvalidCastException), () =>
            {
                int i = (int)o_long;
            }, "Trying to cast long to int - should throw InvalidCastException");

            // Now casts that should throw exception. Any cast that does not throw - means error.
            Assert.Throws(typeof(InvalidCastException), () =>
            {
                int i = (int)o_class;
            }, "Trying to cast object to int - should throw InvalidCastException");

            // Now casts that should throw exception. Any cast that does not throw - means error.
            Assert.Throws(typeof(InvalidCastException), () =>
            {
                int i = (int)o_enum;
            }, "Trying to cast enum to int - should throw InvalidCastException");

            // Now casts that should throw exception. Any cast that does not throw - means error.
            Assert.Throws(typeof(InvalidCastException), () =>
            {
                int i = (int)o_guid;
            }, "Trying to cast Guid to int - should throw InvalidCastException");
        }
예제 #2
0
 public ClassWithStructAndEnum(Business.ClassWithStructAndEnum source)
 {
     Id      = source.Id;
     AStruct = new MyStruct()
     {
         Field1        = source.AStruct.Field1,
         AnotherField2 = source.AStruct.Field2
     };
     AnEnum1 = (DTO.ClassWithStructAndEnum.MyEnum1)(int) source.AnEnum1;
     AnEnum2 = Convert(source.AnEnum2);
 }
예제 #3
0
        public static void ChangeLight2(object sender, object e)
        {
            switch (C2)
            {
            case MyEnum2.Yellow:
                C2 = MyEnum2.Black;
                break;

            case MyEnum2.Black:
                C2 = MyEnum2.Yellow;
                break;

            default:
                break;
            }
        }
예제 #4
0
 public UnaryResult <MyClass2> Echo(string name, int x, int y, MyEnum2 e)
 {
     return(UnaryResult(new MyClass2 {
         Name = name, Sum = (x + y) * (int)e
     }));
 }
예제 #5
0
 public static nint ToNative2(MyEnum2 value)
 {
     throw new NotImplementedException();
 }
예제 #6
0
 public void Test(string a = null, int? x = null, MyEnum2? z = null)
 {
 }
예제 #7
0
 public Task OutputLogAsync(string message, string message2, MyEnum e, MyEnum2 e2)
 {
     Console.WriteLine("log");
     return(Task.CompletedTask);
 }
예제 #8
0
 public void RpcSomeFunction([BitCount(4), ZigZagEncode] MyEnum2 myParam)
 {
     onRpc?.Invoke(myParam);
 }
예제 #9
0
 public static int Get(MyEnum2 key) => s_MyEnum2Data[(int)key];
예제 #10
0
파일: Startup.cs 프로젝트: neuecc/LightNode
 public void ByteArrayCheck3(int x, string y, byte[] byteArray, string a = null, int? xxx = null, MyEnum2? z = null)
 {
 }