question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot control TypeProperties even with a custom binder

See original GitHub issue

I was trying to figure out why AutoBogus was doing nothing with the RepeatedField<T> type (a protobuf type). I created my own binder to try and take control of the situation, but it never even called GetMembers.

Digging into the code a bit, I found that this line does not pass the provided binder onto the base class. Therefore, the base class uses the default binder to populate TypeProperties. Hence, I never get a chance to even tell it that I want to populate my RepeatedField<T> instances.

By changing the above line to this:

: base(locale ?? AutoFaker.DefaultLocale, binder)

I got around my problem. However, when I went to PR this, I noticed a couple of tests broke, and I was then well and truly out of my depth.

Any thoughts on this? Ultimately, I just want my RepeatedField<T> instances to populate like any other list would.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nickdodd79commented, Mar 15, 2019

Hi @kentcb

I finally found some time to look into addressing your use case. I have made some code changes that allow you to register an override for a type generator (including the built in generators).

In the case of your example above you would implement the following:

public class Foo
{
    private readonly RepeatedField<string> bar = new RepeatedField<string>();
    public RepeatedField<string> Bar => bar;
}

AutoFaker.AddGeneratorOverride<Foo>(context =>
{
    var foo = new Foo();
    foo.Bar.Add("VALUE");
    return foo;
});

That should provide an entry point for customizing the generation of a given type. Does that work for you? If so, I will publish a new version to NuGet.

Nick.

0reactions
nickdodd79commented, Apr 29, 2019

Hey @kentcb

If you are ever interested in using AutoBogus again, I have just released v2.3 which includes the ability to define generator overrides. An example of how to applies these to generics can be found in the Playground project.

I’ll close this issue now.

Nick.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make a custom ModelBinder automatically apply ...
I would like this MeasurementModelBinder to apply to all properties of this type in every model. So I'm trying to do that. Here's...
Read more >
Intergraph SmartPlant Instrumentation Help (2016 SP1)
Assign a spec to the binder package, or add a General Note. Cannot repaginate before printing. A problem exists with the specification, the...
Read more >
Custom Model Binding in ASP.NET Core
Model binding allows controller actions to work directly with model types (passed in as method arguments), rather than HTTP requests. Mapping ...
Read more >
A Custom Model Binder for Passing Complex Objects ...
Custom model binder for passing query strings as nested objects or collections to Web API GET or POST methods, also updated for ASP.NET...
Read more >
I Make Custom Binder Covers. Here's a preview of the one ...
This includes a checklist of everything I've finished, have in progress, and plan to work on, as well as previews, instructions to print,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found