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

[Question] Usage of objectMapping.SetOrderBy() #51

Closed
TMaddox opened this issue Jan 4, 2020 · 2 comments
Closed

[Question] Usage of objectMapping.SetOrderBy() #51

TMaddox opened this issue Jan 4, 2020 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@TMaddox
Copy link

TMaddox commented Jan 4, 2020

First, thanks for implementing this!

I am trying to use the objectMapping.SetOrderBy() Method to get everything sorted alphabetically (including the discriminator), but unfortunately I can't apply the solution you provided right here #46 as I am using it this way:

on inititalization:

options.Registry.ObjectMappingConventionRegistry.RegisterProvider(new DsonObjectMappingConventionProvider(mode));

with:

public class DsonObjectMappingConventionProvider : IObjectMappingConventionProvider
    {
        private readonly IObjectMappingConvention _objectMappingConvention;

        public DsonObjectMappingConventionProvider(OutputMode mode)
        {
            _objectMappingConvention = new DsonObjectMappingConvention(mode);
        }

        public IObjectMappingConvention GetConvention(Type type)
        {
            return _objectMappingConvention;
        }
    }

and:

public class DsonObjectMappingConvention : IObjectMappingConvention
    {
       ....
       public void Apply<T>(SerializationRegistry registry, ObjectMapping<T> objectMapping) where T : class
       {
             ....
             objectMapping.SetOrderBy(m => m.MemberName);
       }
    }

I think the problem is that at the time where Apply(...) is executed the MemberNames are all null and cannot be sorted? What am I doing wrong?

@mcatanzariti mcatanzariti self-assigned this Jan 4, 2020
@mcatanzariti mcatanzariti added the bug Something isn't working label Jan 4, 2020
@mcatanzariti
Copy link
Member

I reproduced the problem as a bug

@mcatanzariti
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants