INNOBATE.System.Collections.Generic 1.0.2

dotnet add package INNOBATE.System.Collections.Generic --version 1.0.2
NuGet\Install-Package INNOBATE.System.Collections.Generic -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="INNOBATE.System.Collections.Generic" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add INNOBATE.System.Collections.Generic --version 1.0.2
#r "nuget: INNOBATE.System.Collections.Generic, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install INNOBATE.System.Collections.Generic as a Cake Addin
#addin nuget:?package=INNOBATE.System.Collections.Generic&version=1.0.2

// Install INNOBATE.System.Collections.Generic as a Cake Tool
#tool nuget:?package=INNOBATE.System.Collections.Generic&version=1.0.2

System.Collections.Generics Collection

Extension methods for System.Collections.Generics

ToDataTable

The provided code is a C# extension method that converts a List<T> to a DataTable. Here's a brief explanation of the code:

  • The ToDataTable<T> method creates a new DataTable and sets its name to the name of the type T.
  • It then gets all the public instance properties of the type T and adds them as columns to the DataTable.
  • For each item in the list, it gets the values of the properties and adds them as a new row to the DataTable.
  • The IsNullable method checks if a type is nullable. It returns true if the type is either a reference type or a Nullable value type.
  • The GetCoreType method returns the underlying type if the type is nullable, otherwise it returns the type itself.

This extension method can be useful when you need to convert a list of objects to a DataTable for data processing or data binding purposes. For example, you might use it when binding data to a GridView in ASP.NET or when you need to perform operations on the data using ADO.NET.

Please note that this method only considers public instance properties of the type T. Non-public properties, static properties, and fields are not included in the DataTable. If you need to include these members, you would need to modify the method accordingly.

Also, this method does not support complex types or nested types. If the type T contains properties that are complex types or nested types, you would need to handle them separately.

Eaxample

An example of how you can use the ToDataTable<T> method. This example assumes that you have a List<Student> where Student is a class with properties Name and Age.

public class Student
{
    public string Name { get; set; }
    public int Age { get; set; }
}

public class Program
{
    static void Main(string[] args)
    {
        // Create a list of students
        List<Student> students = new List<Student>
        {
            new Student { Name = "John Doe", Age = 20 },
            new Student { Name = "Jane Doe", Age = 22 },
            new Student { Name = "Jim Doe", Age = 24 },
        };

        // Convert the list of students to a DataTable
        DataTable dt = students.ToDataTable();

        // Print the DataTable to the console
        foreach (DataRow row in dt.Rows)
        {
            foreach (DataColumn column in dt.Columns)
            {
                Console.Write($"{row[column]} ");
            }
            Console.WriteLine();
        }
    }
}

In this code, we first create a list of Student objects. We then call the ToDataTable method on this list to convert it into a DataTable. Finally, we print the contents of the DataTable to the console.

This will output:

John Doe 20
Jane Doe 22
Jim Doe 24

Shuffle

A new extension method for IEnumerable<T> called Shuffle. This method uses the random number generator to shuffle a collection, returning a new sequence with the elements in a random order

Example Showing Shuffle extension method in a .NET application

class Program
{
    static void Main()
    {
        var numbers = Enumerable.Range(1, 10).ToList();
        var shuffledNumbers = numbers.OrderByShuffle().ToList();

        Console.WriteLine("Original numbers:");
        foreach (var number in numbers)
        {
            Console.Write(number + " ");
        }

        Console.WriteLine("\nShuffled numbers:");
        foreach (var number in shuffledNumbers)
        {
            Console.Write(number + " ");
        }
    }
}

In this example, we first create a list of numbers from 1 to 10. We then use the OrderByShuffle extension method to shuffle this list. The shuffled list is then printed to the console.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 242 11/13/2023
1.0.1 88 11/13/2023
1.0.0 232 9/8/2022