public void TestCopyDifferentType(TestClassForQ2N1 originalObject, TestClassForQ2N2 targetObject) { Console.WriteLine("Test results:"); Console.WriteLine($"1. Copy same property name and type, different object type: {originalObject.Name == targetObject.Name}."); //Testing if different types are similar with ToString(). Console.WriteLine($"2. Copy property with same name, but different type- List<int> and List<string>: {originalObject.MonthlyIncome[0].ToString() == targetObject.MonthlyIncome[0]}."); Console.WriteLine($"3. Copy Get but no Set original property to Get and Set target property- double: {originalObject.Hight.Equals(targetObject.Hight)}."); Console.WriteLine($"4. Copy with same property type, but different name- int age and int weight: {originalObject.Age == targetObject.Weight}."); Console.WriteLine($"5. Copy private set, same property, different object type- bool: {originalObject.NotDeadYet == targetObject.NotDeadYet}."); //No need to check 6... It's false Console.WriteLine($"6. Copy private property, same property, different object type: If test 1 was false, this has to be false."); }
static void Main(string[] args) { //LAB 4.1 (1.a) Console.WriteLine("LAB 4.1 (1.a):"); Console.WriteLine(); var assemblyQueryTool = new AssemblyPublicInterfaceQuery(); var msCoreLibAssembly = typeof(string).Assembly; var typsInAssembly = assemblyQueryTool.GetSortedList(msCoreLibAssembly); Console.WriteLine($"List of public Interfaces and number of methods in each type for assembly- {msCoreLibAssembly}:"); Console.WriteLine(); foreach (var type in typsInAssembly) { Console.WriteLine(type); Console.WriteLine($"Number of methods in public interface: {type.GetMethods().Count()}."); } //LAB 4.1 (1.b+C) Console.WriteLine(); Console.WriteLine("LAB 4.1 (1.b+C):"); Console.WriteLine(); var processDisplayerTool = new ProcessDisplayer(); const int maxThreads = 4; var processesByPriority = processDisplayerTool.GetProcesses(maxThreads); Console.WriteLine(); Console.WriteLine($"List of current system processes with less than {maxThreads} sorted by priority:"); foreach (var priorityGroup in processesByPriority) { Console.WriteLine(); Console.WriteLine($"Priority group is : {priorityGroup.Key}"); foreach (var process in priorityGroup) { if (processDisplayerTool.CanAccessTimeStart(process)) { Console.WriteLine($"Process Name: {process.ProcessName}. Process ID: {process.Id}. Process Starting time: {process.StartTime}. Process number of threads: {process.Threads.Count}."); } else { Console.WriteLine($"Process Name: {process.ProcessName}. Process ID: {process.Id}. Process Starting time: Access Denied! Process number of threads: {process.Threads.Count}."); } } } //LAB 4.1 (1.d) Console.WriteLine(); Console.WriteLine("LAB 4.1 (1.d):"); Console.WriteLine(); var threadCounterTool = new ThreadCounter(); Console.WriteLine($"Total number of threads in system: {threadCounterTool.Count()}"); //Lab 4.1 (2) Console.WriteLine(); Console.WriteLine("Lab 4.1 (2):"); Console.WriteLine(); //Creating two objects from the same type for testing of extention method CopyTo() var testOriginalObject = new TestClassForQ2N1("Lachman", new List <int>() { 5000, 8000, 7000 }, 1.70, 86, true, "Sematary"); var testTargetObject = new TestClassForQ2N1("Miley", new List <int>() { 15000, 18000, 17000 }, 1.50, 27, false, "HollyWood"); //Creating object of different type to test extention method CopyTo() var testTargetObject2 = new TestClassForQ2N2("Miley", new List <string>() { "15000", "18000", "17000" }, 1.50, 75, false, "HollyWood"); Console.WriteLine(); Console.WriteLine("Test 1: Testing CopyTo() on two objects from same type TestClassForQ2N1"); Console.WriteLine("Test 1 - before extention method- CopyTo():"); Console.WriteLine(testOriginalObject); Console.WriteLine(testTargetObject); testOriginalObject.CopyTo(testTargetObject); Console.WriteLine("Test 1 - after extention method- CopyTo():"); Console.WriteLine(testTargetObject); Console.WriteLine(); testTargetObject.TestCopy(testOriginalObject, testTargetObject); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Test 2: Testing CopyTo() on two objects from different types: TestClassForQ2N1 and TestClassForQ2N2"); Console.WriteLine("Test 2 - before extention method- CopyTo():"); Console.WriteLine(testOriginalObject); Console.WriteLine(testTargetObject2); testOriginalObject.CopyTo(testTargetObject2); Console.WriteLine("Test 2 - after extention method- CopyTo():"); Console.WriteLine(testTargetObject2); Console.WriteLine(); testTargetObject2.TestCopyDifferentType(testOriginalObject, testTargetObject2); Console.WriteLine(); Console.WriteLine("All tests turned out as expected."); }