obis-mapper 0.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package obis-mapper --version 0.0.3                
NuGet\Install-Package obis-mapper -Version 0.0.3                
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="obis-mapper" Version="0.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add obis-mapper --version 0.0.3                
#r "nuget: obis-mapper, 0.0.3"                
#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 obis-mapper as a Cake Addin
#addin nuget:?package=obis-mapper&version=0.0.3

// Install obis-mapper as a Cake Tool
#tool nuget:?package=obis-mapper&version=0.0.3                

obis-mapper

obis-mapper is a lightweight .NET library that simplifies the mapping of values to model properties based on logical names. It supports nested models, handles nullable types, allows for default values in case of conversion errors, and provides customizable conversion logic through custom property mappings.

Features

  • Logical Name Mapping: Map values to properties based on logical names, with support for tags to distinguish between different mappings.
  • Nested Models: Automatically handles nested models through recursion, making it easy to work with complex object structures.
  • Custom Property Mapping: Define custom conversion logic for properties, allowing flexibility in how values are mapped and converted.
  • Default Values: Specify default values for properties in case of conversion errors, ensuring robustness in data mapping.
  • Flexible Type Conversion: Supports nullable types and provides customizable conversion handling.

Installation

You can install obis-mapper via NuGet Package Manager or .NET CLI.

NuGet Package Manager

Install-Package obis-mapper

.NET CLI

dotnet add package obis-mapper

Usage

Basic Usage

To start using obis-mapper, annotate your model properties with the LogicalNameMappingAttribute and optionally the NestedModelAttribute for nested models.

using ObisMapper;

public class SimpleModel
{
    [LogicalNameMapping("1.1.1.1")] 
    public int FirstNumericData { get; set; }

    [LogicalNameMapping("1.1.1.2")] 
    public int SecondNumericData { get; set; }

    [LogicalNameMapping("1.1.2.1")] 
    public string FirstStringData { get; set; }

    [LogicalNameMapping("1.1.2.2")] 
    public string SecondStringData { get; set; }
}

Mapping Values

Use the FillObisModel extension method to map values to your model based on logical names.

var model = new SimpleModel();
model.FillObisModel("1.1.1.1", 100);
model.FillObisModel("1.1.2.1", "Example");

Nested Models

For nested models, use the NestedModelAttribute.

public class ComplexModel
{
    [NestedModel]
    public SimpleModel Nested { get; set; }

    [LogicalNameMapping("2.1.1.1")] 
    public double SomeData { get; set; }
}

var complexModel = new ComplexModel();
complexModel.FillObisModel("1.1.1.1", 100);

Custom Property Mapping

To define custom conversion logic for properties, use the CustomPropertyMapping class.

var customMapping = new CustomPropertyMapping<SimpleModel>()
    .CreateMapping(
        m => m.FirstNumericData, 
        (currentValue, value) => currentValue + Convert.ToInt32(value)
    );

var model = new SimpleModel();
model.FillObisModel("1.1.1.1", 100, customMapping: customMapping);

Handling Conversion Errors and Default Values

You can specify a default value in the LogicalNameMappingAttribute to handle cases where conversion fails.

public class ModelWithDefaults
{
    [LogicalNameMapping("1.1.1.1", DefaultValue = 42)] 
    public int ValueWithDefault { get; set; }
}

var model = new ModelWithDefaults();
model.FillObisModel("1.1.1.1", "InvalidValue");

In this example, ValueWithDefault will be set to 42 if the provided value is invalid.

Documentation

In-development.

Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.


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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.1

    • 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
0.0.4 633 8/30/2024
0.0.3 103 8/29/2024
0.0.2 95 8/28/2024
0.0.1 98 8/28/2024