SetApi.SimpleExtensions 1.1.1

dotnet add package SetApi.SimpleExtensions --version 1.1.1
                    
NuGet\Install-Package SetApi.SimpleExtensions -Version 1.1.1
                    
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="SetApi.SimpleExtensions" Version="1.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SetApi.SimpleExtensions" Version="1.1.1" />
                    
Directory.Packages.props
<PackageReference Include="SetApi.SimpleExtensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SetApi.SimpleExtensions --version 1.1.1
                    
#r "nuget: SetApi.SimpleExtensions, 1.1.1"
                    
#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.
#addin nuget:?package=SetApi.SimpleExtensions&version=1.1.1
                    
Install SetApi.SimpleExtensions as a Cake Addin
#tool nuget:?package=SetApi.SimpleExtensions&version=1.1.1
                    
Install SetApi.SimpleExtensions as a Cake Tool

SimpleExtensions

NuGet version Build status

Simple useful extensions for C#.

Usage

See Tests for more examples, such as:

The main purpose of this extension library is to simplify the implementation of the business logic of your application, for example:

using System;
using SimpleExtensions;
using System.Collections.Generic;
using System.Linq;

public class ViewFactory {

    public IEnumerable<Item> GetItems() =>
         new[] { new Item{ Id = 1, Name = "Item 1", TypeItem = 1, ProviderId = 10, AppsIds = new [] {3,5,7,7 }, Value = "0.15", Start = "2017-12-4" },
                    new Item{ Id = 2, Name = "Item 3", TypeItem = 1, ProviderId = 7, AppsIds = new [] { 3 }, Value = "0.15", Start = "2017-12-4" },
                    new Item{ Id = 3, Name = "Item 4", TypeItem = 2, ProviderId = 10, AppsIds = new int[0]  },
                    new Item{ Id = 4, Name = "Item 5", TypeItem = 2, ProviderId = 8, AppsIds = new [] {5, 5} },
                    new Item{ Id = 5, Name = "Item 5", TypeItem = 2, ProviderId = 10, AppsIds = new [] {3,7 } } };


    public IEnumerable<Apps> GetApps() => new[] {
        new Apps { Id = 3, Assignment = "First"},
        new Apps { Id = 4, Assignment = "Second"},
        new Apps { Id = 5, Assignment = "Last"},
        new Apps { Id = 7, Assignment = "Slightly more than last"}
    };

    public IEnumerable<Provider> GetProviders() =>
         new[] { new Provider{ Id = 10, Name = "Provider 10", Enable = true },
                    new Provider{ Id = 8, Name = "Provider 8", Enable = true },
                    new Provider{ Id = 8, Name = "Provider 8", Enable = true }};

    public enum Event {
        New, Create, More, Empty
    }

    public IEnumerable<ItemHistory> GetItemHistory() => new[] {
        new ItemHistory{ ItemId = 1, Time = "2017-2-23 10:13", Event = "New" },
        new ItemHistory{ ItemId = 1, Time = "2017-2-23 10:13", Event = "New" },
        new ItemHistory{ ItemId = 3, Time = "2017-2-23 10:13", Event = "Create" },
        new ItemHistory{ ItemId = 3, Time = "2017-2-23 10:13", Event = "Create" },
        new ItemHistory{ ItemId = 1, Time = "2017-2-23 10:13", Event = "New" },
        new ItemHistory{ ItemId = 4, Time = "2017-2-23 10:13", Event = "More" },
        new ItemHistory{ ItemId = 16, Time = "2017-2-23 10:13", Event = "Empty" },
    };

    public IEnumerable<ItemType> GetItemTypes() =>
         new[] { new ItemType{ Id = 1, Type = "Food" },
                       new ItemType{ Id = 2, Type = "Thing" },
                       new ItemType{ Id = 3, Type = "Lump" } };


    public ViewModel GetView() {
        var providers = GetProviders().ToDictionaryTry(i => i.Id);
        var itemTypes = GetItemTypes().ToDictionaryTry(i => i.Id);
        var apps = GetApps().ToDictionaryTry(i => i.Id);
        var history = GetItemHistory().GroupByToDictionary(h => h.ItemId, h => new ViewEvent{ Event = h.Event.ToEnum<Event>(), Time = h.Time.ToDateTime() });

        return new ViewModel {
            Items = GetItems().Where(i => providers.ContainsKey(i.ProviderId) && itemTypes.ContainsKey(i.TypeItem))
                        .Select(i => new ViewItem {
                            Id = i.Id,
                            Name = i.Name,
                            Value = i.Value.ToDecimal(),
                            DateStart = i.Start.ToDateTime(),
                            Provider = providers.TryGetValue(i.ProviderId),
                            Type = itemTypes.TryGetValue(i.TypeItem)?.Type ?? "No Type",
                            Apps = i.AppsIds.Where(id => apps.ContainsKey(id)).Select(apps.TryGetValue),
                            History = history.TryGetValue(i.Id) ?? new ViewEvent[0]
                        })
        };
    }
}
....

Installation

The library itself can also be installed in your application using the NuGet package manager.

PM> Install-Package SetApi.SimpleExtensions
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.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.1.1 1,869 9/7/2018
1.1.0 1,095 3/2/2018
1.0.1 1,073 2/21/2018
1.0.0 914 2/21/2018