Some Helpful Extensions When Dealing With Types in .NET

If you are writing reusable code, chances are high that you will write quite some code that deals with types, generics, and interfaces. Over the years, the collection of my helper extensions for that have grown. As some of my upcoming posts use them, I share them (also) for future reference.

1. Check if a Type Is Deriving From Another Type

Deriving types is a common practice. To some extent, you can use pattern matching. Sometimes, that isn't enough, though (especially if you have a multi-level derivation path). This is when I use one of these two extensions:

Using .NET Caching in EF Core Through Extension Methods [Video]

Entity Framework (EF) Core is the new cross-platform and light-weight version of the popular Entity Framework from Microsoft. EF Core is an object-relational mapping engine for .NET that eliminates the need for most of the data-access code that developers otherwise write.

EF Core is increasingly being used in high transaction server applications (ASP.NET, WCF, and other .NET/.NET Core server apps). And, these applications need scalability to handle large amounts of user requests without slowing down. But, the database becomes a bottleneck and distributed caching must be used to eliminate this bottleneck.

Generic Extension Method to Map Objects From One Type to Another

Let me start with one scenario. Just imagine we have an object which has lots of public properties and we need to use only some properties of it for the user profile method. For example, we have a class Teacher_Interview and another class named Teacher_College.

Public class Teacher_Interview  
{  
    Public int UID {get; set;}  
    Public string Name {get; set;}  
    Public string Email {get; set;}  
    Public string Subject {get; set;}  
}  
  
Public class Teacher_College  
{  
    Public int TID {get; set;}  
    Public string Name {get; set;}  
    Public string Email {get; set;}  
}  

Here, we have written both the classes. As we can see, we have a Teacher_Interview class that contains its public properties. Now, we need to use the Teacher_College class object and want the same values from the Teacher_Interview class object.