Skip to content

Commit 6dcc32a

Browse files
committed
Reflection with Assembly and Type types
1 parent 1a08bbb commit 6dcc32a

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>_20_Reflection</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Reflection;
2+
3+
#region Reflection with Assembly type
4+
5+
Assembly assembly = Assembly.GetExecutingAssembly(); // Get the current assembly
6+
var types = assembly.GetTypes(); // Get all types in the assembly
7+
8+
#endregion
9+
10+
#region Reflection with Type type
11+
12+
MyClass m1 = new MyClass();
13+
Type type = m1.GetType(); // Get the type of the object
14+
Type type2 = typeof(MyClass); // Get the type of the class
15+
16+
#endregion
17+
18+
Console.WriteLine();
19+
20+
21+
22+
class MyClass
23+
{
24+
public int MyProperty { get; set; }
25+
public int MyProperty2 { get; set; }
26+
public string MyProperty3 { get; set; }
27+
int MyProperty4 { get; set; }
28+
int MyField;
29+
public void MyMethod() { }
30+
}

Advanced-C#-Programming/Advanced-C#-Programming.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "18_Custom-Collection-Initia
3939
EndProject
4040
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "19_Attributes", "19_Attributes\19_Attributes.csproj", "{F78E01F6-04B9-4941-B5CF-69013C4921E4}"
4141
EndProject
42+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "20_Reflection", "20_Reflection\20_Reflection.csproj", "{13B7EA4F-231D-4553-BEAC-6A439C1370D6}"
43+
EndProject
4244
Global
4345
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4446
Debug|Any CPU = Debug|Any CPU
@@ -117,6 +119,10 @@ Global
117119
{F78E01F6-04B9-4941-B5CF-69013C4921E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
118120
{F78E01F6-04B9-4941-B5CF-69013C4921E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
119121
{F78E01F6-04B9-4941-B5CF-69013C4921E4}.Release|Any CPU.Build.0 = Release|Any CPU
122+
{13B7EA4F-231D-4553-BEAC-6A439C1370D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
123+
{13B7EA4F-231D-4553-BEAC-6A439C1370D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
124+
{13B7EA4F-231D-4553-BEAC-6A439C1370D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
125+
{13B7EA4F-231D-4553-BEAC-6A439C1370D6}.Release|Any CPU.Build.0 = Release|Any CPU
120126
EndGlobalSection
121127
GlobalSection(SolutionProperties) = preSolution
122128
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)