public void DefaultValueCheck_DefaultConstructorEnum_AsExpectedWhenDefaultValue() { FooEnum value = new FooEnum(); var actual = DefaultValueCheck(value); Assert.Equal(ExpectedWhenDefaultValue, actual); }
public void DefaultValueCheck_FirstEnumOptionWithValueOne_AsExpectedWhenNotDefaultValue() { FooEnum value = FooEnum.FooEnumState; var actual = DefaultValueCheck(value); Assert.Equal(ExpectedWhenNotDefaultValue, actual); }
public void NullCheck_DefaultCustomEnum_AsExpectedWhenNull() { FooEnum value = default(FooEnum); var actual = NullCheck(value); Assert.Equal(ExpectedWhenNotNull, actual); }
/// <summary> /// </summary> public Foo ( FooEnum requiredEnum ) : this() { RequiredEnum = requiredEnum; }
public static int test_0_marshal_return_enum_delegate() { ReturnEnumDelegate d = new ReturnEnumDelegate(managed_return_enum); FooEnum e = (FooEnum)mono_test_marshal_return_enum_delegate(d); return(e == FooEnum.Foo3 ? 0 : 1); }
public STClass(FooEnum foo, int count, string label, double[] buffer) { this.foo = foo; this.count = count; this.label = label; this.buffer = buffer; }
/// <summary> /// </summary> public Foo( FooEnum requiredEnum ) : this() { RequiredEnum = requiredEnum; }
public void When_config_of_EndKey_of_enum_It_configures_underlying_options_Key() { const FooEnum configuredValue = FooEnum.Two; SUT.EndKey(configuredValue); _parameters.EndKey.Should().Be(configuredValue); }
public void When_config_of_Key_of_enum_It_configures_underlying_options_Key() { const FooEnum configuredValue = FooEnum.Two; SUT.Key(configuredValue); _request.Key.Should().Be(configuredValue); }
/// <summary> /// </summary> public Packet( FooEnum aFooEnum, Foo foo ) : this() { AFooEnum = aFooEnum; Foo = foo; }
/// <summary> /// </summary> public Packet ( FooEnum aFooEnum, Foo foo ) : this() { AFooEnum = aFooEnum; Foo = foo; }
internal static string ToSerializedValue(this FooEnum value) { switch (value) { case FooEnum.Foo1: return("foo1"); case FooEnum.Foo2: return("foo2"); case FooEnum.Foo3: return("foo3"); } return(null); }
public void Test() { var tddHandler = new TDDHandler(); CustomObjectSettings.FooClassInstance = new FooClass(); CustomObjectSettings.SecureFooClassInstance = new FooClass(); Random rand = new MyRandom(); Int32 fooValue = rand.NextInt32(); Int32 secureFooValue = rand.NextInt32(); CustomObjectSettings.FooClassInstance.IntValue = fooValue; CustomObjectSettings.SecureFooClassInstance.IntValue = secureFooValue; FooEnum fooEnumValue = (FooEnum)rand.Next((Int32)FooEnum.One, (Int32)FooEnum.Ten); FooEnum secureFooEnumValue = (FooEnum)rand.Next((Int32)FooEnum.One, (Int32)FooEnum.Ten); CustomObjectSettings.FooEnumValue = fooEnumValue; CustomObjectSettings.SecureFooEnumValue = secureFooEnumValue; CustomObjectSettings.SaveSettings(); CustomObjectSettings.FooClassInstance = null; CustomObjectSettings.SecureFooClassInstance = null; CustomObjectSettings.FooEnumValue = FooEnum.Zero; CustomObjectSettings.SecureFooEnumValue = FooEnum.Zero; CustomObjectSettings.LoadSettings(); Assert.IsNotNull(CustomObjectSettings.FooClassInstance); Assert.IsTrue(typeof(FooClass) == CustomObjectSettings.FooClassInstance.GetType()); Assert.AreEqual(CustomObjectSettings.FooClassInstance.IntValue, fooValue); Assert.AreEqual(CustomObjectSettings.FooEnumValue, fooEnumValue); Assert.IsNotNull(CustomObjectSettings.SecureFooClassInstance); Assert.IsTrue(typeof(FooClass) == CustomObjectSettings.SecureFooClassInstance.GetType()); Assert.AreEqual(CustomObjectSettings.SecureFooClassInstance.IntValue, secureFooValue); Assert.AreEqual(CustomObjectSettings.SecureFooEnumValue, secureFooEnumValue); tddHandler.CheckErrors(); }
public static FooEnum managed_return_enum (FooEnum e) { return (FooEnum)((int)e + 1); }
[MyProudAdvice] // fody error public void Method6(FooEnum fooEnum, string name, long id, long count) { }
public void Method6(FooEnum fooEnum, string name, long id, long count) { }
public ClassWithEnumParameter(FooEnum foo) { }
public MethodWithEnumValueAttribute(FooEnum value, Type t) { }
public static string ToSerialString(this FooEnum value) => value switch {
public static FooEnum managed_return_enum(FooEnum e) { return((FooEnum)((int)e + 1)); }
/// <summary> /// Exercise in Power. Control. Power. And once more Control. Show them stupid compiler who's the boss. /// Why? Yes. /// </summary> static void Main(string[] args) { // Casting enums work. But this is boring. { FooEnum fooX = FooEnum.SomeValueA; BarEnum barX = (BarEnum)fooX; } // Casting structs does not compile. Obviously What a shame. { //FooStruct foo = new FooStruct(); //BarStruct bar = (BarStruct)foo; } // Screw you CLR, I'm a ninja. { FooStruct foo = new FooStruct { fieldA = "this is FooStruct.FieldA", fieldB = "this is FooStruct.FieldB", }; BarStruct bar = I.Donʼt.Do.This.Often.But.When.I.Do.I.Always.Cast.From <FooStruct> .To <BarStruct> .ForScience(foo); Console.WriteLine(string.Format("Value of BarStruct.fieldXXX: {0}", bar.fieldXXX)); Console.WriteLine(string.Format("Value of BarStruct.fieldYYY: {0}", bar.fieldYYY)); } // And classes too! Compiles! And even works! { FooClass foo = new FooClass { fieldA = "this is FooClass.FieldA", fieldB = "this is FooClass.FieldB", }; BarClass bar = I.Donʼt.Do.This.Often.But.When.I.Do.I.Always.Cast.From <FooClass> .To <BarClass> .ForScience(foo); Console.WriteLine(string.Format("Value of BarClass.fieldXXX: {0}", bar.fieldXXX)); Console.WriteLine(string.Format("Value of BarClass.fieldYYY: {0}", bar.fieldYYY)); } // Extra fields AND classes? Ha! Also works as expected { FooClass foo = new FooClass { fieldA = "this is FooClass.FieldA", fieldB = "this is FooClass.FieldB", }; BarClassWithExtraField bar = I.Donʼt.Do.This.Often.But.When.I.Do.I.Always.Cast.From <FooClass> .To <BarClassWithExtraField> .ForScience(foo); Console.WriteLine(string.Format("Value of BarClassWithExtraField.fieldXXX: {0}", bar.fieldXXX)); Console.WriteLine(string.Format("Value of BarClassWithExtraField.fieldYYY: {0}", bar.fieldYYY)); Console.WriteLine(string.Format("Value of BarClassWithExtraField.fieldExtra: {0}", bar.fieldExtra ?? "<null>")); } // Split long integeres into shorter ones. Wow :) { FooClassWithLong foo = new FooClassWithLong { fieldA = ulong.MaxValue }; BarClassWithFourShorts bar = I.Donʼt.Do.This.Often.But.When.I.Do.I.Always.Cast.From <FooClassWithLong> .To <BarClassWithFourShorts> .ForScience(foo); Console.WriteLine(string.Format("Value of BarClassWithFourShorts.fieldA: {0}; max ushort: {1}", bar.fieldA, ushort.MaxValue)); Console.WriteLine(string.Format("Value of BarClassWithFourShorts.fieldB: {0}; max ushort: {1}", bar.fieldB, ushort.MaxValue)); Console.WriteLine(string.Format("Value of BarClassWithFourShorts.fieldB: {0}; max ushort: {1}", bar.fieldC, ushort.MaxValue)); Console.WriteLine(string.Format("Value of BarClassWithFourShorts.fieldB: {0}; max ushort: {1}", bar.fieldD, ushort.MaxValue)); } // Don't even need the same field types in source and target (but this is a bit dodgy) { FooClassWithLong foo = new FooClassWithLong { fieldA = ulong.MaxValue }; // Bonus feature: Travel really far into the future. // This yields the date 08/11/14614 13:24:02, whereas DateTime.MaxValue is only 31/12/9999 23:59:59 BarClassWithDate bar = I.Donʼt.Do.This.Often.But.When.I.Do.I.Always.Cast.From <FooClassWithLong> .To <BarClassWithDate> .ForScience(foo); Console.WriteLine(string.Format("Value of BarClassWithDate.fieldB: {0}; max DateTime: {1}", bar.fieldA, DateTime.MaxValue)); } // String.Length is for weak poeple. { string wellHelloThere = "idin 9ehvjd dng8nf yes this is gonna work"; BarClassWithIntOrLong bar = I.Donʼt.Do.This.Often.But.When.I.Do.I.Always.Cast.From <string> .To <BarClassWithIntOrLong> .ForScience(wellHelloThere); Console.WriteLine(string.Format("Value of string.Length is: {0}. And value of BarClassWithIntOrLong.fieldA is: {1}", wellHelloThere.Length, bar.fieldA)); } // Immutable strings? Ha! { string wellHelloThere = "idin 9ehvjd dng8nf yes this is gonna work"; char[] bar = I.Donʼt.Do.This.Often.But.When.I.Do.I.Always.Cast.From <string> .To <char[]> .ForScience(wellHelloThere); bar[0] = 'Y'; bar[1] = 'A'; bar[2] = 'Y'; bar[3] = '!'; Console.WriteLine(string.Format("Value of string after showing who's the boss here: {0}.", wellHelloThere)); } // Is someone over-protective of their code? // Did someone read too many blogs on the benefits of "encapsulation"? // Have they thought to hide cool useful fields using "private" keyword? // Fools! It's Encapsulation-Boomcapsulation time! Turn their private fields into public! { FooClassWithPrivateFields foo = new FooClassWithPrivateFields(fieldA: "private field A", fieldB: "private field B"); BarClassWithEverythingPublic bar = I.Donʼt.Do.This.Often.But.When.I.Do.I.Always.Cast.From <FooClassWithPrivateFields> .To <BarClassWithEverythingPublic> .ForScience(foo); Console.WriteLine("Private field A? Not anymore!: {0}", bar.fieldAPublic); Console.WriteLine("Private field B? Not anymore!: {0}", bar.fieldBPublic); } // Arrays of T. Turn them into Arrays of Y! { var fooThings = new FooClass[] { new FooClass { fieldA = "foo.FieldA 1", fieldB = "foo.FieldB 1" }, new FooClass { fieldA = "foo.FieldA 2", fieldB = "foo.FieldB 2" } }; // This will not compile. //var barThings = (BarClass[])fooThings; // But we don't care! var barThings = I.Donʼt.Do.This.Often.But.When.I.Do.I.Always.Cast.From <FooClass[]> .To <BarClass[]> .ForScience(fooThings); foreach (var bar in barThings) { Console.WriteLine("Array. bar.fieldXXX: {0}", bar.fieldXXX); Console.WriteLine("Array. bar.fieldYYY: {0}", bar.fieldYYY); } } // Linq and enumerables -- no problem! { var fooArray = new FooClass[] { new FooClass { fieldA = "foo.FieldA 1", fieldB = "foo.FieldB 1" }, new FooClass { fieldA = "foo.FieldA 2", fieldB = "foo.FieldB 2" } }; var fooThingsEnumerable = fooArray.AsEnumerable(); // This will throw InvalidCastException. //var barThings = (IEnumerable<BarClass>)fooThingsEnumerable; // But we don't care! var barThings = I.Donʼt.Do.This.Often.But.When.I.Do.I.Always.Cast.From <IEnumerable <FooClass> > .To <IEnumerable <BarClass> > .ForScience(fooThingsEnumerable); foreach (var bar in barThings) { Console.WriteLine("Enumerable. bar.fieldXXX: {0}", bar.fieldXXX); Console.WriteLine("Enumerable. bar.fieldYYY: {0}", bar.fieldYYY); } } // Enhanced polymorphism without class hierarchy - Turn dogs into cats! { var cat = new Cat(); // This will not compile. //var dog = (Dog)cat; // But we don't care! var dog = I.Donʼt.Do.This.Often.But.When.I.Do.I.Always.Cast.From <Cat> .To <Dog> .ForScience(cat); Console.WriteLine("Cat says: {0}", cat.SaySomething()); Console.WriteLine("Cat became dog: {0}", dog.SaySomething()); } // And many, many other fun application. :) }
public static void Main(string[] args) { // Note that since the method does not take an argument which // specifies the generic type, you must provide it explicitly. FooEnum randomFoo = EnumRandomizer.GetRandomValue <FooEnum>(); }
public TestAttribute(int[] foos, FooEnum @enum, Type type) { }
/// <summary>Helper for setting <see cref="FooEnumProperty"/> on <paramref name="element"/>.</summary> /// <param name="element"><see cref="DependencyObject"/> to set <see cref="FooEnumProperty"/> on.</param> /// <param name="value">FooEnum property value.</param> public static void SetFooEnum(DependencyObject element, FooEnum value) { element.SetValue(FooEnumProperty, value); }
public string SetEnumValue(FooEnum value) { return(value.ToString()); }