Advertisement
kanagara

Untitled

Feb 28th, 2021
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9.  
  10.  
  11. namespace Zadatak
  12. {
  13.  
  14.  
  15. class Program
  16. {
  17. static void Main(string[] args)
  18. {
  19. Type type = Type.GetType("System.String");
  20.  
  21. Console.WriteLine(type.Name);
  22. Console.WriteLine(type.Namespace);
  23. Console.WriteLine(type.Assembly);
  24. Console.WriteLine(type.BaseType);
  25. Console.WriteLine(type.IsAbstract);
  26. Console.WriteLine(type.IsGenericTypeDefinition);
  27. Console.WriteLine(type.IsSealed);
  28. Console.WriteLine(type.IsClass);
  29.  
  30. Console.WriteLine();
  31.  
  32. // Drugi deo zadatka
  33.  
  34.  
  35. Assembly assembly = null;
  36.  
  37. try
  38. {
  39. assembly = Assembly.Load("Zadatak");
  40. }
  41. catch (FileNotFoundException exc)
  42. {
  43. Console.WriteLine(exc.Message);
  44. }
  45.  
  46. if (assembly == null)
  47. return;
  48.  
  49.  
  50. Type countryType = assembly.GetType("Zadatak.Country");
  51. object countryObject = Activator.CreateInstance(countryType, new object[] { "Scotland", 4500000 });
  52.  
  53. MethodInfo methInfo = countryType.GetMethod("GetCountryInfo");
  54.  
  55. Console.WriteLine(methInfo.Invoke(countryObject, null));
  56.  
  57. }
  58. }
  59.  
  60. class Country
  61. {
  62. public string Name { get; set; }
  63. public int Population { get; set; }
  64.  
  65. public Country(string name, int population)
  66. {
  67. Name = name;
  68. Population = population;
  69. }
  70.  
  71. public string GetCountryInfo()
  72. {
  73. return "Country " + Name + " has the population of " + Population + ".";
  74. }
  75. }
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement