Coder Social home page Coder Social logo

Comments (9)

Haukinger avatar Haukinger commented on July 18, 2024

Figured it out: internals have to be visible to SimpleConfig.Dynamic.InterfaceImplementations

But the dynamic creation of implementations does not seem to apply to properties within the interface, i.e. those remain null, even if decorated with CustomEnumerable.

from simple-config.

Haukinger avatar Haukinger commented on July 18, 2024

Sorted this one out, too: GetCustomAttributes(true) does not returned attributes declared in or on implemented interfaces, so PropertyHelper.GetMappingStrategies needs to manually look through all implemented interfaces:

To do that, I added .Concat( @this.DeclaringType.GetInterfaces().SelectMany( x => x.GetProperties().Where( y => y.Name == @this.Name ).SelectMany( y => y.GetMappingStrategies() ) ) ) between Where and ToArray at the beginning of the method.

from simple-config.

spadger avatar spadger commented on July 18, 2024

Good to see you got around this. TBH though, I'd be inclined to use POCOs instead of interfaces - the interface stuff was really a bad excuse to play with codegen.

POCOs are easier to reason with and control IMHO, and easier to test without mocking config.

from simple-config.

Haukinger avatar Haukinger commented on July 18, 2024

I prefer the interfaces, because they work without setters on the properties. With pocos, technically anybody can modify the settings.

from simple-config.

spadger avatar spadger commented on July 18, 2024

I believe your Poco could be

public class SomeConfig
{
    public string SomeValue { get; private set }
}

And obviously it's a valid defensive position to make, but conversely (it took me a number of years to reach this point), do you rate your colleagues so low that they'd be modifying a config instance after initialisation? Possible, but not probable

from simple-config.

Haukinger avatar Haukinger commented on July 18, 2024

It works with a private setter, just not for read-only properties. You might add the line to GetMappingStrategies just for completeness' sake, in case someone tries an interface property in an interface.

As for the colleagues... they'll do anything you can or cannot imaging, so I prefer to be safe than sorry :-D

from simple-config.

spadger avatar spadger commented on July 18, 2024

from simple-config.

spadger avatar spadger commented on July 18, 2024

Hi,

I no longer have access to a windows machine, and getting this stuff up and running in netstandard so I can develop and test it is not trivial (e.g. TypeGenerator.cs(132, 51): [CS7069] Reference to type 'Assembly' claims it is defined in 'System.Runtime', but it could not be found after adding back the missing runtime and code-generation packages)

I'm not sure I have the energy to fix this on a mac

from simple-config.

spadger avatar spadger commented on July 18, 2024

For completeness, I took a look at this code with Mono, and I'm hesitant to add your addition. The current code is for a specific property instance that happens to have a name. Your code will find mapping strategies for any property that has the same name, but a class can have multiple properties with the same name if they're an explicit interface implementation, so the mapping strategies could end up being a superset of the legal strategies

from simple-config.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.