Skip to content

Commit

Permalink
add feature to intercept property binding (#20)
Browse files Browse the repository at this point in the history
Add a functionally to intercept the property bind and convert it to primitive value or do something else.
  • Loading branch information
Daniel-iel authored Feb 6, 2023
1 parent 3ffaba7 commit 45f741f
Show file tree
Hide file tree
Showing 48 changed files with 1,343 additions and 374 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci-benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
env:
APP: "${{ github.workspace }}/app"
PROJECT_BIN5: "./app/Spinner/bin/Release/net5.0"
PROJECT_BENCH_WRITER: "./bench/Writer.Benchmark"
PROJECT_BENCH: "./bench/Spinner.Benchmark"

runs-on: ubuntu-latest

Expand Down Expand Up @@ -52,20 +52,20 @@ jobs:
dotnet-version: 7.0.100

- name: Clean Dependencies 📦
run: dotnet clean ${{env.PROJECT_BENCH_WRITER }}
run: dotnet clean ${{env.PROJECT_BENCH }}

- name: Restore Dependencies 📦
run: dotnet restore ${{env.PROJECT_BENCH_WRITER }}
run: dotnet restore ${{env.PROJECT_BENCH }}

- name: Build ⚙️
run: dotnet build ${{env.PROJECT_BENCH_WRITER }} -c Release -p:Version=$BUILD_VERSION --no-restore
run: dotnet build ${{env.PROJECT_BENCH }} -c Release -p:Version=$BUILD_VERSION --no-restore

- name: Publish 📮
run: dotnet publish ${{env.PROJECT_BENCH_WRITER }} -f net7.0 -c Release --verbosity normal -o ./publish.benchmarks/
run: dotnet publish ${{env.PROJECT_BENCH }} -f net6.0 -c Release --verbosity normal -o ./publish.benchmarks/

- name: Run 🏋️‍♂️
if: github.event_name == 'pull_request'
run: dotnet ./publish.benchmarks/Writer.Benchmark.dll -f "Writer.Benchmark.*"
run: dotnet ./publish.benchmarks/Spinner.Benchmark.dll -f "Spinner.Benchmark.*"

- name: Upload Results 📂
if: github.event_name == 'pull_request'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup Node 🔧
uses: actions/setup-node@v1
with:
node-version: "15.x"
node-version: "16.x"
cache: "npm"
cache-dependency-path: ./docs/package-lock.json
path: $DOC_FOLDER
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ jobs:
with:
dotnet-version: ${{ matrix.dotnet-version }}

- name: Setup Stryker 📦
- name: Setup Stryker 🔧
run: dotnet tool install -g dotnet-stryker

- name: Install dotnet-format tool 🔧
run: dotnet tool install -g dotnet-format

- name: Clean Dependencies 📦
run: dotnet clean ${{env.PROJECT_SLN }}

Expand All @@ -55,6 +58,9 @@ jobs:
- name: Build ⚙️
run: dotnet build ${{env.PROJECT_SLN }} -c Release -p:Version=$BUILD_VERSION --no-restore

- name: Format ♻️
run: dotnet format ${{env.APP }} -v diag --severity error --no-restore

- name: Test 🧪
run: dotnet test ${{env.PROJECT_SLN }} --configuration Release --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover

Expand Down
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,14 @@ node_modules

BenchmarkDotNet.Artifacts
BenchmarkDotNet.Artifacts/*
*/BenchmarkDotNet.Artifacts/*
*/BenchmarkDotNet.Artifacts/*

.sarif
.sarif/*
*/.sarif
*/.sarif/*

infer-out/*
*/infer-out

diagram.html
74 changes: 22 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,25 @@
<div align="center">
<img src="/assets/logo.png?raw=true">
<img src="./assets/logo.png?raw=true">
</div>

#

<a href="https://github.com/Daniel-iel/Spinner/graphs/contributors" alt="Contributors">
<img src="https://img.shields.io/github/contributors/Daniel-iel/Spinner" />
</a>
<a href="https://github.com/Daniel-iel/Spinner/commits/main" alt="Total Commits">
<img src="https://img.shields.io/github/commit-activity/m/Daniel-iel/Spinner/main" />
</a>
<a href="https://github.com/Daniel-iel/Spinner/actions/workflows/ci.yml">
<img src="https://github.com/Daniel-iel/Spinner/actions/workflows/ci.yml/badge.svg" alt="build status">
</a>
<a href="https://github.com/Daniel-iel/Spinner/actions/workflows/ci.yml">
<img src="https://github.com/Daniel-iel/Spinner/actions/workflows/ci-documentation.yml/badge.svg" alt="build status">
</a>
<a href="https://github.com/Daniel-iel/Spinner/blob/main/LICENSE">
<img src="https://img.shields.io/github/license/Daniel-iel/Spinner" alt="License"/>
</a>
<a href="https://www.nuget.org/packages/Spinner">
<img src="https://img.shields.io/nuget/dt/Spinner" alt="Nuget"/>
</a>
<a href="#">
<img alt="views" title="Views" src="https://visitor-badge-reloaded.herokuapp.com/badge?page_id=https://github.com/Daniel-iel/Spinner&logo=github"/>
</a>
<a href="#">
<img alt="Release" title="Release" src="https://img.shields.io/nuget/v/spinner"/>
</a>
<a href="#">
<img alt="Repo Size" title="Repo Size" src="https://img.shields.io/github/repo-size/Daniel-iel/spinner"/>
</a>
<a href="https://www.codefactor.io/repository/github/Daniel-iel/spinner">
<img alt="" title="" src="https://www.codefactor.io/repository/github/Daniel-iel/spinner/badge"/>
</a>
<a href="https://codecov.io/gh/Daniel-iel/Spinner">
<img alt="Coverity Scan Build Status" src="https://codecov.io/gh/Daniel-iel/Spinner/branch/main/graph/badge.svg?token=0DO0Z5CA6N/">
</a>
<a href="https://scan.coverity.com/projects/spinner">
<img alt="Coverity Scan Build Status"
src="https://img.shields.io/coverity/scan/24116.svg"/>
</a>
<a href="">
<img alt="" src="https://api.meercode.io/badge/Daniel-iel/Spinner?type=ci-score&lastDay=31"/>
</a>

<br />

### Introduction
[![Contributors](https://img.shields.io/github/contributors/Daniel-iel/Spinner)](https://www.nuget.org/packages/Spinner/)
[![Activity](https://img.shields.io/github/commit-activity/m/Daniel-iel/Spinner)](https://www.nuget.org/packages/Spinner/)
[![ci](https://github.com/Daniel-iel/Spinner/actions/workflows/ci.yml/badge.svg)](https://github.com/Daniel-iel/Spinner/actions/workflows/ci.yml/badge.svg/)
[![documentation](https://github.com/Daniel-iel/Spinner/actions/workflows/ci-documentation.yml/badge.svg)](https://github.com/Daniel-iel/Spinner/actions/workflows/ci-documentation.yml/badge.svg/)
[![ci](https://github.com/Daniel-iel/Spinner/actions/workflows/ci-benchmark.yml/badge.svg)](https://github.com/Daniel-iel/Spinner/actions/workflows/ci-benchmark.yml/badge.svg/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md)
[![Downloads](https://img.shields.io/nuget/dt/Spinner)](https://www.nuget.org/packages/Spinner/)
[![Visitors](https://visitor-badge-reloaded.herokuapp.com/badge?page_id=https://github.com/Daniel-iel/Spinner&logo=github)
[![Release](https://img.shields.io/nuget/v/spinner)](https://www.nuget.org/packages/Spinner/)
[![Repo Size](https://img.shields.io/github/repo-size/Daniel-iel/spinner)](https://www.nuget.org/packages/Spinner/)
[![Code Factor](https://www.codefactor.io/repository/github/Daniel-iel/spinner/badge)](https://www.codefactor.io/repository/github/Daniel-iel/spinner)
[![coverity](https://img.shields.io/coverity/scan/24116.svg)](https://scan.coverity.com/projects/spinner)
[![Code Factor](https://api.meercode.io/badge/Daniel-iel/Spinner?type=ci-score&lastDay=31)](https://scan.coverity.com/projects/spinner)
[![Snyk](https://img.shields.io/snyk/vulnerabilities/github/Daniel-iel/Spinner)](https://scan.coverity.com/projects/spinner)

## Introduction

Spinner is a simple object mapper, it’s useful to communicate to any system that uses a positional string as communication.

Expand All @@ -71,17 +43,17 @@ dotnet add package Spinner
[ObjectMapper(length: 50)]
public struct Nothing
{
public Nothing(string name, string adress)
public Nothing(string name, string webSite)
{
this.Name = name;
this.Adress = adress;
this.WebSite = webSite;
}

[WriteProperty(length: 20, order: 1, paddingChar: ' ')]
public string Name { get; private set; }

[WriteProperty(length: 30, order: 2, paddingChar: ' ')]
public string Adress { get; private set; }
public string WebSite { get; private set; }
}

var nothing = new Nothing("spinner", "www.spinner.com.br");
Expand All @@ -96,9 +68,7 @@ See Learn: Getting Started for setting up your project [here](https://spinnerfra

## Contributors

<a href="https://github.com/Daniel-iel">
<img src="https://github.com/Daniel-iel.png?size=40" width="40" style="border-radius: 100%" />
</a>
[![Daniel-Profile](https://github.com/Daniel-iel.png?size=40)](https://github.com/Daniel-iel)

## Support

Expand All @@ -110,4 +80,4 @@ Our code and framework are licensed under the MIT license. Please see the licens

# Stats

<img src="https://repobeats.axiom.co/api/embed/c3f5ed375e6e703c23a90745aaee5bca46ebd0fd.svg" alt="Repobeats analytics image" />
[![Repobeats analytics image](https://repobeats.axiom.co/api/embed/c3f5ed375e6e703c23a90745aaee5bca46ebd0fd.svg)]
4 changes: 2 additions & 2 deletions app/Spinner.Test/Attributes/ObjectMapperTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Spinner.Attribute;
using Spinner.Test.Helper;
using Xunit;
using System;
using System.Reflection;
using Xunit;

namespace Spinner.Test.Attributes
{
Expand Down Expand Up @@ -48,4 +48,4 @@ public void Should_ValidateHowManyAttributesExistsInObjectMapperAttributeFile()
Assert.Equal(AttributeTargets.Struct | AttributeTargets.Class, attributeUsage.ValidOn);
}
}
}
}
6 changes: 3 additions & 3 deletions app/Spinner.Test/Attributes/ReadPropertyTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Spinner.Attribute;
using Spinner.Test.Helper;
using Xunit;
using System;
using System.Reflection;
using Xunit;

namespace Spinner.Test.Attributes
{
Expand All @@ -15,7 +15,7 @@ public void Should_ValidateHowManyContructorsExistsInReadPropertyAttributeFile()
ConstructorInfo[] constructors = FileInspect<ReadPropertyAttribute>.GetConstructors();

// Assert
Assert.Single(constructors);
Assert.Equal(2, constructors.Length);
}

[Fact]
Expand Down Expand Up @@ -51,4 +51,4 @@ public void Should_ValidateHowManyAttributesExistsInReadPropertyAttributeFile()
Assert.Equal(AttributeTargets.Property, attributeUsage.ValidOn);
}
}
}
}
4 changes: 2 additions & 2 deletions app/Spinner.Test/Attributes/WritePropertyTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Spinner.Attribute;
using Spinner.Test.Helper;
using Xunit;
using System;
using System.Reflection;
using Xunit;

namespace Spinner.Test.Attributes
{
Expand Down Expand Up @@ -77,4 +77,4 @@ public void Should_ValidateHowManyAttributesExistsInWritePropertyFile()
Assert.Equal(AttributeTargets.Property, attributeUsage.ValidOn);
}
}
}
}
26 changes: 26 additions & 0 deletions app/Spinner.Test/Cache/ParserTypeCacheTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Spinner.Cache;
using Spinner.Parsers;
using Spinner.Test.Helper.Parses;
using Xunit;

namespace Spinner.Test.Cache
{
public class ParserTypeCacheTest
{
[Fact]
public void TryGet_WhenCalled_ShoudReturnParsedTypeFromCache()
{
// Arrange
const string key = "key";
ITypeParse parser = new CacheParser();

ParserTypeCache.Add(key, parser);
// Act
var typeCached = ParserTypeCache.TryGet(key, out var typeInCache);

// Assert
Assert.True(typeCached);
Assert.IsType<CacheParser>(typeInCache);
}
}
}
6 changes: 3 additions & 3 deletions app/Spinner.Test/Extensions/SpanExtensionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using Spinner.Extensions;
using System;
using Xunit;
using Spinner.Extensions;

namespace Spinner.Test.Extensions
{
Expand Down Expand Up @@ -74,4 +74,4 @@ public void ShouldNot_PadRight(string value, string expected, ushort numberOfPad
Assert.Equal(expected, result.ToString());
}
}
}
}
2 changes: 1 addition & 1 deletion app/Spinner.Test/Helper/FileInspect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public static ConstructorInfo[] GetConstructors()
return Type.GetConstructors();
}
}
}
}
12 changes: 12 additions & 0 deletions app/Spinner.Test/Helper/Parses/CacheParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Spinner.Parsers;

namespace Spinner.Test.Helper.Parses
{
internal sealed class CacheParser : ITypeParse
{
public object Parser(object obj)
{
return obj;
}
}
}
14 changes: 14 additions & 0 deletions app/Spinner.Test/Helper/Parses/DecimalParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Spinner.Parsers;
using System.Globalization;

namespace Spinner.Test.Helper.Parses
{
internal sealed class DecimalParser : ITypeParse
{
public object Parser(object obj)
{
string value = obj.ToString().Insert(2, ".");
return decimal.Parse(value, new CultureInfo("en-US"));
}
}
}
32 changes: 32 additions & 0 deletions app/Spinner.Test/Models/NothingDecimal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Spinner.Attribute;
using System;

namespace Spinner.Test.Models
{
[ObjectMapper(length: 4)]
internal struct NothingDecimal : IEquatable<NothingDecimal>
{
public NothingDecimal(string value)
{
Value = value;
}

[WriteProperty(length: 4, order: 0, paddingChar: ' ')]
public string Value { get; set; }

public bool Equals(NothingDecimal other)
{
return Value == other.Value;
}

public override int GetHashCode()
{
return HashCode.Combine(Value);
}

public override bool Equals(object obj)
{
return obj is NothingDecimal nothingDecimal && Equals(nothingDecimal);
}
}
}
28 changes: 28 additions & 0 deletions app/Spinner.Test/Models/NothingDecimalReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Spinner.Attribute;
using Spinner.Test.Helper.Parses;
using System;

namespace Spinner.Test.Models
{
[ObjectMapper(length: 4)]
internal sealed class NothingDecimalReader : IEquatable<NothingDecimalReader>
{
[ReadProperty(start: 0, length: 4, type: typeof(DecimalParser))]
public decimal Value { get; set; }

public bool Equals(NothingDecimalReader other)
{
return Value == other.Value;
}

public override int GetHashCode()
{
return HashCode.Combine(Value);
}

public override bool Equals(object obj)
{
return obj is NothingDecimalReader nothingDecimalReader && Equals(nothingDecimalReader);
}
}
}
Loading

0 comments on commit 45f741f

Please sign in to comment.