Step by step migration of ASP.NET Core 2.2 to 3.1

In order to upgrade/migrate core version to 3.1 following steps to be perform.
Download and install Visual Studio 2019 version 16.4 or higher.Download and install .NET Core 3.1 the projects of solution to .NET Core 3.1 , because ASP.NET Core 3.1 requires it.Update existing Nuget packages to a version compatible with ASP.NET Core 3.1 in each projectUse IHost interface from a IHostBuilder instead of building and running a IWebHost from a IWebHostBuilder in Program.cs public static IHostBuilder CreateWebHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseKestrel() .UseSerilog() .UseStartup<Startup>(); }) Change AddMvc method has been replaced by AddControllers in Startup.cs of each projects.In Startup.cs,UseMvc method to be replaced by…

clone a generic list in C# using extension method

In practical situation you need to clone of object so that change in cloned object will not affect the original one.
If you need a cloned list with the same capacity you need to do some extra stuff with your user type.

I came up with this easy solution using ICloneable interface in your custom type class.

The first step you need to implement the ICloneable interface in your class like below.

 public class MyClassDto : ICloneable  
     public Int64 Id { get; set; }  
     public string Time { get; set; }  
     public int user{ get; set; }  
     public object Clone()  
       return new MyClassDto{ Date = this.Date, Id = this.Id, user = this.user};  

after that you need to add extension method in common class so that you can use it everywhere you want.

 public static class Extensions  
     public static List<T> Clone<T>(this List<T> listToClone) where T : ICloneable  
       return listToClone.Select(item => (T)item.Clone()).ToList();  

the above extension will clone the list and return the cloned list using linq.

you can now use the extension in your code where you want to cloned generic list.

 List<MyClassDto> lst=new List<MyClassDto>();  
 lst.Add(new MyClassDto{id=1,Time="10.20",user=2})  
 lst.Add(new MyClassDto{id=2,Time="10.21",user=3})  
 var userInfoPush = lst.Clone<MyClassDto>(); 

That's it. Now your generic list will be cloned successfully


Popular posts from this blog

Restore the lost focus of Auto post back controls in update Panel control

Add Comma automatically while entering amounts in textbox using Javascript

Devexpress Datebox date formatting in angular 6 with example