d-edge / Cardidy

A .net library to identify credit card number and cvv
MIT License
33 stars 12 forks source link

Would it be nice to use code generator to parse a json with all card's data and add a generation step? #50

Open aloisdg opened 2 years ago

aloisdg commented 2 years ago

.NET 5.0 adds Source Code Generator to the C# world: https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/

The goal would be to move all the data into a json data file and to generate all the classes, the enum, etc. with source generator.

hey24sheep commented 2 years ago

I think that's a great idea. I created a scraper for the data here, it's github pages hosted.

I created this cuz I want to add all other cards as well easily. If it helps you with source-gen. I am thinking of doing a simple placeholder replace like (won't source gen will be overkill?)

internal record {{provider}} : {{base)}}
{
    public {{provider}}() : base(CardType.{{provider}}, {{range}}, {{length}}) { }
}

Obviously for base, length and IINrange I will use logic to determine which/how to put data according to current implementation. But, if you could use source-gens I will be curious to see how they work.

aloisdg commented 2 years ago

Source gen may be a bit overkill, but is is nice way to experiment with it and it will be more contributor friendly.

I create a bot on Cardizer to create issues on update of the page. We could go further but I think it was a nice first step.

Your tool could be very useful to get from html to json. We wont write the C# directly though thanks to source code generator. I think I will handle the source gen issue. At least, I will start a POC in a branch.

hey24sheep commented 2 years ago

I changed my code to Wiki API now (I started getting CORS error otherwise) so now it is accessible.

I usually use Reflection to generate C# or transpile C# to other stuff like we generate .dart files from our C# models. So, source-gen will be a pretty intresting thing for me.

aloisdg commented 2 years ago

Here we are talking about compile time generation not runtime generation like reflection. I would like to transpile C# to js too btw (see #36).

hey24sheep commented 2 years ago

I know, compile time generation was possible too with Rosyln Compiler but it was a lot of work, let's see how good is source-code generators.

I did checkout C# to JS, but I H5 doesn't have any documentation. I will give it a try later this week, hopefully will be able to work it up.

aloisdg commented 2 years ago

Yeah. I plan to try it myself later on. If you want to try out before, go for it :)

C# to js is not quite needed. It is a nice to have :)

hey24sheep commented 2 years ago

It's okay, you can go for it, I don't want to hang you guys up.

H5 itself is a good to know library. I might try that up.

I'm thinking of doing a Flutter wrapper of Cardidy though (as I work a lot on Flutter) not sure if dart-wise feasible because Flutter is bad in serialisation of data, but we'll see 🙈