Coder Social home page Coder Social logo

nerdle.autoconfig's Issues

Choking on property of type Type

Wanted to use the property of type Type ...
Interface:
public interface IMyConfiguration
{
Type DeclaredType { get; }
}
Config
...

But got an exception
Tried to map element ... using 'RecursingMapper', and barfed. See inner exception for details.

Workaround:
declare property as string
in the code use:
var mytype = Type.GetType(myconfig.DeclaredType)

Unable to ignore namespace and attributes with namespace prefixes on the config section.

Hi there,
Thanks for this library - I've rolled my own configuration classes before and this is much less boilerplate code to write - I much prefer your library.

However, I would like to use an schema XSD file alongside my configuration section so that I can benefit from intellisense in Visual Studio and document the configuration settings.

To do this I added an XSD describing my custom config section and decorated the my config section that will be processed by AutoConfig with an xsi:noNamespaceSchemaLocation attribute and xmlns:xsi - something like this:

However the namespace declaration attributes are picked up in the automatic mapping so I errors because AutoConfig cannot map these attributes to my config class.

I cloned the repo and debugged and found that MappingFactory.CreateMapping() includes namespace declarations - so I ingored the xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" declaration by adding a where clause to ingnore it :
var attributeList = sectionElement.Attributes().Where(x => !x.IsNamespaceDeclaration).ToList();

Of course, it still tries to match the xsi:noNamespaceSchemaLocation attribute. To get around this I added a NoNamespaceSchemaLocation to my config interface and defined it as optional with AutoConfig.WhenMapping<> but the code in MappingFactory.TakeAttribute is not namespace aware.

So I changed MappingFactory.TakeAttribute() to use LocalName instead:
static XAttribute TakeAttribute(ICollection attributeList, string name)
{
return TakeSingleMatching(attributeList, attr => attr.Name.LocalName == name,
count => string.Format("Found {0} attributes with name '{1}' but only expected to find one.", count, name));
}

This works for my purposes, but you may wish to add optional logic to ignore attributes for specific namespaces and namespace prefixes as a better solution. If you could configure via AutoConfig.WhenMapping() to ignore the a given namespace that would be perfect.

Something like:
AutoConfig.WhenMapping(mapping =>
{
mapping.IgnoreNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")
});

Then you could change element/attribute mapping to see if the namespace is in the ignore list and ignore any that are not part of the actual config for the project.

Thanks,
Darryl

.NET Standard

Hello --

I see a commit for updating the assembly to support .NET Standard 2.0. Would you mind publishing a new version of the Nuget package that supports this? Thank you so much for your work on this project!

Joe

How do I add Section Group ?

@edpollitt, I would like to add Section Group like below. How do i achieve this? Below is my sample xml and C# code

var mappings = AutoConfig.Map<IBaseConfigurations>();

public interface IBaseConfigurations
{
    IApiSettingsConfiguration ApiSettings { get; set; }
    ITestConfiguration TestConfiguration { get; set; }
}
<baseConfigurations>
	<apiSettingsConfiguration>
		<baseUrl>http://localhost:62954</baseUrl>
		<endPoint></endPoint>
		<pollingIntervalInSeconds>10</pollingIntervalInSeconds>
	</apiSettingsConfiguration>
	<testConfiguration>
		<name>Testing</name>
	</testConfiguration>
</baseConfigurations>

Sign assembly at nuget.org

Could you please sign the assemblies published at nuget.org so that they become strong named?

Thanks in advance!

Read config file in another location

Hi,
Could you please add an ability to read configuration from not default configuration file?

For instance, it could look like this:
AutoConfig.SetPathToConfigFile(string configFile)
or like this
AutoConfig.Map(string sectionName = null, string fileName = null)

Thanks!

how to map KeyedCollection<Tkey,TItem>

when map to a KeyedCollection<Tkey,TItem> will get a exception, but List was well.
when i use a class(with get and set property) and deserialize from xml, the KeyedCollection<Tkey,TItem> will run well

$exception	{"Tried to map element 'themeConfig' to property 'ThemeConfig' of 'AutoConfig.DynamicTypes.Implementation_Of_ConsoleTest_IWebsiteConfiguration' using 'RecursingMapper', and barfed. See inner exception for details."}	Nerdle.AutoConfig.Exceptions.AutoConfigMappingException
<section name="websiteConfiguration" type="Nerdle.AutoConfig.Section, Nerdle.AutoConfig" />
....
  <websiteConfiguration>
    <siteUrl><![CDATA[http://my.domian.com/]]></siteUrl>
    <themeConfig default="Red">
      <themes>
        <theme name="Blue"  />
        <theme name="Red" />
        <theme name="Black" />
      </themes>
    </themeConfig>
  </websiteConfiguration>
    public interface IWebsiteConfiguration
    {
        string SiteUrl { get; }
		
        IThemeConfig ThemeConfig { get; }
    }

    public interface IThemeConfig
    {
        string Default { get; }

        ThemeCollection Themes { get; }

    }
    public interface ITheme
    {
        string Name { get;}
    }
	
    public class ThemeCollection : KeyedCollection<string, ITheme>
    {
        protected override string GetKeyForItem(ITheme item)
        {
            return item.Name;
        }
    }

Update/Save configuration values

Configuration manager use caching to save configuration values from config file and use it next time. Is it possible to update config values by any concrete class instance and use those updated values if config loaded in memory next time (app restart)?

A custom IMapper cannot be specified when mapping from an attribute

Hi! How I can use mapper for nested fields? E.g.:
interface IA {
IB property1;
}

interface IB {
someEnum property2;
}

If I am trying like that

AutoConfig.WhenMapping<IA>(
mapping =>
                {
                    mapping.Map(x => x.property1.property2).Using<Property2Mapper>();
                });

I'll get nothing.

But if I am trying as following

AutoConfig.WhenMapping<IB>(
mapping =>
                {
                    mapping.Map(x => x.property2).Using<Property2Mapper>();
                });

I'll get exception ....... A custom IMapper cannot be specified when mapping from an attribute.

Why ?

Ability to use AutoConfig.Map on things that aren't on disk

We'd like to be able to compose this library's awesome config deserialization code with things that aren't on disk (our existing config library supports loading config from a file system abstraction library for in-memory testing and long-path support).

Your public API currently requires that we write the content out to disk so it can be loaded in by the library (your public API optionally takes a configFilePath). Would you consider adding an overload to AutoConfig.Map that takes a Stream or a TextReader, or alternatively making the internal method that takes an XElement public?

Thanks for the good work on this library!

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.