Inheritance: IDoStuffPublically, IDoStuffInternally
        static void Main()
        {
            DoStuff ds = Console.WriteLine;

            //ds("Hallo Welt!");

            // das ist das gleich
            if (ds != null)
            {
                ds("Ja, ist nicht null");
            }

            // wie das hier:
            ds?.Invoke("Ja, ist nicht null");

            // oder
            //ds.Invoke("Hallo");

            //ds = MeineKlasseKlasse.MeineKlasseMethode;
            //ds("Hallo Welt!");


            //ds = (s) => Console.WriteLine("Nachricht aus der Lamda-Methode: " + s);

            //ds("Hallo Welt!");

            MyMethod(ds);

            Console.ReadLine();
        }
Example #2
0
        public void demo5()
        {
            Task <int> value = DoStuff.FindSeriesSum(100000);

            DoStuff.CountBig(100000);
            DoStuff.CountBig(100000);
            DoStuff.CountBig(100000);
            DoStuff.CountBig(100000);
            Console.WriteLine("Sum: {0}", value.Result);
        }
Example #3
0
    static void Main()
    {
        Task <int> value = DoStuff.FindSeriesSum(1000000);

        CountBig(100000);
        CountBig(100000);
        CountBig(100000);
        CountBig(100000);
        Console.WriteLine("Sum: {0}", value.Result);
    }
Example #4
0
        public static void Main()
        {
            DoStuff     stuff     = new DoStuff(MyMethod);
            DoMoreStuff moreStuff = MyMethod;

            Console.WriteLine($"Stuff: {stuff("Louis", 2)}");
            Console.WriteLine($"MoreStuff: {moreStuff("Louis", 2)}");

            Func <string, int, string> funcStuff = MyMethod;

            Console.WriteLine($"FuncStuff: {funcStuff("Louis", 2)}");
            Console.ReadLine();
        }
        public void CallPrivateMethod()
        {
            DoStuff instance = new DoStuff();

            var privateMethod = typeof(DoStuff).GetMethod("getPrivateThoughts", BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.NonPublic);

            var privateResult = privateMethod.Invoke(instance, null);

            var returnType = privateMethod.ReturnType;

            var resultString = (returnType.Name == "String") ? Convert.ToString(privateResult) : "";

            Assert.True(resultString == "private thoughts here");
        }
Example #6
0
    private static void Main()
    {
        var doStuff = DoStuff.Create();

        if (doStuff.CanProcessAsynchronously)
        {
            var response = doStuff.DoIt(new[] { "stuff 1 ", "more stuff 1" });
            Console.WriteLine(response.ResponseCode);
        }
        else
        {
            doStuff.DoItCompleted += DoItCompleted;
            doStuff.DoItAsync(new[] { "stuff 2 ", "more stuff 2" });
        }
        Console.ReadLine();
    }
        public void UnitTest()
        {
            DoStuff instance = new DoStuff();

            var allMethods     = typeof(DoStuff).GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic);
            var privateMethods = typeof(DoStuff).GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.NonPublic);
            var publicMethods  = typeof(DoStuff).GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);

            foreach (var method in allMethods)
            {
                Console.WriteLine(string.Format("Method: {0}, with return type: {1}", method.Name, method.ReturnType.AssemblyQualifiedName));
            }

            Assert.True(allMethods.Length == 6);
            Assert.True(privateMethods.Length == 3);
            Assert.True(publicMethods.Length == 3);
        }
    static void Main(string[] args)
    {
        // var loggerEnvironment = "AzureFunctions";
        var     loggerEnvironment = "ConsoleApp";
        ILogger logger            = null;

        if (loggerEnvironment == "AzureFunctions")
        {
            Microsoft.Azure.WebJobs.Host.TraceWriter azureFunctionLogger = null;
            logger = new AzureFunctionLogger(azureFunctionLogger);
        }
        else if (loggerEnvironment == "ConsoleApp")
        {
            logger = new TraceLogger();
        }
        var doStuff = new DoStuff(logger);

        Console.ReadKey();
    }
        public void Run()
        {
            Test("Hello, ", "World!");

            // no problem, not nullable
            var doStuff1 = new DoStuff <string, string>();
            // type param should not be nullable
            var doStuff2 = new DoStuff <string?, string>();

            // nice touch, key should not be nullable
            var dict = new Dictionary <int?, string>();

            string[] testArray = { "Hello!", "World!" };
            var      value     = MyArray.Find <string>(testArray, s => s == "Hello!");

            WriteLine(value.Length); // Warning: Dereference of a possibly null reference.

            MyArray.Resize <string>(ref testArray, 200);
            WriteLine(testArray.Length); // Safe!
        }
        public void EditPrivateProperty()
        {
            var instance = new DoStuff();

            PropertyInfo privateProp = typeof(DoStuff).GetProperty("privateProperty", BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.Public);

            var privateValue = (string)privateProp.GetGetMethod(true).Invoke(instance, null);

            //var privateValue = typeof(DoStuff)
            //    .GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Public)
            //    .Where(x => x.Name.StartsWith("get_")).First()
            //    .Invoke(instance, null);

            Assert.True(privateValue == "private property");

            privateProp.SetValue(instance, "Break all the rules");

            privateValue = (string)privateProp.GetGetMethod(true).Invoke(instance, null);

            Assert.True(privateValue == "Break all the rules");
        }
 private static void MyMethod(DoStuff ds)
 {
     ds("Hey");
 }
Example #12
0
 public string Get()
 {
     return(DoStuff.moreStuff());
 }
 public SomethingClass(DoStuff doStuff)
 {
     this._doStuff = doStuff;
 }