Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate extension methods #21

Open
mrverdant13 opened this issue Jun 28, 2021 · 2 comments
Open

feat: generate extension methods #21

mrverdant13 opened this issue Jun 28, 2021 · 2 comments

Comments

@mrverdant13
Copy link

mrverdant13 commented Jun 28, 2021

Description

Given the following classes:

class Dog {
  final String breed;
  final int age;
  final String name;
  Dog(this.breed, this.age, this.name);
}

class DogModel {
  final String breed;
  final int age;
  final String name;
  DogModel(this.breed, this.age, this.name);
}

And given the following mapper interface:

// dogmapper.dart

part 'dogmapper.mapper.g.dart';

@Mapper()
abstract class DogMapper {
  Dog asEntity(DogModel model);
}

Instead of generating a mapper class, it would be great to generate mapper extension methods as follows:

// dogmapper.mapper.g.dart

extension ConvertibleDogModel on DogModel {
  Dog get asEntity => Dog(breed, age, name);
}
@smotastic
Copy link
Owner

smotastic commented Jun 28, 2021

Hey @mrverdant13
I like the idea, I'm thinking of maybe making this configurable.
So that you would be able to write something like

@Mapper(extension: true)
...

And instead of implementing the mapper class, it would generate extension methods like you suggested.

I don't know how much time I'll have in the weeks, but I'll see what I can do.
Or if you feel like it, feel free to open a PR

@mrverdant13
Copy link
Author

Definitely gonna check this out and try to post a PR.

BTW, thanks for the package! I was about to create one with just similar capabilities! 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants