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"); }
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); }
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; } }
public UnaryResult <MyClass2> Echo(string name, int x, int y, MyEnum2 e) { return(UnaryResult(new MyClass2 { Name = name, Sum = (x + y) * (int)e })); }
public static nint ToNative2(MyEnum2 value) { throw new NotImplementedException(); }
public void Test(string a = null, int? x = null, MyEnum2? z = null) { }
public Task OutputLogAsync(string message, string message2, MyEnum e, MyEnum2 e2) { Console.WriteLine("log"); return(Task.CompletedTask); }
public void RpcSomeFunction([BitCount(4), ZigZagEncode] MyEnum2 myParam) { onRpc?.Invoke(myParam); }
public static int Get(MyEnum2 key) => s_MyEnum2Data[(int)key];
public void ByteArrayCheck3(int x, string y, byte[] byteArray, string a = null, int? xxx = null, MyEnum2? z = null) { }