상속: MonoBehaviour
        public void ConstructorsWithArguments()
        {
            // Classes can can have constructors with arguments:
            Example1 obj = new Example1(3);

            Assert.Equal(3, obj.a);
        }
        public void Constructors()
        {
            // Classes can can have constructors which are called when you create an object of the class with new:
            Example1 obj = new Example1();

            Assert.Equal(1, obj.a);
        }
예제 #3
0
        public static void Main(string[] args)
        {
            var JsonMapperService = new JsonMapper();

            var example = new Example1(1, 1.0, new List <string> {
                "a", "b"
            }, new List <int> {
                27, 1, 2, 3, 4, 5, 6, 50, 7, 8
            }, new List <double> {
                1.1, 1.2
            }, new Dictionary <string, string> {
                { "asd", "123" }, { "def", "456" }
            }, new List <Example2> {
                new Example2(7, new Dictionary <string, string> {
                    { "fgh", "789" }
                }, new Dictionary <int, string> {
                    { 3, "dasdas" }
                })
            });
            var json = JsonConvert.SerializeObject(example);

            var path1            = "example2[0].dict[\"fgh\"].Value()";
            var testeSetVariable = JsonMapperService.SetJsonProperty(json, path1, "Teste");

            var path = "example2[0].dictint.elementAt(0).Value()";

            var result = JsonMapperService.GetJsonProperty(json, path);
        }
        public void Example1Test()
        {
            Example1 example;

            example           = new Example1();
            example.Property1 = "aaa";
            example.Property2 = "BbB";
            example.Transform();

            Assert.AreEqual("AAA", example.Property1);
            Assert.AreEqual("bbb", example.Property2);

            example           = new Example1();
            example.Property1 = "aaa";
            example.Property2 = "BbB";
            example.Transform(nameof(example.Property1));

            Assert.AreEqual("AAA", example.Property1);
            Assert.AreEqual("BbB", example.Property2);

            example           = new Example1();
            example.Property1 = "aaa";
            example.Property2 = "BbB";
            example.Transform(nameof(example.Property2));

            Assert.AreEqual("aaa", example.Property1);
            Assert.AreEqual("bbb", example.Property2);
        }
예제 #5
0
        static void Main(string[] args)
        {
            var serviceProvider = new ServiceCollection()
                                  .AddLogging(c => c.AddConsole())
                                  .AddSingleton(typeof(IDIExample), typeof(DIExample2))
                                  .AddScoped(typeof(IDependant), typeof(Dependant))
                                  .BuildServiceProvider();

            /* Commenting Trick
             * var e = new Example1();
             * /*/
            IExample e = new Example1();
            //*/


            var diExample = serviceProvider.GetService <IDIExample>();

            diExample.LogSomething();
            e.Run();

            var dep = serviceProvider.GetService <IDependant>();

            dep.CallDependentObj();

            StreamWriter w = new StreamWriter("log.txt");

            w.WriteLine("TEST");
            w.Flush();
            w.Close();
        }
예제 #6
0
    public static void  Main(System.String[] args) {
	if (args.Length > 0) {
	    Example1 t = new Example1(args[0]);
	} else {
	    Console.Out.WriteLine("usage: example1.exe <template>");
	}
    }
예제 #7
0
        public void C_ConstructorsWithArguments()
        {
            // Classes can can have constructors with arguments:
            Example1 obj = new Example1(3);

            Assert.AreEqual(FILL_ME_IN, obj.a);
        }
        public void Example1_Test()
        {
            var ex2 = (Example2)System.Runtime.Serialization.FormatterServices.GetUninitializedObject(typeof(Example2));

            var target = new Example1(ex2);

            Assert.NotNull(target);
        }
예제 #9
0
    //so on
    public Example1 CreateExample1(string option)
    {
        Example1 obj = new Example1();

        obj.username = this.UserName;
        obj.password = this.Password;
        return(obj);
    }
예제 #10
0
        private static async Task MainAsync(string[] args)
        {
            var t = Example1.Start();

            Console.WriteLine("Main has control and It is awaiting");
            await t;

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
예제 #11
0
        static void Main(string[] args)
        {
            // Just uncomment whatever you want to debug
            Example1.Run(args);
//          Example2.Run();
//          Example3.Run();
//          Example4.Run();
//          Example5.Run();
//			Example6.Run();
        }
예제 #12
0
 public static void Main(string[] args)
 {
     Example1.Main();
     //Example2.Main();
     //Example3.Main();
     //Example4.Main();
     //Example5.Main();
     //Example6.Main();
     //Example7.Main();
 }
예제 #13
0
        void OutClass(out Example1 obj)
        {
            // Next line gives compile error if not commented out,
            // because the method has to suppose that the object is not yet initialized.
            // obj.a = 1;

            // Commenting out the next line would give a compilation error because the method
            // has to assign to the argument.
            obj = new Example1();
        }
 public static void  Main(System.String[] args)
 {
     if (args.Length > 0)
     {
         Example1 t = new Example1(args[0]);
     }
     else
     {
         Console.Out.WriteLine("usage: example1.exe <template>");
     }
 }
    static void Main()
    {
        Example1 example1 = new Example1();

        Console.WriteLine("Class type instance is {0} and derives from {1}", example1.GetType().Name, example1.GetType().BaseType);

        Example2 example2 = new Example2();

        Console.WriteLine("Class type instance is {0} and derives from {1}", example2.GetType().Name, example2.GetType().BaseType);

        Example3 example3 = new Example3();

        Console.WriteLine("Class type instance is {0} and derives from {1}", example3.GetType().Name, example3.GetType().BaseType);
    }
예제 #16
0
        public static void MenuExamples()
        {
            CreateExamplesList();
            Console.WriteLine("> Menu Examples: ");
            foreach (var example in Examples)
            {
                Console.WriteLine(example);
            }
            Console.WriteLine("Write the number of the example you want to see:");

            var input  = Console.ReadLine();
            var select = 0;

            if (input == null)
            {
                Console.WriteLine("You must choose.");
                MenuExamples();
                return;
            }

            select = Int32.Parse(input);

            switch (select)
            {
            case 0:
                Menu();
                break;

            case 1:
                Console.Clear();
                Example1.Run();
                break;

            case 2:
                Console.Clear();
                Example2.Run();
                break;

            case 3:
                Console.Clear();
                Example3.Run();
                break;

            default:
                Console.Clear();
                Console.WriteLine("That example doesn't exist.");
                MenuExamples();
                break;
            }
        }
예제 #17
0
    public static void Main()
    {
        Example1 ex1 = new Example1();

        GetOsVersion();
        Console.WriteLine();
        GetClrVersion();
        Console.WriteLine();
        GetSpecificAssemblyVersion();
        Console.WriteLine();
        ex1.GetExecutingAssemblyVersion();
        Console.WriteLine();
        GetApplicationVersion();
    }
예제 #18
0
        static void Main(string[] args)
        {
            bool print = args.Contains("--print");

            Check("Example  1", Example1.Run(print));
            Check("Example  2", Example2.Run(print));
            Check("Example  3", Example3.Run(print));
            Check("Example  4", Example4.Run(print));
            Check("Example  5", Example5.Run(print));
            Check("Example  6", Example6.Run(print));
            Check("Example  7", Example7.Run(print));
            Check("Example  8", Example8.Run(print));
            Check("Example  9", Example9.Run());
            Check("Example 10", Example10.Run(print));
            Check("Example 11", Example11.Run(print));
        }
예제 #19
0
        public async Task GivenValidVersion_WhenGettingValue_ThenReturnCachedValue()
        {
            using CancellationTokenSource source = new CancellationTokenSource();

            _schemaVersionResolver.GetCurrentVersionAsync(source.Token).Returns((SchemaVersion)SchemaVersionConstants.Min);
            Example1 first = (await _versionedCache.GetAsync(source.Token)) as Example1;

            Assert.NotNull(first);
            await _schemaVersionResolver.Received(1).GetCurrentVersionAsync(source.Token);

            _schemaVersionResolver.GetCurrentVersionAsync(source.Token).Returns((SchemaVersion)SchemaVersionConstants.Max);
            Example1 second = (await _versionedCache.GetAsync(source.Token)) as Example1;

            Assert.Same(first, second);
            await _schemaVersionResolver.Received(1).GetCurrentVersionAsync(source.Token);
        }
예제 #20
0
        public void CommandState_ShouldBeHidden_WhenFolderDoesNotExist()
        {
            // arrange
            var doSomethingCommand = new Example1();
            var commandContext     = new CommandContext();

            using (var db = new Db {
            })
            {
                // act
                var commandState = doSomethingCommand.QueryState(commandContext);

                // assert
                commandState.Should().Be(CommandState.Hidden);
            }
        }
예제 #21
0
        static void Main()
        {
            // Speech SDK needs to be installed
            // https://www.microsoft.com/en-us/download/details.aspx?id=10121
            Example1.Test();

#if false
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
#endif


            System.Console.WriteLine(System.Environment.NewLine);
            System.Console.WriteLine(" --- Press any key to continue --- ");
            System.Console.ReadKey();
        }
        public void Store_Structs_And_Get_Logs()
        {
            var contractAddress1 = new uint160(1);
            var contractAddress2 = new uint160(2);

            var state1 = new TestSmartContractState(null, new TestMessage {
                ContractAddress = contractAddress1.ToAddress(this.network)
            }, null, null, null, null, null, null, null);
            var log1 = new Example1("Jordan", 12345);
            var log2 = new Example1("John", 123);

            var state2 = new TestSmartContractState(null, new TestMessage {
                ContractAddress = contractAddress2.ToAddress(this.network)
            }, null, null, null, null, null, null, null);
            var log3 = new Example2(new Address("mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRfn"), "This is a test message.", 16);

            this.logHolder.Log(state1, log1);
            this.logHolder.Log(state1, log2);
            this.logHolder.Log(state2, log3);

            IList <Log> logs = this.logHolder.GetRawLogs().ToLogs(this.serializer);

            Assert.Equal(3, logs.Count);

            // First log has 3 topics, for name and 2 fields.
            Assert.Equal(contractAddress1, logs[0].Address);
            Assert.Equal(3, logs[0].Topics.Count);
            Assert.Equal(nameof(Example1), Encoding.UTF8.GetString(logs[0].Topics[0]));
            Assert.Equal(log1.Name, Encoding.UTF8.GetString(logs[0].Topics[1]));
            Assert.Equal(log1.Amount, BitConverter.ToUInt32(logs[0].Topics[2]));

            // Second log has 3 topics, for name and 2 fields.
            Assert.Equal(contractAddress1, logs[1].Address);
            Assert.Equal(3, logs[1].Topics.Count);
            Assert.Equal(nameof(Example1), Encoding.UTF8.GetString(logs[1].Topics[0]));
            Assert.Equal(log2.Name, Encoding.UTF8.GetString(logs[1].Topics[1]));
            Assert.Equal(log2.Amount, BitConverter.ToUInt32(logs[1].Topics[2]));

            // Third log has 4 topics, for name and 3 fields.
            Assert.Equal(contractAddress2, logs[2].Address);
            Assert.Equal(4, logs[2].Topics.Count);
            Assert.Equal(nameof(Example2), Encoding.UTF8.GetString(logs[2].Topics[0]));
            Assert.Equal(log3.Address, new uint160(logs[2].Topics[1]).ToAddress(this.network));
            Assert.Equal(log3.Message, Encoding.UTF8.GetString(logs[2].Topics[2]));
            Assert.Equal(log3.Id, BitConverter.ToInt32(logs[2].Topics[3]));
        }
        public void Store_Structs_And_Get_Logs()
        {
            var contractAddress1 = new uint160(1);
            var contractAddress2 = new uint160(2);

            var state1 = new TestSmartContractState(null, new TestMessage {
                ContractAddress = contractAddress1.ToAddress()
            }, null, null, null, null, null, null, null);
            var log1 = new Example1("Jordan", 12345);
            var log2 = new Example1("John", 123);

            var state2 = new TestSmartContractState(null, new TestMessage {
                ContractAddress = contractAddress2.ToAddress()
            }, null, null, null, null, null, null, null);
            var log3 = new Example2("0x95D34980095380851902ccd9A1Fb4C813C2cb639".HexToAddress(), 16, "This is a test message.");

            this.logHolder.Log(state1, log1);
            this.logHolder.Log(state1, log2);
            this.logHolder.Log(state2, log3);

            IList <Log> logs = this.logHolder.GetRawLogs().ToLogs(this.serializer);

            Assert.Equal(3, logs.Count);

            // First log has 3 topics, for name and 2 fields.
            Assert.Equal(contractAddress1, logs[0].Address);
            Assert.Equal(3, logs[0].Topics.Count);
            Assert.Equal(nameof(Example1), Encoding.UTF8.GetString(logs[0].Topics[0]));
            Assert.Equal(log1.Name, Encoding.UTF8.GetString(logs[0].Topics[1]));
            Assert.Equal(log1.Amount, BitConverter.ToUInt32(logs[0].Topics[2]));

            // Second log has 3 topics, for name and 2 fields.
            Assert.Equal(contractAddress1, logs[1].Address);
            Assert.Equal(3, logs[1].Topics.Count);
            Assert.Equal(nameof(Example1), Encoding.UTF8.GetString(logs[1].Topics[0]));
            Assert.Equal(log2.Name, Encoding.UTF8.GetString(logs[1].Topics[1]));
            Assert.Equal(log2.Amount, BitConverter.ToUInt32(logs[1].Topics[2]));

            // Third log has 3 topics, for name and 2 indexed fields - message is not included.
            Assert.Equal(contractAddress2, logs[2].Address);
            Assert.Equal(3, logs[2].Topics.Count);
            Assert.Equal(nameof(Example2), Encoding.UTF8.GetString(logs[2].Topics[0]));
            Assert.Equal(log3.Address, new uint160(logs[2].Topics[1]).ToAddress());
            Assert.Equal(log3.Id, BitConverter.ToInt32(logs[2].Topics[2]));
        }
        public void FieldsAndMethods()
        {
            // Objects of classes can have fields and methods.
            Example1 obj = new Example1();

            // modify a field:
            obj.a = 2;
            Assert.Equal(2, obj.a);

            // call a method:
            Assert.Equal(4, obj.GetSquareOfA());

            // But you can only access them if they are public. This would be illegal:
            //obj.b = 3;

            // But methods of the class can access non-public fields:
            Assert.Equal(2, obj.GetB());
        }
        public void A_FieldsAndMethods()
        {
            // Objects of classes can have fields and methods.
            Example1 obj = new Example1();

            // modify a field:
            obj.a = 2;
            Assert.Equal(FILL_ME_IN, obj.a);

            // call a method:
            Assert.Equal(FILL_ME_IN, obj.GetSquareOfA());

            // But you can only access them if they are public. This would be illegal:
            //obj.b = 3;

            // But methods of the class can access non-public fields:
            Assert.Equal(FILL_ME_IN, obj.GetB());
        }
예제 #26
0
        public void PassingClassObjectsWithTheOutKeyword()
        {
            Example1 obj1 = new Example1();
            Example1 obj2 = obj1;

            // obj1 and obj2 are references that point to the same object in memory
            Assert.Equal(true, obj1 == obj2);

            // If an object is passed to a method with the out keyword, the address of the variable is passed,
            // so the address that is stored in obj1 can be changed by the method.
            // This is identical to ref, except that the method is guaranteed to work if the object is not
            // initialized, and that an assignment to it will be done.
            // Otherwise there will be a compilation error in the method.
            // Note that you need to add the out keyword in the call as well, this makes it clearer at the
            // call site what the intention of the method is.
            OutClass(out obj1);
            Assert.Equal(false, obj1 == obj2);
        }
예제 #27
0
        public void CommandState_ShouldBeHidden_WhenNoChildren()
        {
            // arrange
            var folderId           = new ID("{B4F0DAD0-B60E-49D9-8332-8DF1A61C5101}");
            var doSomethingCommand = new Example1();
            var commandContext     = new CommandContext();

            using (var db = new Db
            {
                new DbItem("Folder", folderId)
            })
            {
                // act
                var commandState = doSomethingCommand.QueryState(commandContext);

                // assert
                commandState.Should().Be(CommandState.Hidden);
            }
        }
예제 #28
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            #region Exmaple One
            Example1 example       = new Example1();
            int[]    numbers       = new[] { 1, 2, -4, 5, 6 };
            int      notFoundValue = 0;

            // Without Ref
            int result = example.GetFirstNegativeNumberWithoutRef(numbers);
            Console.WriteLine(result); // -4
            result++;                  //-3
            Console.WriteLine(result); // -3
            result = example.GetFirstNegativeNumberWithoutRef(numbers);
            Console.WriteLine(result); // -4 (without ref return it would chnaged the value)

            // With Ref
            ref int result1 = ref example.GetFirstNegativeNumberWithRef(numbers, ref notFoundValue);
예제 #29
0
        public void PassingClassObjectsByReference()
        {
            Example1 obj1 = new Example1();
            Example1 obj2 = obj1;

            // obj1 and obj2 are references that point to the same object in memory
            Assert.Equal(true, obj1 == obj2);

            // If an object is passed to a method but not by reference, the address of the object is passed,
            // so the address that is stored in obj1 cannot be changed by the method.
            // (the same as in Java, or as passing a pointer in C/C++)
            PassClassNotByRef(obj1);
            Assert.Equal(true, obj1 == obj2);

            // However, if an object is passed by reference, the address of the variable is passed to the method,
            // so it can change to memory location obj1 is pointing.
            // Note that you need to add the keyword ref in front of the argument in both the method and the call.
            // (the same as a pointer to a pointer in C/C++)
            PassClassByRef(ref obj1);
            Assert.Equal(false, obj1 == obj2);
        }
예제 #30
0
        public void CommandState_ShouldBeEnabled_WhenChildrenExist()
        {
            // arrange
            var folderId           = new ID("{B4F0DAD0-B60E-49D9-8332-8DF1A61C5101}");
            var doSomethingCommand = new Example1();
            var commandContext     = new CommandContext();

            using (var db = new Db
            {
                new DbItem("Folder", folderId)
                {
                    new DbItem("child 1"),
                    new DbItem("child 2")
                }
            })
            {
                // act
                var commandState = doSomethingCommand.QueryState(commandContext);

                // assert
                commandState.Should().Be(CommandState.Enabled);
            }
        }
예제 #31
0
파일: Task5.cs 프로젝트: akirarizky14/-
        public static void Prog5()
        {
            string   path    = "C:\\OS";
            Example1 example = new Example1()
            {
                hello = 123
            };

            using (var file = new StreamWriter($"{path}\\test.xml"))
            {
                XmlSerializer x = new XmlSerializer(typeof(Example1));
                x.Serialize(file, example);
            }

            Console.WriteLine("Do you want to delete the file ? y/n");
            if (Console.ReadLine().Equals("y"))
            {
                path = "C:\\OS\test.xml";
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
        }
예제 #32
0
        static void Main()
        {
            Example1 example1 = new Example1();

            example1.ShowExample();

            Example2 example2 = new Example2();

            example2.ShowExample();

            Example3 example3 = new Example3();

            example3.ShowExample();

            Example4 example4 = new Example4();

            example4.ShowExample();

            Example5 example5 = new Example5();

            example5.ShowExample();

            Console.ReadKey();
        }
 public void C_ConstructorsWithArguments()
 {
     // Classes can can have constructors with arguments:
     Example1 obj = new Example1(3);
     Assert.Equal(FILL_ME_IN, obj.a);
 }
 public void B_Constructors()
 {
     // Classes can can have constructors which are called when you create an object of the class with new:
     Example1 obj = new Example1();
     Assert.Equal(FILL_ME_IN, obj.a);
 }