Comments (9)
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.
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.
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.
I prefer the interfaces, because they work without setters on the properties. With pocos, technically anybody can modify the settings.
from simple-config.
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.
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.
from simple-config.
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.
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)
- Problem with Travis HOT 1
- Import dictionary HOT 2
- Default values HOT 1
- I get an error during compilation of my solution: Assembly generation failed -- Referenced assembly 'SimpleConfigSections' does not have a strong name HOT 2
- How to use Simple-Config HOT 2
- Complex Types? HOT 1
- Support for section groups? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simple-config.