Search

How to Get all loaded assemblies in C#
By Tan Lee Published on Feb 04, 2025 344

In C#, you can get all loaded assemblies by using the AppDomain.CurrentDomain.GetAssemblies() method.

Read more
How to Get all classes that implement interface in C#
By Tan Lee Published on Feb 04, 2025 389

You can use reflection to retrieve all classes in the current assembly that implement a specific interface.

Read more
How to Use Convert.ChangeType to convert string to any type in C#
By Tan Lee Published on Feb 04, 2025 508

You can utilize Convert.ChangeType() to transform a string into any type, like this:

Read more
How to Convert a string to an int in C#
By Tan Lee Published on Feb 04, 2025 210

When working with C#, you'll often need to convert a string into an integer.

Read more
How to convert char to int in C#
By Tan Lee Published on Feb 04, 2025 257

onverting a char to an int means obtaining the numeric value that the char represents (e.g., ‘1’ becomes 1). This is different from casting a char to an int, which gives you the char's ASCII or Unicode value (e.g., ‘1’ is 49 in Unicode).

Read more
How to get types from assembly in C#
By Tan Lee Published on Feb 04, 2025 474

In C#, you can extract type information from an assembly through a reflection-only load. This process allows you to examine metadata without executing the assembly, which can help avoid runtime errors that typically occur with a fully loaded assembly.

Read more
How to Convert a list of strings into a set of enums in C#
By Tan Lee Published on Feb 04, 2025 231

Imagine you have a list of user roles that you read from a configuration file or a database when your application starts. Whenever a user logs in, you want to check if their assigned role is part of the allowed roles list.

Read more
How to Get subclass properties with reflection in C#
By Tan Lee Published on Feb 04, 2025 323

When you use reflection to get properties, you can retrieve only the subclass's properties by using BindingFlags.DeclaredOnly (which excludes inherited properties).

Read more
How to Check if a property is an enum with reflection in C#
By Tan Lee Published on Feb 04, 2025 279

When working with reflection to inspect a class’s properties, you can use PropertyInfo.PropertyType.IsEnum to determine if the property is an enum type.

Read more
How to load assemblies at runtime using Microsoft Extensibility Framework in C#
By Tan Lee Published on Feb 04, 2025 269

The Microsoft Extensibility Framework (MEF) is a powerful tool that allows you to load assemblies dynamically at runtime.

Read more