dynalon / jsonconfig Goto Github PK
View Code? Open in Web Editor NEWsimple configuration library using JSON and C# 4.0 dynamic feature
License: MIT License
simple configuration library using JSON and C# 4.0 dynamic feature
License: MIT License
Saving change file two times, causes System.IO.IOexception - as file is locked by saving process i guess. Use File.ReadAllLines instead of File.ReadAllText to prevent locking the file during read.
Would it be possible to add support to allow the settings to be loaded from alternative locations?
It's so surprising!
I try to read a array from a json format file. The file has two elements in Repository
array, but after deserializing, I get a 3-element array.
This is the json file
{"Repository":["http://mirrors.neusoft.edu.cn/android/repository","https://dl.google.com/android/repository"],"SeletedRepository":0}
This is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace MeloduetAndroidSDKManagerWinform.Helper
{
public class ApplicationSetting
{
public List<string> Repository { get; } = new List<string>() { "http://mirrors.neusoft.edu.cn/android/repository" };
public int SeletedRepository { get; set; } = 0;
public static ApplicationSetting Load(string path)
{
if (System.IO.File.Exists(path))
{
ApplicationSetting obj = null;
string json = System.IO.File.ReadAllText(path);
obj = JsonConvert.DeserializeObject<ApplicationSetting>(json);
return obj;
}
else
{
var obj = new ApplicationSetting();
obj.Save(path);
return obj;
}
}
public void Save(string path)
{
System.IO.File.WriteAllText(path, JsonConvert.SerializeObject(this),Encoding.UTF8);
}
}
}
Good day,
We are busy migrating to .net core and cannot get this library to work.
Please can you update nuget with the dll build for .net standard
Is there a nuget package available for jsonconfig?
It would be nice if you enabled nuget package restore for the solution, this way we can very easily retrieve any dependencies after checking out the repository. As it is, we have to manually find and retrieve any dependencies manually.
Hi there, great library.
I've run into a number of problems trying to compile the solution and it is largely due to JsonFX. I was able to get it running on some sites, but others would crash unexpectedly.
I modified your code to use http://www.nuget.org/packages/newtonsoft.json/ which is the most widely and popular used json library in .NET. Now it works without any issues at all.
Just thought you should know, I can provide details on the code I changed if you'd like.
Avoid using Console.Write or Console.WriteLine as it can affect console application output. Use Debug.Write or Debug.WriteLine instead.
JsonConfig/JsonConfig/ConfigObjects.cs
Line 32 in 5127e28
Would it be possible to access the keys case insensitive, if the initialitazion of the dictionary were like this:
internal Dictionary<string, object> members = new Dictionary<string, object> (StringComparer.InvariantCultureIgnoreCase);
As I've added a few other commits, I can't PR but here's a commit that enables dictionary enumerator support.
Can you merge that in please?
Currently the library provides read-only access to JSON configuration-files.
I would be lucky to see the ability to save single ConfigObjects as JSON-files again to persist configuration changes made by the application.
You had a TODO in the Config constructor for checking IDE build dir and adjusting the execution path accordingly to make in windows-aware. Here is a patch for that.
This is shown when running the ManualDefaultAndUserConfig
unit test together with CurrentScopeTest
, before bfb1f4d.
When executed separately both will pass, but when ran together the line:
dynamic c = Config.GetCurrentScope ();
will initialize the global config object, causing it to be an outdated merge of the user/default configs after they're set in the set up of ManualDefaultAndUserConfig
:
Config.SetUserConfig (parsed.Fruits);
Config.SetDefaultConfig (parsed.Vegetables);
//...
dynamic scope = Config.Global; //no longer up-to-date
I am not seeing how to create a Config object with an explicit path?
Sorry if this is an elementary question.
There is no Config constructor that accepts a path.
I see this project, that may be a response to this need.
https://github.com/splitice/JSONConfigHelpers.Net
Thoughts?
I am not sure where exactly to put my default.conf file? I have put it in the root directory but when I debug there are 0 keys on my Config.Default instance?
it would be cool if we can access the formatter and if possible change it.
I am looking to support camel casing in the config files, but access these properties via Pascal naming
#config
{
"foo":"bar"
}
Console.Write(config.Foo); //prints bar
If you look at line 98 in the current version of Merger.cs, it's using the same value twice when determining types
var value1 = kvp1.Value;
var value2 = kvp2.Value;
var type1 = value1.GetType ();
var type2 = value1.GetType ();
Doesn't seem right to me...
Hello
thanks for developing this. I was wondering if there is a way through which i can save the config file in a shared folder and have two .net based desktop applications read and write it?
Looking forward to the response. Thanks
I have a db connection string in my config file:
Connection: "localhost\sqlexpress"
but when I debug. in code the variable is " localhostsqlexpress" (no "" )
and if put two "" then both of them appear in the variable?
is there a special way I need to read the string?
Hey everyone,
I just ran into the problem, that you cannot merge the default value null with anothe value. They key simply will not show up in the result. Here is a quick example in Pseudocode:
var actual = @"{"override":"1png","onlyActual":1}"
var default = @"{"override":null,"onlyDefault":2}"
JsonConfig.Merger.Merge(JsonConfig.Config.ParseJson(actual),JsonConfig.Config.ParseJson(default));
// => "{"onlyActual":1,"onlyDefault:2}"
A quick research in the code lead to line 67 in Merger.cs:
// skip already copied over keys
if (!dict2.Keys.Contains(kvp1.Key) || dict2[kvp1.Key] == null)
continue;
Could this be the problem?
Cheers! Marvin
I'm having an issue where when I try to access a config element, say
JsonConfig.Config.MergedConfig.ServiceName
, which is a string in the default.conf file. I'm getting a null value. BUT if I pause execution and then add
JsonConfig.Config.MergedConfig
to the watch variables, and I expand it, it will evaluate properly.
Any thoughts?
BTW great job on this - I was about to write one, but now I dont need to!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.