Отражение — это получение информации о типе, с помощью объекта класса Type.
Требуется подключить пространство имен System.Reflection
Требуется подключить пространство имен System.Reflection
Main.cs
usingSystem;//подключить пространство именusingSystem.Reflection;publicclassCounter {-
ushortshowStart; -
ushortshowEnd; -
decimalprice; -
publicCounter(ushortarg0,ushortarg1,decimalarg2) { -
showStart = arg0; -
showEnd = arg1; -
price = arg2; -
} -
publicushortResultShow() { -
return(ushort)(showEnd-showStart); -
} -
publicdecimalSum() { -
returnMath.Round((decimal)(ResultShow()*price), 2); -
} }classProgram {-
publicstaticintMain() { -
Console.WriteLine("оплата за электроэнергию\n"); -
Console.Write("Введите начальные показания счетчика : "); -
ushortshow_start =ushort.Parse(Console.ReadLine()); -
Console.Write("Введите конечные показания счетчика : "); -
ushortshow_end =ushort.Parse(Console.ReadLine()); -
Console.Write("Введите цену за 1 кВт/ч : "); -
decimalprice =decimal.Parse(Console.ReadLine()); -
Counter C =newCounter(show_start, show_end, price); -
Console.WriteLine("Сумма за электроэнергию : {0}", C.Sum()); -
Console.WriteLine(); -
//создаем объект класса Type и присваиваем ему значение - тип класса -
Type T =typeof(Counter); -
//получаем список членов класса -
MemberInfo[] arrayMembers = T.GetMembers(); -
foreach(var iinarrayMembers) { -
if(i !=null) { -
Console.WriteLine("член класса {0}", i); -
} -
else{ -
Console.WriteLine("член класса отсутствует"); -
} -
} -
Console.WriteLine(); -
//получаем список конструкторов класса -
ConstructorInfo[] arrayConstructors = T.GetConstructors(); -
foreach(var iinarrayConstructors) { -
if(i !=null) { -
Console.WriteLine("конструктор класса {0}", i); -
} -
else{ -
Console.WriteLine("конструктор класса отсутствует"); -
} -
} -
Console.WriteLine(); -
//получаем список методов класса -
MethodInfo[] arrayMethods = T.GetMethods(); -
foreach(var iinarrayMethods) { -
if(i !=null) { -
Console.WriteLine("метод класса {0}", i); -
} -
else{ -
Console.WriteLine("метод класса отсутствует"); -
} -
} -
Console.ReadKey(); -
return0; -
} }
usingSystem;//подключить пространство именusingSystem.Reflection;publicclassCounter {-
ushortshowStart; -
ushortshowEnd; -
decimalprice; -
publicCounter(ushortarg0,ushortarg1,decimalarg2) { -
showStart = arg0; -
showEnd = arg1; -
price = arg2; -
} -
publicushortResultShow() { -
return(ushort)(showEnd-showStart); -
} -
publicdecimalSum() { -
returnMath.Round((decimal)(ResultShow()*price), 2); -
} }classProgram {-
publicstaticintMain() { -
Console.WriteLine("оплата за электроэнергию\n"); -
Console.Write("Введите начальные показания счетчика : "); -
ushortshow_start =ushort.Parse(Console.ReadLine()); -
Console.Write("Введите конечные показания счетчика : "); -
ushortshow_end =ushort.Parse(Console.ReadLine()); -
Console.Write("Введите цену за 1 кВт/ч : "); -
decimalprice =decimal.Parse(Console.ReadLine()); -
Counter C =newCounter(show_start, show_end, price); -
Console.WriteLine("Сумма за электроэнергию : {0}", C.Sum()); -
Console.WriteLine(); -
//создаем объект класса Type и присваиваем ему значение - тип класса -
Type T =typeof(Counter); -
//получаем список членов класса -
MemberInfo[] arrayMembers = T.GetMembers(); -
foreach(var iinarrayMembers) { -
if(i !=null) { -
Console.WriteLine("член класса {0}", i); -
} -
else{ -
Console.WriteLine("член класса отсутствует"); -
} -
} -
Console.WriteLine(); -
//получаем список конструкторов класса -
ConstructorInfo[] arrayConstructors = T.GetConstructors(); -
foreach(var iinarrayConstructors) { -
if(i !=null) { -
Console.WriteLine("конструктор класса {0}", i); -
} -
else{ -
Console.WriteLine("конструктор класса отсутствует"); -
} -
} -
Console.WriteLine(); -
//получаем список методов класса -
MethodInfo[] arrayMethods = T.GetMethods(); -
foreach(var iinarrayMethods) { -
if(i !=null) { -
Console.WriteLine("метод класса {0}", i); -
} -
else{ -
Console.WriteLine("метод класса отсутствует"); -
} -
} -
Console.ReadKey(); -
return0; -
} }
оплата за электроэнергию
Введите начальные показания счетчика : 0
Введите конечные показания счетчика : 100
Введите цену за 1 кВт/ч : 0,3084
Сумма за электроэнергию : 30,84
член класса UInt16 ResultShow()
член класса System.Decimal Sum()
член класса System.String ToString()
член класса Boolean Equals(System.Object)
член класса Int32 GetHashCode()
член класса System.Type GetType()
член класса Void .ctor(UInt16, UInt16, System.Decimal)
конструктор класса Void .ctor(UInt16, UInt16, System.Decimal)
метод класса UInt16 ResultShow()
метод класса System.Decimal Sum()
метод класса System.String ToString()
метод класса Boolean Equals(System.Object)
метод класса Int32 GetHashCode()
метод класса System.Type GetType()
Введите начальные показания счетчика : 0
Введите конечные показания счетчика : 100
Введите цену за 1 кВт/ч : 0,3084
Сумма за электроэнергию : 30,84
член класса UInt16 ResultShow()
член класса System.Decimal Sum()
член класса System.String ToString()
член класса Boolean Equals(System.Object)
член класса Int32 GetHashCode()
член класса System.Type GetType()
член класса Void .ctor(UInt16, UInt16, System.Decimal)
конструктор класса Void .ctor(UInt16, UInt16, System.Decimal)
метод класса UInt16 ResultShow()
метод класса System.Decimal Sum()
метод класса System.String ToString()
метод класса Boolean Equals(System.Object)
метод класса Int32 GetHashCode()
метод класса System.Type GetType()