diff --git a/Cfg.Net.40/Properties/AssemblyInfo.cs b/Cfg.Net.40/Properties/AssemblyInfo.cs index d046246..0be7607 100644 --- a/Cfg.Net.40/Properties/AssemblyInfo.cs +++ b/Cfg.Net.40/Properties/AssemblyInfo.cs @@ -1,4 +1,21 @@ -using System.Reflection; +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -32,5 +49,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.9.3.0")] -[assembly: AssemblyFileVersion("0.9.3.0")] +[assembly: AssemblyVersion("0.9.4.0")] +[assembly: AssemblyFileVersion("0.9.4.0")] diff --git a/Cfg.Net.45/Properties/AssemblyInfo.cs b/Cfg.Net.45/Properties/AssemblyInfo.cs index 7eb871b..c7f72dd 100644 --- a/Cfg.Net.45/Properties/AssemblyInfo.cs +++ b/Cfg.Net.45/Properties/AssemblyInfo.cs @@ -1,4 +1,21 @@ -using System.Reflection; +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -32,5 +49,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.9.3.0")] -[assembly: AssemblyFileVersion("0.9.3.0")] +[assembly: AssemblyVersion("0.9.4.0")] +[assembly: AssemblyFileVersion("0.9.4.0")] diff --git a/Cfg.Net.452/Properties/AssemblyInfo.cs b/Cfg.Net.452/Properties/AssemblyInfo.cs index c2a7711..7dc5d03 100644 --- a/Cfg.Net.452/Properties/AssemblyInfo.cs +++ b/Cfg.Net.452/Properties/AssemblyInfo.cs @@ -1,4 +1,21 @@ -using System.Reflection; +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -32,5 +49,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.9.3.0")] -[assembly: AssemblyFileVersion("0.9.3.0")] +[assembly: AssemblyVersion("0.9.4.0")] +[assembly: AssemblyFileVersion("0.9.4.0")] diff --git a/Cfg.Net.Environment/EnvironmentModifier.cs b/Cfg.Net.Environment/EnvironmentModifier.cs index ddbb192..815569a 100644 --- a/Cfg.Net.Environment/EnvironmentModifier.cs +++ b/Cfg.Net.Environment/EnvironmentModifier.cs @@ -1,3 +1,20 @@ +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion using System; using System.Collections.Generic; using System.Linq; diff --git a/Cfg.Net.Environment/IPlaceHolderReplacer.cs b/Cfg.Net.Environment/IPlaceHolderReplacer.cs index dca9751..98355f3 100644 --- a/Cfg.Net.Environment/IPlaceHolderReplacer.cs +++ b/Cfg.Net.Environment/IPlaceHolderReplacer.cs @@ -1,3 +1,20 @@ +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion using System.Collections.Generic; using Cfg.Net.Contracts; diff --git a/Cfg.Net.Environment/PlaceHolderReplacer.cs b/Cfg.Net.Environment/PlaceHolderReplacer.cs index 50b67d8..9980744 100644 --- a/Cfg.Net.Environment/PlaceHolderReplacer.cs +++ b/Cfg.Net.Environment/PlaceHolderReplacer.cs @@ -1,4 +1,21 @@ -using System.Collections.Generic; +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion +using System.Collections.Generic; using System.Text; using Cfg.Net.Contracts; diff --git a/Cfg.Net.Environment/Properties/AssemblyInfo.cs b/Cfg.Net.Environment/Properties/AssemblyInfo.cs index 413e2f7..17e3b35 100644 --- a/Cfg.Net.Environment/Properties/AssemblyInfo.cs +++ b/Cfg.Net.Environment/Properties/AssemblyInfo.cs @@ -1,4 +1,21 @@ -using System.Resources; +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion +using System.Resources; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/Cfg.Net.Parsers.Json.Net/JsonNetNode.cs b/Cfg.Net.Parsers.Json.Net/JsonNetNode.cs index ee812a8..9340901 100644 --- a/Cfg.Net.Parsers.Json.Net/JsonNetNode.cs +++ b/Cfg.Net.Parsers.Json.Net/JsonNetNode.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Parsers.Json.Net/JsonNetParser.cs b/Cfg.Net.Parsers.Json.Net/JsonNetParser.cs index edc4fb5..6a47193 100644 --- a/Cfg.Net.Parsers.Json.Net/JsonNetParser.cs +++ b/Cfg.Net.Parsers.Json.Net/JsonNetParser.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Parsers.Json.Net/JsonNetSerializer.cs b/Cfg.Net.Parsers.Json.Net/JsonNetSerializer.cs index 160167d..88ce874 100644 --- a/Cfg.Net.Parsers.Json.Net/JsonNetSerializer.cs +++ b/Cfg.Net.Parsers.Json.Net/JsonNetSerializer.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Parsers.Json.Net/Properties/AssemblyInfo.cs b/Cfg.Net.Parsers.Json.Net/Properties/AssemblyInfo.cs index 9337352..af3086e 100644 --- a/Cfg.Net.Parsers.Json.Net/Properties/AssemblyInfo.cs +++ b/Cfg.Net.Parsers.Json.Net/Properties/AssemblyInfo.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Parsers.Xml.Linq/Properties/AssemblyInfo.cs b/Cfg.Net.Parsers.Xml.Linq/Properties/AssemblyInfo.cs index 34f4671..8615711 100644 --- a/Cfg.Net.Parsers.Xml.Linq/Properties/AssemblyInfo.cs +++ b/Cfg.Net.Parsers.Xml.Linq/Properties/AssemblyInfo.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Parsers.Xml.Linq/XDocumentNode.cs b/Cfg.Net.Parsers.Xml.Linq/XDocumentNode.cs index 2e71611..7425571 100644 --- a/Cfg.Net.Parsers.Xml.Linq/XDocumentNode.cs +++ b/Cfg.Net.Parsers.Xml.Linq/XDocumentNode.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Parsers.Xml.Linq/XDocumentParser.cs b/Cfg.Net.Parsers.Xml.Linq/XDocumentParser.cs index f5876bc..cc7e9b4 100644 --- a/Cfg.Net.Parsers.Xml.Linq/XDocumentParser.cs +++ b/Cfg.Net.Parsers.Xml.Linq/XDocumentParser.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Parsers.YamlDotNet/Properties/AssemblyInfo.cs b/Cfg.Net.Parsers.YamlDotNet/Properties/AssemblyInfo.cs index 8731464..08aac12 100644 --- a/Cfg.Net.Parsers.YamlDotNet/Properties/AssemblyInfo.cs +++ b/Cfg.Net.Parsers.YamlDotNet/Properties/AssemblyInfo.cs @@ -1,4 +1,21 @@ -using System.Reflection; +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/Cfg.Net.Parsers.YamlDotNet/YamlDotNetNode.cs b/Cfg.Net.Parsers.YamlDotNet/YamlDotNetNode.cs index 0fc45b0..bf539f3 100644 --- a/Cfg.Net.Parsers.YamlDotNet/YamlDotNetNode.cs +++ b/Cfg.Net.Parsers.YamlDotNet/YamlDotNetNode.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Parsers.YamlDotNet/YamlDotNetParser.cs b/Cfg.Net.Parsers.YamlDotNet/YamlDotNetParser.cs index 1ec0e77..9ef6fec 100644 --- a/Cfg.Net.Parsers.YamlDotNet/YamlDotNetParser.cs +++ b/Cfg.Net.Parsers.YamlDotNet/YamlDotNetParser.cs @@ -1,4 +1,21 @@ -using System.Collections.Generic; +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion +using System.Collections.Generic; using System.IO; using Cfg.Net.Contracts; diff --git a/Cfg.Net.Parsers.YamlDotNet/YamlDotNetSerializer.cs b/Cfg.Net.Parsers.YamlDotNet/YamlDotNetSerializer.cs index 7e7614f..b29237b 100644 --- a/Cfg.Net.Parsers.YamlDotNet/YamlDotNetSerializer.cs +++ b/Cfg.Net.Parsers.YamlDotNet/YamlDotNetSerializer.cs @@ -1,3 +1,20 @@ +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion using System.IO; using Cfg.Net.Contracts; using YamlDotNet.Serialization; diff --git a/Cfg.Net.Reader/DefaultReader.cs b/Cfg.Net.Reader/DefaultReader.cs index a8b3002..8782573 100644 --- a/Cfg.Net.Reader/DefaultReader.cs +++ b/Cfg.Net.Reader/DefaultReader.cs @@ -1,20 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion - using System; using System.Collections.Generic; using Cfg.Net.Contracts; diff --git a/Cfg.Net.Reader/FileReader.cs b/Cfg.Net.Reader/FileReader.cs index 981679e..b9e5d2c 100644 --- a/Cfg.Net.Reader/FileReader.cs +++ b/Cfg.Net.Reader/FileReader.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Reader/HttpUtility.cs b/Cfg.Net.Reader/HttpUtility.cs index 169a2c4..94d56a9 100644 --- a/Cfg.Net.Reader/HttpUtility.cs +++ b/Cfg.Net.Reader/HttpUtility.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Reader/Properties/AssemblyInfo.cs b/Cfg.Net.Reader/Properties/AssemblyInfo.cs index 2789668..3dc8a13 100644 --- a/Cfg.Net.Reader/Properties/AssemblyInfo.cs +++ b/Cfg.Net.Reader/Properties/AssemblyInfo.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Reader/ReTryingReader.cs b/Cfg.Net.Reader/ReTryingReader.cs index 6f19a95..f4407a8 100644 --- a/Cfg.Net.Reader/ReTryingReader.cs +++ b/Cfg.Net.Reader/ReTryingReader.cs @@ -1,20 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion - using System; using System.Collections.Generic; using Cfg.Net.Contracts; diff --git a/Cfg.Net.Reader/WebReader.cs b/Cfg.Net.Reader/WebReader.cs index eba22ff..d2af225 100644 --- a/Cfg.Net.Reader/WebReader.cs +++ b/Cfg.Net.Reader/WebReader.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Cfg.Net.Shared.projitems b/Cfg.Net.Shared/Cfg.Net.Shared.projitems index f7f994d..15d7d28 100644 --- a/Cfg.Net.Shared/Cfg.Net.Shared.projitems +++ b/Cfg.Net.Shared/Cfg.Net.Shared.projitems @@ -11,7 +11,6 @@ - @@ -30,6 +29,7 @@ + @@ -40,6 +40,7 @@ + diff --git a/Cfg.Net.Shared/CfgAttribute.cs b/Cfg.Net.Shared/CfgAttribute.cs index 1ded98c..390e74c 100644 --- a/Cfg.Net.Shared/CfgAttribute.cs +++ b/Cfg.Net.Shared/CfgAttribute.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/CfgConstants.cs b/Cfg.Net.Shared/CfgConstants.cs index 0732ed2..ba64bcc 100644 --- a/Cfg.Net.Shared/CfgConstants.cs +++ b/Cfg.Net.Shared/CfgConstants.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/CfgEvents.cs b/Cfg.Net.Shared/CfgEvents.cs index 3a1d0de..37c266d 100644 --- a/Cfg.Net.Shared/CfgEvents.cs +++ b/Cfg.Net.Shared/CfgEvents.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,6 +17,7 @@ #endregion using System; using Cfg.Net.Loggers; + namespace Cfg.Net { internal sealed class CfgEvents { @@ -27,66 +29,45 @@ public CfgEvents(DefaultLogger logger) { } public void DuplicateSet(string uniqueAttribute, object value, string nodeName) { - Logger.Error("Duplicate '{0}' value '{1}' in '{2}'.", uniqueAttribute, value, nodeName); + Logger.Error("Duplicate {0} value {1} in {2}.", uniqueAttribute, value, nodeName); } public void InvalidAttribute(string parentName, string nodeName, string attributeName, string validateAttributes) { - Logger.Error("A{3} '{0}' '{1}' element contains an invalid '{2}' attribute. Valid attributes are: {4}.", parentName, nodeName, attributeName, - Suffix(parentName), validateAttributes); + Logger.Error("A{2} {0} contains an invalid {1}. It may only contain: {3}.", CombineName(parentName, nodeName), attributeName, Suffix(parentName), validateAttributes); + } + + private static string CombineName(string parent, string child) { + return string.IsNullOrEmpty(parent) || parent == child ? child : parent + " " + (child == "add" ? "item" : child); } public void InvalidElement(string parentName, string nodeName, string subNodeName) { if (string.IsNullOrEmpty(parentName)) { - Logger.Error("A{2} '{0}' element has an invalid '{1}' element. If you need a{2} '{1}' element, decorate it with the Cfg attribute.", nodeName, subNodeName, Suffix(nodeName)); + Logger.Error("A{2} {0} has an invalid {1}. If you need a{2} {1}, decorate it with the [Cfg].", nodeName, subNodeName, Suffix(nodeName)); } else { - Logger.Error("A{3} '{0}' '{1}' element has an invalid '{2}' element.", parentName, nodeName, subNodeName, Suffix(parentName)); + Logger.Error("A{2} {0} has an invalid {1}.", CombineName(parentName, nodeName), subNodeName, Suffix(parentName)); } } public void MissingAttribute(string parentName, string nodeName, string attributeName) { - Logger.Error("A{3} '{0}' '{1}' element is missing a '{2}' attribute.", parentName, nodeName, attributeName, Suffix(parentName)); - } - - public void MissingElement(string nodeName, string elementName) { - Logger.Error("The {0} element is missing a{2} '{1}' element.", nodeName == string.Empty ? "root" : "'" + nodeName + "'", - elementName, Suffix(elementName)); - } - - public void MissingAddElement(string elementName) { - Logger.Error("A{1} '{0}' element is missing a child element.", elementName, Suffix(elementName)); - } - - public void MissingValidator(string nodeName, string validatorName) { - Logger.Warn("A '{0}' attribute can not find the {1} validator. Please make it's passed in to your Cfg-Net root constructor.", nodeName, validatorName); - } - - public void ValidatorException(string validatorName, Exception ex, object value) { - Logger.Error("The '{0}' validator threw an exception when validating the value '{2}'. {1}", validatorName, ex.Message, value); - } - - public void MissingNestedElement(string parentName, string nodeName, string elementName) { - Logger.Error("A{3} '{0}' '{1}' element is missing a{4} '{2}' element.", parentName, nodeName, elementName, - Suffix(parentName), Suffix(elementName)); + var combinedName = CombineName(parentName, nodeName); + Logger.Error("A{2} {0} is missing {1}.", combinedName, attributeName, Suffix(combinedName)); } public void MissingRequiredAdd(string parent, string key) { - Logger.Error($"A{Suffix(key)} '{key}' element with at least one item is required{(string.IsNullOrEmpty(parent) ? "." : " in " + parent + ".")}"); + Logger.Error($"{key} must be populated{(string.IsNullOrEmpty(parent) ? "." : " in " + parent + ".")}"); } public void SettingValue(string propertyName, object value, string parentName, string nodeName, string message) { - Logger.Error("Could not set '{0}' to '{1}' inside '{2}' '{3}'. {4}", propertyName, value, parentName, nodeName, message); - } - public void UnexpectedElement(string elementName, string subNodeName) { - Logger.Error("Invalid element {0} in {1}. Only 'add' elements are allowed here.", subNodeName, elementName); + Logger.Error("Could not set {0} to {1} inside {2}. {3}", propertyName, value, CombineName(parentName, nodeName), message); } - public void ShorthandNotLoaded(string parentName, string nodeName, string attributeName) { - Logger.Error("A{3} '{0}' '{1}' element's '{2}' attribute needs a shorthand configuration, but none was loaded.", parentName, nodeName, attributeName, Suffix(parentName)); + public void UnexpectedElement(string elementName, string subNodeName) { + Logger.Error("There is an invalid {0} in {1}.", subNodeName, elementName); } public void ValueNotInDomain(string name, object value, string validValues) { - Logger.Error("An invalid value of '{0}' is in the '{1}' attribute. The valid domain is: {2}.", value, name, validValues); + Logger.Error("An invalid value of {0} is in {1}. The valid domain is: {2}.", value, name, validValues); } public void ParseException(string message) { @@ -111,43 +92,51 @@ private static bool IsVowel(char c) { } public void OnlyOneAttributeAllowed(string parentName, string name, int count) { - Logger.Error("The '{0}' '{1}' collection does not inherit from CfgNode or implement IProperties, so you can only have one value (attribute). You have {2} defined.", parentName, name, count); + Logger.Error("{0} does not inherit from CfgNode or implement IProperties, so you can only have one value in it. You have {1} defined.", CombineName(parentName, name), count); } public void ConstructorNotFound(string parentName, string name) { - Logger.Error("The '{0}' '{1}' collection implementing IProperties has an incompatible constructor. Cfg-Net needs a constructorless or single parameter constructor. The single parameter may be a string[] of names, or an integer representing capacity.", parentName, name); + Logger.Error("{0} implementing IProperties has an incompatible constructor. Cfg-Net needs a constructorless or single parameter constructor. The single parameter may be a string[] of names, or an integer representing capacity.", CombineName(parentName, name)); } public void TypeMismatch(string key, object value, Type propertyType) { - Logger.Error("The '{0}' attribute default value '{1}' does not have the same type as the property type of '{2}'.", key, value, propertyType); + Logger.Error("The {0} default of {1} is not a {2}. Please cast it as such or change your type.", key, value, propertyType); } public void ValueTooShort(string name, string value, int minLength) { - Logger.Error("The '{0}' attribute value '{1}' is too short. It is {3} characters. It must be at least {2} characters.", name, value, minLength, value.Length); + Logger.Error("The {0} {1} is too short. It is {3} characters. It must be at least {2} characters.", name, value, minLength, value.Length); } public void ValueTooLong(string name, string value, int maxLength) { - Logger.Error("The '{0}' attribute value '{1}' is too long. It is {3} characters. It must not exceed {2} characters.", name, value, maxLength, value.Length); + var val = string.IsNullOrEmpty(value) ? "(blank)" : value; + Logger.Error("The {0} {1} is too long. It is {3} characters. It must not exceed {2} characters.", name, val, maxLength, value?.Length ?? 0); } public void ValueIsNotComparable(string name, object value) { - Logger.Error("The '{0}' attribute value '{1}' is not comparable. Having a minValue or maxValue set on an incomparable property type causes this.", name, value); + var val = value == null || value.ToString() == string.Empty ? "(blank)" : value; + Logger.Error("The {0} value {1} is not comparable. Having a minValue or maxValue set on an incomparable property type is invalid.", name, val); } public void ValueTooSmall(string name, object value, object minValue) { - Logger.Error("The '{0}' attribute value '{1}' is too small. The minimum value allowed is '{2}'.", name, value, minValue); + var val = value == null || value.ToString() == string.Empty ? "(blank)" : value; + Logger.Error("The {0} value {1} is too small. The minimum value allowed is {2}.", name, val, minValue); } public void ValueTooBig(string name, object value, object maxValue) { - Logger.Error("The '{0}' attribute value '{1}' is too big. The maximum value allowed is '{2}'.", name, value, maxValue); + var val = value == null || value.ToString() == string.Empty ? "(blank)" : value; + Logger.Error("The {0} value {1} is too big. The maximum value allowed is {2}.", name, val, maxValue); + } + + public void NullOrEmptyConfiguration() { + Error("The configuration passed in is null or empty."); } - public string[] Errors() { - return Logger.Errors(); + public void InvalidConfiguration(char character) { + Error($"Without a custom parser, the configuration should be XML or JSON. Your configuration starts with {character}."); } - public string[] Warnings() { - return Logger.Warnings(); + public void Clear() { + Logger.Clear(); } } diff --git a/Cfg.Net.Shared/CfgMetadata.cs b/Cfg.Net.Shared/CfgMetadata.cs index 90c604c..2ecf945 100644 --- a/Cfg.Net.Shared/CfgMetadata.cs +++ b/Cfg.Net.Shared/CfgMetadata.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -32,7 +33,7 @@ sealed class CfgMetadata { public Action Setter { get; set; } public Func Getter { get; set; } public bool TypeMismatch { get; set; } - public object Default { get; set; } + public object TypeDefault { get; set; } public CfgMetadata(PropertyInfo propertyInfo, CfgAttribute attribute) { PropertyInfo = propertyInfo; diff --git a/Cfg.Net.Shared/CfgMetadataCache.cs b/Cfg.Net.Shared/CfgMetadataCache.cs index 39097be..958bea6 100644 --- a/Cfg.Net.Shared/CfgMetadataCache.cs +++ b/Cfg.Net.Shared/CfgMetadataCache.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -49,7 +50,6 @@ internal static Dictionary GetMetadata(Type type, CfgEvents var propertyInfos = type.GetProperties(); #endif - metadata = new Dictionary(StringComparer.Ordinal); foreach (var propertyInfo in propertyInfos) { if (!propertyInfo.CanRead) @@ -68,7 +68,7 @@ internal static Dictionary GetMetadata(Type type, CfgEvents var key = NormalizeName(type, propertyInfo.Name); var item = new CfgMetadata(propertyInfo, attribute) { - Default = GetDefaultValue(propertyInfo.PropertyType) + TypeDefault = GetDefaultValue(propertyInfo.PropertyType) }; // check default value for type mismatch @@ -100,7 +100,6 @@ internal static Dictionary GetMetadata(Type type, CfgEvents attribute.maxValue = maxValue; } - #if NETS var propertyTypeInfo = propertyInfo.PropertyType.GetTypeInfo(); if (propertyTypeInfo.IsGenericType) { @@ -124,7 +123,6 @@ internal static Dictionary GetMetadata(Type type, CfgEvents } #endif - if (string.IsNullOrEmpty(attribute.name)) { attribute.name = key; } @@ -262,5 +260,6 @@ private static void CloneLists(IDictionary meta, object nod meta[pair.Key].Setter(clone, cloneItems); } } + } } \ No newline at end of file diff --git a/Cfg.Net.Shared/CfgNode.cs b/Cfg.Net.Shared/CfgNode.cs index 552cfe2..3a9ac3e 100644 --- a/Cfg.Net.Shared/CfgNode.cs +++ b/Cfg.Net.Shared/CfgNode.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,7 +21,6 @@ using System.Linq; using System.Reflection; using Cfg.Net.Contracts; -using Cfg.Net.Ext; using Cfg.Net.Loggers; using Cfg.Net.Parsers; using Cfg.Net.Serializers; @@ -39,29 +39,34 @@ public abstract class CfgNode { internal CfgEvents Events { get; set; } protected Dictionary UniqueProperties { get; } = new Dictionary(); + protected CfgNode() { + Events = new CfgEvents(new DefaultLogger(new MemoryLogger(), Logger)); + Clear(); + Type = GetType(); + } + /// /// Constructor for injecting anything marked with IDependency /// /// - protected CfgNode(params IDependency[] dependencies) { - - if (dependencies != null) { - foreach (var dependency in dependencies.Where(dependency => dependency != null)) { - if (dependency is IReader) { - Reader = dependency as IReader; - } else if (dependency is IParser) { - Parser = dependency as IParser; - } else if (dependency is ISerializer) { - Serializer = dependency as ISerializer; - } else if (dependency is ILogger) { - Logger = dependency as ILogger; - } else if (dependency is ICustomizer) { - Customizers.Add(dependency as ICustomizer); - } + protected CfgNode(params IDependency[] dependencies) : this() { + + if (dependencies == null) + return; + + foreach (var dependency in dependencies.Where(dependency => dependency != null)) { + if (dependency is IReader) { + Reader = dependency as IReader; + } else if (dependency is IParser) { + Parser = dependency as IParser; + } else if (dependency is ISerializer) { + Serializer = dependency as ISerializer; + } else if (dependency is ILogger) { + Logger = dependency as ILogger; + } else if (dependency is ICustomizer) { + Customizers.Add(dependency as ICustomizer); } } - - Type = GetType(); } protected internal void Error(string message, params object[] args) { @@ -76,16 +81,14 @@ protected internal void Warn(string message, params object[] args) { /// Load the configuration into the root (top-most) node. /// /// by default, cfg should be XML or JSON, but can be other things depending on what IParser is injected. - /// key, value pairs that replace @(PlaceHolders) with values. + /// key, value pairs that may be used in ICustomizer implementations. public void Load(string cfg, IDictionary parameters = null) { - var logger = new DefaultLogger(new MemoryLogger(), Logger); - Events = new CfgEvents(logger); - this.Clear(Events); + Clear(); + Events.Clear(); if (string.IsNullOrEmpty(cfg)) { - Events.Error("The configuration passed in is null."); - this.SetDefaults(); + Events.NullOrEmptyConfiguration(); return; } @@ -98,9 +101,8 @@ public void Load(string cfg, IDictionary parameters = null) { INode node; try { if (Reader != null) { - cfg = Reader.Read(cfg, parameters, logger); - if (Events.Errors().Any()) { - this.SetDefaults(); + cfg = Reader.Read(cfg, parameters, Events.Logger); + if (Events.Logger.Errors().Any()) { return; } } @@ -114,8 +116,7 @@ public void Load(string cfg, IDictionary parameters = null) { node = new NanoXmlParser().Parse(cfg); break; default: - Events.Error("Without a custom parser, the configuration should be XML or JSON. Your configuration starts with the character {0}.", cfg[0]); - this.SetDefaults(); + Events.InvalidConfiguration(cfg[0]); return; } } else { @@ -145,16 +146,18 @@ public void Load(string cfg, IDictionary parameters = null) { } } - LoadProperties(node, string.Empty, parameters, Customizers); - LoadCollections(node, string.Empty, parameters); - PreValidate(); - ValidateBasedOnAttributes(node, parameters); - ValidateListsBasedOnAttributes(node.Name); - Validate(); - PostValidate(); + Process(node, string.Empty, Serializer, Events, parameters, Customizers); } - CfgNode Load( + public void Check() { + Events.Clear(); + var name = CfgMetadataCache.NormalizeName(Type, Type.Name); + var node = new ObjectNode(this, name); + Process(node, name, Serializer, Events, new Dictionary(StringComparer.OrdinalIgnoreCase), Customizers); + } + + + private CfgNode Process( INode node, string parent, ISerializer serializer, @@ -162,10 +165,10 @@ CfgNode Load( IDictionary parameters, IList customizers ) { - this.Clear(events); - - // parser, reader, and mergeParameters do not need to be passed in + Clear(); + // preserving events, customizers, and serializer + Events = events; Customizers = customizers; Serializer = serializer; @@ -290,8 +293,8 @@ void LoadCollections(INode node, string parentName, IDictionary } } } else { - var loaded = item.Loader().Load(add, subNode.Name, Serializer, Events, parameters, Customizers); - elements[addKey].Add(loaded); + var processed = item.Loader().Process(add, subNode.Name, Serializer, Events, parameters, Customizers); + elements[addKey].Add(processed); } } else { Events.UnexpectedElement(add.Name, subNode.Name); @@ -308,7 +311,7 @@ protected internal void ValidateListsBasedOnAttributes(string parent) { var elementNames = CfgMetadataCache.ElementNames(Type).ToList(); foreach (var listName in elementNames) { var listMetadata = metadata[listName]; - var list = (IList)metadata[listName].Getter(this); + var list = (IList)listMetadata.Getter(this); ValidateUniqueAndRequiredProperties(parent, listName, listMetadata, list); } } @@ -404,6 +407,9 @@ void LoadProperties(INode node, string parentName, IDictionary p if (item.PropertyInfo.PropertyType == typeof(string)) { + if (attribute.Value == null) // user has not provided a default + continue; + var stringValue = attribute.Value.ToString(); if (item.Attribute.toLower) { @@ -520,12 +526,25 @@ void CheckValueBoundaries(CfgAttribute itemAttributes, string name, object value } public string[] Errors() { - return Events == null ? new string[0] : Events.Errors(); + return Events == null ? new string[0] : Events.Logger.Errors(); } public string[] Warnings() { - return Events == null ? new string[0] : Events.Warnings(); + return Events == null ? new string[0] : Events.Logger.Warnings(); } + /// + /// Clears Cfg decorated properties. + /// + private void Clear() { + var metadata = CfgMetadataCache.GetMetadata(GetType(), Events); + foreach (var pair in metadata) { + if (pair.Value.ListType == null) { + pair.Value.Setter(this, pair.Value.TypeMismatch ? pair.Value.TypeDefault : pair.Value.Attribute.value); + } else { + pair.Value.Setter(this, Activator.CreateInstance(pair.Value.PropertyInfo.PropertyType)); + } + } + } } } \ No newline at end of file diff --git a/Cfg.Net.Shared/CfgNodeTraverser.cs b/Cfg.Net.Shared/CfgNodeTraverser.cs deleted file mode 100644 index 5a4174d..0000000 --- a/Cfg.Net.Shared/CfgNodeTraverser.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using Cfg.Net.Contracts; - -namespace Cfg.Net.Shared { - public static class CfgNodeTraverser { - public static void Traverse(IEnumerable nodes, Action, ILogger> action, IDictionary parameters, ILogger logger) { - foreach (var node in nodes) { - action(node, parameters, logger); - Traverse(node.SubNodes, action, parameters, logger); - } - } - } -} diff --git a/Cfg.Net.Shared/CfgReflectionHelper.cs b/Cfg.Net.Shared/CfgReflectionHelper.cs index 477603e..7f344da 100644 --- a/Cfg.Net.Shared/CfgReflectionHelper.cs +++ b/Cfg.Net.Shared/CfgReflectionHelper.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -65,5 +66,9 @@ public static Action CreateSetterGeneric(MethodInfo setter var setterDelegate = (Action)((instance, value) => setterTypedDelegate((T)instance, value == null ? default(V) : (V)value)); return setterDelegate; } + + } + + } \ No newline at end of file diff --git a/Cfg.Net.Shared/Contracts/IAttribute.cs b/Cfg.Net.Shared/Contracts/IAttribute.cs index 724b7f7..870f229 100644 --- a/Cfg.Net.Shared/Contracts/IAttribute.cs +++ b/Cfg.Net.Shared/Contracts/IAttribute.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Contracts/ICustomizer.cs b/Cfg.Net.Shared/Contracts/ICustomizer.cs index 19b5831..3e23092 100644 --- a/Cfg.Net.Shared/Contracts/ICustomizer.cs +++ b/Cfg.Net.Shared/Contracts/ICustomizer.cs @@ -1,3 +1,20 @@ +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion using System.Collections.Generic; namespace Cfg.Net.Contracts { diff --git a/Cfg.Net.Shared/Contracts/IDependency.cs b/Cfg.Net.Shared/Contracts/IDependency.cs index 7b9224e..3a16d25 100644 --- a/Cfg.Net.Shared/Contracts/IDependency.cs +++ b/Cfg.Net.Shared/Contracts/IDependency.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Contracts/ILogger.cs b/Cfg.Net.Shared/Contracts/ILogger.cs index 518141e..27e1800 100644 --- a/Cfg.Net.Shared/Contracts/ILogger.cs +++ b/Cfg.Net.Shared/Contracts/ILogger.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Contracts/INode.cs b/Cfg.Net.Shared/Contracts/INode.cs index 49b4104..b1c0dae 100644 --- a/Cfg.Net.Shared/Contracts/INode.cs +++ b/Cfg.Net.Shared/Contracts/INode.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,10 +17,8 @@ #endregion using System.Collections.Generic; -namespace Cfg.Net.Contracts -{ - public interface INode - { +namespace Cfg.Net.Contracts { + public interface INode { string Name { get; } List Attributes { get; } List SubNodes { get; } diff --git a/Cfg.Net.Shared/Contracts/IParser.cs b/Cfg.Net.Shared/Contracts/IParser.cs index 5536bcf..1d70e69 100644 --- a/Cfg.Net.Shared/Contracts/IParser.cs +++ b/Cfg.Net.Shared/Contracts/IParser.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Contracts/IProperties.cs b/Cfg.Net.Shared/Contracts/IProperties.cs index e5f7a20..502b48f 100644 --- a/Cfg.Net.Shared/Contracts/IProperties.cs +++ b/Cfg.Net.Shared/Contracts/IProperties.cs @@ -1,20 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion - using System.Collections.Generic; namespace Cfg.Net.Contracts { diff --git a/Cfg.Net.Shared/Contracts/IReader.cs b/Cfg.Net.Shared/Contracts/IReader.cs index e23871d..6ec750a 100644 --- a/Cfg.Net.Shared/Contracts/IReader.cs +++ b/Cfg.Net.Shared/Contracts/IReader.cs @@ -1,20 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion - using System.Collections.Generic; namespace Cfg.Net.Contracts { diff --git a/Cfg.Net.Shared/Contracts/ISerializer.cs b/Cfg.Net.Shared/Contracts/ISerializer.cs index a985334..43bba3b 100644 --- a/Cfg.Net.Shared/Contracts/ISerializer.cs +++ b/Cfg.Net.Shared/Contracts/ISerializer.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Ext/Extensions.cs b/Cfg.Net.Shared/Ext/Extensions.cs index da15a6a..248b1f7 100644 --- a/Cfg.Net.Shared/Ext/Extensions.cs +++ b/Cfg.Net.Shared/Ext/Extensions.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,9 +17,7 @@ #endregion using System; using System.Linq; -using System.Reflection; using System.Text; -using Cfg.Net.Contracts; using Cfg.Net.Loggers; using Cfg.Net.Parsers; @@ -26,59 +25,6 @@ namespace Cfg.Net.Ext { public static class Extensions { - internal static void SetDefaults(this CfgNode node) { - - var metadata = CfgMetadataCache.GetMetadata(node.GetType(), node.Events); - foreach (var pair in metadata) { -#if NETS - bool? isGenericType = pair.Value.PropertyInfo.PropertyType.GetTypeInfo().IsGenericType; -#else - bool? isGenericType = pair.Value.PropertyInfo.PropertyType.IsGenericType; -#endif - if (isGenericType.Value) { - var value = pair.Value.Getter(node); - if (value == null) { - pair.Value.Setter(node, Activator.CreateInstance(pair.Value.PropertyInfo.PropertyType)); - } - } else { - if (pair.Value.TypeMismatch || pair.Value.Attribute.value == null) - continue; - - var value = pair.Value.Getter(node); - - if (value == null) { - pair.Value.Setter(node, pair.Value.Attribute.value); - } else if (value.Equals(pair.Value.Default)) { - if (pair.Value.Default.Equals(pair.Value.Attribute.value)) { - if (!pair.Value.Attribute.ValueIsSet) { - pair.Value.Setter(node, pair.Value.Attribute.value); - } - } else { - pair.Value.Setter(node, pair.Value.Attribute.value); - } - } - } - } - } - - internal static void Clear(this CfgNode node, CfgEvents events) { - var metadata = CfgMetadataCache.GetMetadata(node.GetType(), node.Events); - foreach (var pair in metadata) { -#if NETS - bool? isGenericType = pair.Value.PropertyInfo.PropertyType.GetTypeInfo().IsGenericType; -#else - bool? isGenericType = pair.Value.PropertyInfo.PropertyType.IsGenericType; -#endif - - if (isGenericType.Value) { - pair.Value.Setter(node, Activator.CreateInstance(pair.Value.PropertyInfo.PropertyType)); - } else { - pair.Value.Setter(node, pair.Value.TypeMismatch ? pair.Value.Default : pair.Value.Attribute.value); - } - } - node.Events = events ?? new CfgEvents(new DefaultLogger(new MemoryLogger(), null)); - } - /// /// When you want to clone yourself /// @@ -88,14 +34,13 @@ public static T Clone(this T node) where T : CfgNode { return CfgMetadataCache.Clone(node); } - + [Obsolete("This isn't necessary anymore. Every object that inherits from CfgNode is created with defaults.")] public static T WithDefaults(this T node) where T : CfgNode { - node.SetDefaults(); return node; } + [Obsolete("Use Check method in CfgNode instead.")] public static T WithValidation(this T node, string parent = "") where T : CfgNode { - node.WithDefaults(); if (node.Events == null) { node.Events = new CfgEvents(new DefaultLogger(new MemoryLogger(), null)); } diff --git a/Cfg.Net.Shared/Loggers/DefaultLogger.cs b/Cfg.Net.Shared/Loggers/DefaultLogger.cs index 32f66ce..09e6344 100644 --- a/Cfg.Net.Shared/Loggers/DefaultLogger.cs +++ b/Cfg.Net.Shared/Loggers/DefaultLogger.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -31,14 +32,14 @@ public DefaultLogger(MemoryLogger memorylogger, ILogger logger) { } public void Warn(string message, params object[] args) { - for (int i = 0; i < _loggers.Count; i++) { - _loggers[i].Warn(message, args); + foreach (var logger in _loggers) { + logger.Warn(message, args); } } public void Error(string message, params object[] args) { - for (int i = 0; i < _loggers.Count; i++) { - _loggers[i].Error(message, args); + foreach (var logger in _loggers) { + logger.Error(message, args); } } @@ -49,5 +50,9 @@ public string[] Errors() { public string[] Warnings() { return _memorylogger.Warnings(); } + + public void Clear() { + _memorylogger.Clear(); + } } } \ No newline at end of file diff --git a/Cfg.Net.Shared/Loggers/MemoryLogger.cs b/Cfg.Net.Shared/Loggers/MemoryLogger.cs index 38de04f..7a97b2f 100644 --- a/Cfg.Net.Shared/Loggers/MemoryLogger.cs +++ b/Cfg.Net.Shared/Loggers/MemoryLogger.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -71,5 +72,11 @@ public string[] Warnings() { .ToArray()); } + public void Clear() { + _errorCache = null; + _warningCache = null; + _errors.Clear(); + _warnings.Clear(); + } } } \ No newline at end of file diff --git a/Cfg.Net.Shared/Loggers/NullLogger.cs b/Cfg.Net.Shared/Loggers/NullLogger.cs index 216affe..0e09e92 100644 --- a/Cfg.Net.Shared/Loggers/NullLogger.cs +++ b/Cfg.Net.Shared/Loggers/NullLogger.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Parsers/CollectionNode.cs b/Cfg.Net.Shared/Parsers/CollectionNode.cs new file mode 100644 index 0000000..2218974 --- /dev/null +++ b/Cfg.Net.Shared/Parsers/CollectionNode.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using Cfg.Net.Contracts; + +namespace Cfg.Net.Parsers { + + public class CollectionNode : INode { + public CollectionNode(string name) { + Name = name; + Attributes = new List(); + SubNodes = new List(); + } + public string Name { get; } + public List Attributes { get; } + public List SubNodes { get; } + public bool TryAttribute(string name, out IAttribute attr) { + attr = null; + return false; + } + } +} \ No newline at end of file diff --git a/Cfg.Net.Shared/Parsers/JsonNode.cs b/Cfg.Net.Shared/Parsers/JsonNode.cs index 1b5b6ca..c3eed26 100644 --- a/Cfg.Net.Shared/Parsers/JsonNode.cs +++ b/Cfg.Net.Shared/Parsers/JsonNode.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Parsers/JsonParser.cs b/Cfg.Net.Shared/Parsers/JsonParser.cs index 1c04261..a7c540a 100644 --- a/Cfg.Net.Shared/Parsers/JsonParser.cs +++ b/Cfg.Net.Shared/Parsers/JsonParser.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,9 +23,5 @@ public class FastJsonParser : IParser { public INode Parse(string cfg) { return new JsonNode(JSON.Parse(cfg)); } - - public string Decode(string value) { - return value; - } } } \ No newline at end of file diff --git a/Cfg.Net.Shared/Parsers/NodeAttribute.cs b/Cfg.Net.Shared/Parsers/NodeAttribute.cs index d0affea..af39a43 100644 --- a/Cfg.Net.Shared/Parsers/NodeAttribute.cs +++ b/Cfg.Net.Shared/Parsers/NodeAttribute.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,10 +17,15 @@ #endregion using Cfg.Net.Contracts; -namespace Cfg.Net.Parsers -{ - public class NodeAttribute : IAttribute - { +namespace Cfg.Net.Parsers { + public class NodeAttribute : IAttribute { + public NodeAttribute() {} + + public NodeAttribute(string name, object value) { + Name = name; + Value = value; + } + public string Name { get; set; } public object Value { get; set; } } diff --git a/Cfg.Net.Shared/Parsers/ObjectNode.cs b/Cfg.Net.Shared/Parsers/ObjectNode.cs new file mode 100644 index 0000000..3199338 --- /dev/null +++ b/Cfg.Net.Shared/Parsers/ObjectNode.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using Cfg.Net.Contracts; + +namespace Cfg.Net.Parsers { + public class ObjectNode : INode { + + private readonly Dictionary _attributes = new Dictionary(); + + public ObjectNode(object cfgNode, string name) { + + var type = cfgNode.GetType(); + var metadata = CfgMetadataCache.GetMetadata(type); + Name = name; + Attributes = new List(); + SubNodes = new List(); + + foreach (var pair in metadata) { + if (pair.Value.ListType == null) { + // get the value, create attribute + var value = pair.Value.Getter(cfgNode); + var attribute = new NodeAttribute(pair.Value.Attribute.name, value); + _attributes[attribute.Name] = attribute; + Attributes.Add(attribute); + } else { + // get the list, transfer it to collection node of sub nodes + var list = (IList)pair.Value.Getter(cfgNode); + if (list == null) + continue; + var collection = new CollectionNode(pair.Value.Attribute.name); + foreach (var item in list) { + collection.SubNodes.Add(new ObjectNode(item, "add")); + } + SubNodes.Add(collection); + } + } + } + + public string Name { get; } + public List Attributes { get; } + public List SubNodes { get; } + public bool TryAttribute(string name, out IAttribute attr) { + if (_attributes.ContainsKey(name)) { + attr = _attributes[name]; + return true; + } + attr = null; + return false; + } + } +} \ No newline at end of file diff --git a/Cfg.Net.Shared/Parsers/XmlNode.cs b/Cfg.Net.Shared/Parsers/XmlNode.cs index 33c52a3..8c50005 100644 --- a/Cfg.Net.Shared/Parsers/XmlNode.cs +++ b/Cfg.Net.Shared/Parsers/XmlNode.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Parsers/XmlParser.cs b/Cfg.Net.Shared/Parsers/XmlParser.cs index d538d94..c9a2ca3 100644 --- a/Cfg.Net.Shared/Parsers/XmlParser.cs +++ b/Cfg.Net.Shared/Parsers/XmlParser.cs @@ -1,23 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Text; using Cfg.Net.Contracts; using Cfg.Net.Parsers.nanoXML; diff --git a/Cfg.Net.Shared/Parsers/fastJSON/JSON.cs b/Cfg.Net.Shared/Parsers/fastJSON/JSON.cs index a0f0e5b..ab809dd 100644 --- a/Cfg.Net.Shared/Parsers/fastJSON/JSON.cs +++ b/Cfg.Net.Shared/Parsers/fastJSON/JSON.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Parsers/fastJSON/JsonParser.cs b/Cfg.Net.Shared/Parsers/fastJSON/JsonParser.cs index 82238de..551e934 100644 --- a/Cfg.Net.Shared/Parsers/fastJSON/JsonParser.cs +++ b/Cfg.Net.Shared/Parsers/fastJSON/JsonParser.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlAttribute.cs b/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlAttribute.cs index d3ce9f6..f5c5b3a 100644 --- a/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlAttribute.cs +++ b/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlAttribute.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlBase.cs b/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlBase.cs index 8e08941..4f6da22 100644 --- a/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlBase.cs +++ b/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlBase.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlDocument.cs b/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlDocument.cs index 6561c70..1ec0c79 100644 --- a/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlDocument.cs +++ b/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlDocument.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlNode.cs b/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlNode.cs index eaddb8d..88821c3 100644 --- a/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlNode.cs +++ b/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlNode.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlParsingException.cs b/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlParsingException.cs index 6350092..5259584 100644 --- a/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlParsingException.cs +++ b/Cfg.Net.Shared/Parsers/nanoXML/NanoXmlParsingException.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shared/Serializers/JsonSerializer.cs b/Cfg.Net.Shared/Serializers/JsonSerializer.cs index d4a7690..0995607 100644 --- a/Cfg.Net.Shared/Serializers/JsonSerializer.cs +++ b/Cfg.Net.Shared/Serializers/JsonSerializer.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -119,7 +120,7 @@ private static void SerializeAttributes(IDictionary meta, o continue; } var value = pair.Value.Getter(obj); - if (value == null || value.Equals(pair.Value.Attribute.value) || (!pair.Value.Attribute.ValueIsSet && pair.Value.Default != null && pair.Value.Default.Equals(value))) { + if (value == null || value.Equals(pair.Value.Attribute.value) || (!pair.Value.Attribute.ValueIsSet && pair.Value.TypeDefault != null && pair.Value.TypeDefault.Equals(value))) { continue; } diff --git a/Cfg.Net.Shared/Serializers/XmlSerializer.cs b/Cfg.Net.Shared/Serializers/XmlSerializer.cs index 5fbf7d8..e469d0e 100644 --- a/Cfg.Net.Shared/Serializers/XmlSerializer.cs +++ b/Cfg.Net.Shared/Serializers/XmlSerializer.cs @@ -1,20 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion - using System; using System.Collections; using System.Collections.Generic; @@ -131,7 +131,7 @@ private void SerializeAttributes(IDictionary meta, object o continue; var value = pair.Value.Getter(obj); - if (value == null || value.Equals(pair.Value.Attribute.value) || (!pair.Value.Attribute.ValueIsSet && pair.Value.Default != null && pair.Value.Default.Equals(value))) { + if (value == null || value.Equals(pair.Value.Attribute.value) || (!pair.Value.Attribute.ValueIsSet && pair.Value.TypeDefault != null && pair.Value.TypeDefault.Equals(value))) { continue; } diff --git a/Cfg.Net.Shorthand/Expression.cs b/Cfg.Net.Shorthand/Expression.cs index 5d298a8..16229ec 100644 --- a/Cfg.Net.Shorthand/Expression.cs +++ b/Cfg.Net.Shorthand/Expression.cs @@ -1,20 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion - using System; using System.Collections.Generic; using System.Linq; diff --git a/Cfg.Net.Shorthand/Expressions.cs b/Cfg.Net.Shorthand/Expressions.cs index 843d3ba..af39d2f 100644 --- a/Cfg.Net.Shorthand/Expressions.cs +++ b/Cfg.Net.Shorthand/Expressions.cs @@ -1,20 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion - using System.Collections.Generic; using System.Linq; diff --git a/Cfg.Net.Shorthand/Method.cs b/Cfg.Net.Shorthand/Method.cs index fa6f541..f046109 100644 --- a/Cfg.Net.Shorthand/Method.cs +++ b/Cfg.Net.Shorthand/Method.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shorthand/MethodData.cs b/Cfg.Net.Shorthand/MethodData.cs index fc2b219..a00add7 100644 --- a/Cfg.Net.Shorthand/MethodData.cs +++ b/Cfg.Net.Shorthand/MethodData.cs @@ -1,20 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion - namespace Cfg.Net.Shorthand { public class MethodData { public MethodData(Method method, Signature signature) { diff --git a/Cfg.Net.Shorthand/Node.cs b/Cfg.Net.Shorthand/Node.cs index 3d289fc..7d61cf4 100644 --- a/Cfg.Net.Shorthand/Node.cs +++ b/Cfg.Net.Shorthand/Node.cs @@ -1,20 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion - using System; using System.Collections.Generic; using Cfg.Net.Contracts; diff --git a/Cfg.Net.Shorthand/Parameter.cs b/Cfg.Net.Shorthand/Parameter.cs index 6878630..0f1c188 100644 --- a/Cfg.Net.Shorthand/Parameter.cs +++ b/Cfg.Net.Shorthand/Parameter.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shorthand/Properties/AssemblyInfo.cs b/Cfg.Net.Shorthand/Properties/AssemblyInfo.cs index b8e46ec..0bf551f 100644 --- a/Cfg.Net.Shorthand/Properties/AssemblyInfo.cs +++ b/Cfg.Net.Shorthand/Properties/AssemblyInfo.cs @@ -1,4 +1,21 @@ -using System.Resources; +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion +using System.Resources; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/Cfg.Net.Shorthand/ShorthandAttribute.cs b/Cfg.Net.Shorthand/ShorthandAttribute.cs index b4a15d6..ad5246b 100644 --- a/Cfg.Net.Shorthand/ShorthandAttribute.cs +++ b/Cfg.Net.Shorthand/ShorthandAttribute.cs @@ -1,20 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion - using Cfg.Net.Contracts; namespace Cfg.Net.Shorthand { diff --git a/Cfg.Net.Shorthand/ShorthandCustomizer.cs b/Cfg.Net.Shorthand/ShorthandCustomizer.cs index ac60d5a..d2eb91e 100644 --- a/Cfg.Net.Shorthand/ShorthandCustomizer.cs +++ b/Cfg.Net.Shorthand/ShorthandCustomizer.cs @@ -1,4 +1,21 @@ -using System; +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion +using System; using System.Collections.Generic; using System.Linq; using Cfg.Net.Contracts; diff --git a/Cfg.Net.Shorthand/ShorthandRoot.cs b/Cfg.Net.Shorthand/ShorthandRoot.cs index c8d51fa..69b531e 100644 --- a/Cfg.Net.Shorthand/ShorthandRoot.cs +++ b/Cfg.Net.Shorthand/ShorthandRoot.cs @@ -1,20 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion - using System; using System.Collections.Generic; using System.Linq; diff --git a/Cfg.Net.Shorthand/Signature.cs b/Cfg.Net.Shorthand/Signature.cs index 02189c3..6129a49 100644 --- a/Cfg.Net.Shorthand/Signature.cs +++ b/Cfg.Net.Shorthand/Signature.cs @@ -1,20 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion - using System.Collections.Generic; namespace Cfg.Net.Shorthand diff --git a/Cfg.Net.Shorthand/Target.cs b/Cfg.Net.Shorthand/Target.cs index a185522..a5bef0b 100644 --- a/Cfg.Net.Shorthand/Target.cs +++ b/Cfg.Net.Shorthand/Target.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Net.Shorthand/Utility.cs b/Cfg.Net.Shorthand/Utility.cs index 93c148a..940807a 100644 --- a/Cfg.Net.Shorthand/Utility.cs +++ b/Cfg.Net.Shorthand/Utility.cs @@ -1,20 +1,20 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion - using System; using System.Collections.Generic; using System.Linq; diff --git a/Cfg.Net.sln.DotSettings b/Cfg.Net.sln.DotSettings new file mode 100644 index 0000000..2d62e9c --- /dev/null +++ b/Cfg.Net.sln.DotSettings @@ -0,0 +1,16 @@ + + $SOLUTION$ +An Alternative .NET Configuration Handler +Copyright 2015-2017 Dale Newman + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. \ No newline at end of file diff --git a/Cfg.Net/Cfg.Net.nuspec b/Cfg.Net/Cfg.Net.nuspec index ec2de62..9b9a3d9 100644 --- a/Cfg.Net/Cfg.Net.nuspec +++ b/Cfg.Net/Cfg.Net.nuspec @@ -2,7 +2,7 @@ Cfg-NET - 0.9.3 + 0.9.4 Cfg-NET Dale Newman Dale Newman @@ -10,7 +10,7 @@ https://github.com/dalenewman/Cfg-NET false An alternative configuration handler. - fix issue #2 + Configure in Code and Check Copyright 2015-2017 configuration, settings diff --git a/Cfg.Net/Properties/AssemblyInfo.cs b/Cfg.Net/Properties/AssemblyInfo.cs index 5b1045e..446e222 100644 --- a/Cfg.Net/Properties/AssemblyInfo.cs +++ b/Cfg.Net/Properties/AssemblyInfo.cs @@ -1,4 +1,21 @@ -using System.Reflection; +#region license +// Cfg.Net +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -26,5 +43,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("0.9.3.0")] -[assembly: AssemblyFileVersion("0.9.3.0")] +[assembly: AssemblyVersion("0.9.4.0")] +[assembly: AssemblyFileVersion("0.9.4.0")] diff --git a/Cfg.Test/Case.cs b/Cfg.Test/Case.cs index c9e8305..c998618 100644 --- a/Cfg.Test/Case.cs +++ b/Cfg.Test/Case.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/Cfg.Test.csproj b/Cfg.Test/Cfg.Test.csproj index eecb915..37dcb8b 100644 --- a/Cfg.Test/Cfg.Test.csproj +++ b/Cfg.Test/Cfg.Test.csproj @@ -63,6 +63,7 @@ + diff --git a/Cfg.Test/Clone.cs b/Cfg.Test/Clone.cs index 28498ef..f207de8 100644 --- a/Cfg.Test/Clone.cs +++ b/Cfg.Test/Clone.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/ConfigureWithCode.cs b/Cfg.Test/ConfigureWithCode.cs new file mode 100644 index 0000000..4be53f1 --- /dev/null +++ b/Cfg.Test/ConfigureWithCode.cs @@ -0,0 +1,49 @@ +using System.Collections.Generic; +using System.Runtime.Remoting; +using Cfg.Net; +using NUnit.Framework; + +namespace Cfg.Test { + + [TestFixture] + public class ConfigureWithCode { + + [Test] + public void Test1() { + + var example = new Example(); + Assert.AreEqual(0, example.Errors().Length); + Assert.IsNullOrEmpty(example.Name); + Assert.IsNotNull(example.Items); + + example.Check(); + Assert.AreNotEqual(0, example.Errors().Length); + Assert.AreEqual(1, example.Warnings().Length); + Assert.AreEqual(2, example.Errors().Length); + + example.Items.Add(new ExampleItem { Value = 5}); + example.Items.Add(new ExampleItem { Value = 6}); + example.Check(); + Assert.AreNotEqual(0, example.Errors().Length); + Assert.AreEqual(1, example.Warnings().Length); + Assert.AreEqual(1, example.Errors().Length, "Only 1 error because we fixed the missing items."); + + example.Name = "I am required"; + example.Check(); + Assert.AreEqual(0, example.Errors().Length, "0 errors because we added a name."); + } + } + + public class Example : CfgNode { + [Cfg(required = true)] + public string Name { get; set; } + + [Cfg(required = true)] + public List Items { get; set; } + } + + public class ExampleItem : CfgNode { + [Cfg(minValue = 1, maxValue = 10)] + public int Value { get; set; } + } +} diff --git a/Cfg.Test/CustomProblems.cs b/Cfg.Test/CustomProblems.cs index 5d9205d..45da411 100644 --- a/Cfg.Test/CustomProblems.cs +++ b/Cfg.Test/CustomProblems.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/DifferentJsonParser.cs b/Cfg.Test/DifferentJsonParser.cs index bd6fb44..7591e23 100644 --- a/Cfg.Test/DifferentJsonParser.cs +++ b/Cfg.Test/DifferentJsonParser.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/DifferentXmlParser.cs b/Cfg.Test/DifferentXmlParser.cs index c9f2da2..f83a82b 100644 --- a/Cfg.Test/DifferentXmlParser.cs +++ b/Cfg.Test/DifferentXmlParser.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/Domain.cs b/Cfg.Test/Domain.cs index 10b3afc..46cb231 100644 --- a/Cfg.Test/Domain.cs +++ b/Cfg.Test/Domain.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -43,7 +44,7 @@ public void TestXml() { var problems = cfg.Errors(); Assert.AreEqual(1, problems.Length); - Assert.AreEqual("An invalid value of 'bad-value' is in the 'value' attribute. The valid domain is: good-value, another-good-value.", problems[0]); + Assert.AreEqual("An invalid value of bad-value is in value. The valid domain is: good-value, another-good-value.", problems[0]); } @@ -64,7 +65,7 @@ public void TestJson() { var problems = cfg.Errors(); Assert.AreEqual(1, problems.Length); - Assert.AreEqual("An invalid value of 'bad-value' is in the 'value' attribute. The valid domain is: good-value, another-good-value.", problems[0]); + Assert.AreEqual("An invalid value of bad-value is in value. The valid domain is: good-value, another-good-value.", problems[0]); } @@ -87,7 +88,7 @@ public void TestDifferentDomainDelimiter() { var problems = cfg.Errors(); Assert.AreEqual(1, problems.Length); - Assert.AreEqual("An invalid value of 'bad' is in the 'value' attribute. The valid domain is: GOOD, VALUE, ANOTHER, GOOD, VALUE.", problems[0]); + Assert.AreEqual("An invalid value of bad is in value. The valid domain is: GOOD, VALUE, ANOTHER, GOOD, VALUE.", problems[0]); } @@ -110,7 +111,7 @@ public void TestDomainAndToLower() { var problems = cfg.Errors(); Assert.AreEqual(1, problems.Length); - Assert.AreEqual("An invalid value of 'bad-value' is in the 'value' attribute. The valid domain is: good-value, another-good-value.", problems[0]); + Assert.AreEqual("An invalid value of bad-value is in value. The valid domain is: good-value, another-good-value.", problems[0]); } } diff --git a/Cfg.Test/ElementNameVariations.cs b/Cfg.Test/ElementNameVariations.cs index 033379a..e9a2ac2 100644 --- a/Cfg.Test/ElementNameVariations.cs +++ b/Cfg.Test/ElementNameVariations.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/EmptyLists.cs b/Cfg.Test/EmptyLists.cs index be33b44..0054e42 100644 --- a/Cfg.Test/EmptyLists.cs +++ b/Cfg.Test/EmptyLists.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -24,6 +25,32 @@ namespace Cfg.Test { [TestFixture] public class EmptyLists { + [Test] + public void ShouldBeInitialized() { + var cfg = new EmptyListCfg(); + Assert.IsNotNull(cfg.Connections); + Assert.AreEqual(0, cfg.Connections.Count); + Assert.IsNullOrEmpty(cfg.NullProperty); + Assert.IsNotNull(cfg.DefaultedProperty); + Assert.AreEqual("Default", cfg.DefaultedProperty); + } + + [Test] + public void ShouldRespectObjectInitialization() { + var cfg = new EmptyListCfg { + DefaultedProperty = "Set", + NullProperty = "Null", + Connections = new List { new EmptyListConnection() } + }; + + Assert.IsNotNull(cfg.Connections); + Assert.AreEqual(1, cfg.Connections.Count); + Assert.IsNotNull(cfg.NullProperty); + Assert.IsNotNull(cfg.DefaultedProperty); + Assert.AreEqual("Null", cfg.NullProperty); + Assert.AreEqual("Set", cfg.DefaultedProperty); + } + [Test] public void TestConnectionsXml() { var xml = @" @@ -97,10 +124,20 @@ public void TestOtherThingsJson() { } public sealed class EmptyListCfg : CfgNode { + + public EmptyListCfg() { + } + public EmptyListCfg(string xml) { Load(xml); } + [Cfg()] + public string NullProperty { get; set; } + + [Cfg(value = "Default")] + public string DefaultedProperty { get; set; } + [Cfg(required = false)] public List Connections { get; set; } diff --git a/Cfg.Test/FixIssue2.cs b/Cfg.Test/FixIssue2.cs index bf86b88..043608e 100644 --- a/Cfg.Test/FixIssue2.cs +++ b/Cfg.Test/FixIssue2.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -42,7 +43,7 @@ public void Test() { } Assert.AreEqual(1, cfg.Errors().Length); - Assert.IsTrue(cfg.Errors()[0] == "A 'test' element has an invalid 'things' element. If you need a 'things' element, decorate it with the Cfg attribute."); + Assert.IsTrue(cfg.Errors()[0] == "A test has an invalid things. If you need a things, decorate it with the [Cfg]."); } diff --git a/Cfg.Test/FreeFormData.cs b/Cfg.Test/FreeFormData.cs index 75a5c54..89038aa 100644 --- a/Cfg.Test/FreeFormData.cs +++ b/Cfg.Test/FreeFormData.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/Length.cs b/Cfg.Test/Length.cs index 498a415..fa203da 100644 --- a/Cfg.Test/Length.cs +++ b/Cfg.Test/Length.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -44,8 +45,8 @@ public void TestXml() { var problems = cfg.Errors(); Assert.AreEqual(2, problems.Length); - Assert.IsTrue(problems[0] == "The 'value' attribute value 'too-short' is too short. It is 9 characters. It must be at least 10 characters."); - Assert.IsTrue(problems[1] == "The 'value' attribute value 'this-is-way-too-long' is too long. It is 20 characters. It must not exceed 15 characters."); + Assert.IsTrue(problems[0] == "The value too-short is too short. It is 9 characters. It must be at least 10 characters."); + Assert.IsTrue(problems[1] == "The value this-is-way-too-long is too long. It is 20 characters. It must not exceed 15 characters."); } @@ -68,8 +69,8 @@ public void TestJson() { var problems = cfg.Errors(); Assert.AreEqual(2, problems.Length); - Assert.IsTrue(problems[0] == "The 'value' attribute value 'too-short' is too short. It is 9 characters. It must be at least 10 characters."); - Assert.IsTrue(problems[1] == "The 'value' attribute value 'this-is-way-too-long' is too long. It is 20 characters. It must not exceed 15 characters."); + Assert.IsTrue(problems[0] == "The value too-short is too short. It is 9 characters. It must be at least 10 characters."); + Assert.IsTrue(problems[1] == "The value this-is-way-too-long is too long. It is 20 characters. It must not exceed 15 characters."); } diff --git a/Cfg.Test/ListOfString.cs b/Cfg.Test/ListOfString.cs index eb1abd3..333619a 100644 --- a/Cfg.Test/ListOfString.cs +++ b/Cfg.Test/ListOfString.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/Main.cs b/Cfg.Test/Main.cs index 8994b9d..3c963ef 100644 --- a/Cfg.Test/Main.cs +++ b/Cfg.Test/Main.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,6 +20,7 @@ using System.Xml.Linq; using Cfg.Net; using Cfg.Net.Ext; +using Cfg.Net.Parsers; using Cfg.Test.TestClasses; using NUnit.Framework; @@ -31,14 +33,14 @@ public class Main { public void TestEmptyXmlCfg() { var cfg = new AttributeCfg(@""); Assert.AreEqual(1, cfg.Errors().Length); - Assert.AreEqual("A 'sites' element with at least one item is required in cfg.", cfg.Errors()[0]); + Assert.AreEqual("sites must be populated in cfg.", cfg.Errors()[0]); } [Test] public void TestEmptyJsonCfg() { var cfg = new AttributeCfg(@"{}"); Assert.AreEqual(1, cfg.Errors().Length); - Assert.AreEqual("A 'sites' element with at least one item is required.", cfg.Errors()[0]); + Assert.AreEqual("sites must be populated.", cfg.Errors()[0]); } [Test] @@ -48,7 +50,7 @@ public void TestGetDefaultOf() { Assert.IsNotNull(cfg.Sites); Assert.AreEqual(0, cfg.Sites.Count); - var sites = new AttributeSite().WithDefaults(); + var sites = new AttributeSite(); Assert.IsNotNull(sites); Assert.IsNotNull(sites.Something); } @@ -60,7 +62,7 @@ public void TestGetJsonDefaultOf() { Assert.IsNotNull(cfg.Sites); Assert.AreEqual(0, cfg.Sites.Count); - var sites = new AttributeSite().WithDefaults(); + var sites = new AttributeSite(); Assert.IsNotNull(sites); Assert.IsNotNull(sites.Something); } @@ -85,14 +87,14 @@ public void TestNewJson() { public void TestEmptySites() { var cfg = new AttributeCfg(@""); Assert.AreEqual(1, cfg.Errors().Length); - Assert.AreEqual("A 'sites' element with at least one item is required in cfg.", cfg.Errors()[0]); + Assert.AreEqual("sites must be populated in cfg.", cfg.Errors()[0]); } [Test] public void TestEmptyJsonSites() { var cfg = new AttributeCfg("{\"sites\":[]}"); Assert.AreEqual(1, cfg.Errors().Length); - Assert.AreEqual("A 'sites' element with at least one item is required.", cfg.Errors()[0]); + Assert.AreEqual("sites must be populated.", cfg.Errors()[0]); } [Test] @@ -112,8 +114,8 @@ public void TestInvalidProcess() { foreach (var problem in problems) { Console.WriteLine(problem); } - Assert.IsTrue(problems[0] == "A 'sites' 'add' element is missing a 'name' attribute."); - Assert.IsTrue(problems[1] == "A 'sites' 'add' element is missing a 'url' attribute."); + Assert.IsTrue(problems[0] == "A sites item is missing name."); + Assert.IsTrue(problems[1] == "A sites item is missing url."); } [Test] @@ -133,8 +135,8 @@ public void TestInvalidSiteAttribute() { } Assert.AreEqual(2, problems.Length); - Assert.AreEqual("A 'sites' 'add' element contains an invalid 'invalid' attribute. Valid attributes are: name, url, something, numeric, common.", problems[0]); - Assert.AreEqual("A 'sites' 'add' element is missing a 'url' attribute.", problems[1]); + Assert.AreEqual("A sites item contains an invalid invalid. It may only contain: name, url, something, numeric, common.", problems[0]); + Assert.AreEqual("A sites item is missing url.", problems[1]); } @@ -149,12 +151,14 @@ public void TestMultipleSites() { ".Replace("'", "\""); + var parser = new NanoXmlParser(); + var stopWatch = new Stopwatch(); stopWatch.Start(); - var cfg = new AttributeCfg(xml); + var x = parser.Parse(xml); stopWatch.Stop(); - Console.WriteLine("cfg.net load ms:" + stopWatch.ElapsedMilliseconds); + Console.WriteLine("nano load ms:" + stopWatch.ElapsedMilliseconds); stopWatch.Restart(); var doc = XDocument.Parse(xml); @@ -162,8 +166,10 @@ public void TestMultipleSites() { Console.WriteLine("xdoc parse ms:" + stopWatch.ElapsedMilliseconds); + Assert.IsNotNull(x); Assert.IsNotNull(doc); + var cfg = new AttributeCfg(xml); var problems = cfg.Errors(); foreach (var problem in problems) { @@ -171,8 +177,8 @@ public void TestMultipleSites() { } Assert.AreEqual(2, problems.Length); - Assert.AreEqual("Could not set 'numeric' to 'x' inside 'sites' 'add'. Input string was not in a correct format.", problems[0]); - Assert.AreEqual("Duplicate 'name' value 'github' in 'sites'.", problems[1]); + Assert.AreEqual("Could not set numeric to x inside sites item. Input string was not in a correct format.", problems[0]); + Assert.AreEqual("Duplicate name value github in sites.", problems[1]); Assert.AreEqual(4, cfg.Sites.Count); diff --git a/Cfg.Test/ModifierTest.cs b/Cfg.Test/ModifierTest.cs index 3d178fc..77de951 100644 --- a/Cfg.Test/ModifierTest.cs +++ b/Cfg.Test/ModifierTest.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/Parameters.cs b/Cfg.Test/Parameters.cs index 5f93388..7e8f98e 100644 --- a/Cfg.Test/Parameters.cs +++ b/Cfg.Test/Parameters.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/PassInLogger.cs b/Cfg.Test/PassInLogger.cs index 7b5e879..e8bd1ee 100644 --- a/Cfg.Test/PassInLogger.cs +++ b/Cfg.Test/PassInLogger.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/PreValidateTest.cs b/Cfg.Test/PreValidateTest.cs index 20038a9..748c8dc 100644 --- a/Cfg.Test/PreValidateTest.cs +++ b/Cfg.Test/PreValidateTest.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/Properties/AssemblyInfo.cs b/Cfg.Test/Properties/AssemblyInfo.cs index ce84b44..489dd21 100644 --- a/Cfg.Test/Properties/AssemblyInfo.cs +++ b/Cfg.Test/Properties/AssemblyInfo.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/PropertyManipulation.cs b/Cfg.Test/PropertyManipulation.cs index a3bbbb0..9dfc29f 100644 --- a/Cfg.Test/PropertyManipulation.cs +++ b/Cfg.Test/PropertyManipulation.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -38,7 +39,7 @@ public void TestXml() { var problems = cfg.Errors(); Assert.AreEqual(1, problems.Length); - Assert.AreEqual("An invalid value of 'System.Int16' is in the 'thing1' attribute. The valid domain is: int16.", problems[0]); + Assert.AreEqual("An invalid value of System.Int16 is in thing1. The valid domain is: int16.", problems[0]); Assert.AreEqual("System.Int16", cfg.Thing1); Assert.AreEqual("int16", cfg.Thing2); diff --git a/Cfg.Test/QueryStringTest.cs b/Cfg.Test/QueryStringTest.cs index 92ce8e4..c5868c2 100644 --- a/Cfg.Test/QueryStringTest.cs +++ b/Cfg.Test/QueryStringTest.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/ReadMe.cs b/Cfg.Test/ReadMe.cs index 021a19f..3dcfb73 100644 --- a/Cfg.Test/ReadMe.cs +++ b/Cfg.Test/ReadMe.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,11 +18,9 @@ using System; using System.Collections.Generic; using System.IO; -using System.Text.RegularExpressions; +using System.Linq; using System.Threading; using Cfg.Net; -using Cfg.Net.Contracts; -using Cfg.Net.Ext; using Cfg.Net.Parsers; using NUnit.Framework; @@ -169,8 +168,30 @@ public void NewTest() { } + [Test] + public void TestCode() { + + var cfg = new Cfg { + Fruit = new List { + new Fruit { + Name = "Apple", + Colors = new List { + new Color {Name = "red"}, + new Color {Name = "aqua"} + } + } + } + }; + + cfg.Check(); + + Assert.AreEqual(1, cfg.Errors().Length); + Assert.AreEqual("An invalid value of aqua is in name. The valid domain is: red, yellow, green, purple, blue, orange.", cfg.Errors().First()); + } } + + class Cfg : CfgNode { [Cfg(required = true)] // THERE MUST BE SOME FRUIT! public List Fruit { get; set; } diff --git a/Cfg.Test/ReadMeJson.cs b/Cfg.Test/ReadMeJson.cs index 75939d0..d307b48 100644 --- a/Cfg.Test/ReadMeJson.cs +++ b/Cfg.Test/ReadMeJson.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/ShorthandTest.cs b/Cfg.Test/ShorthandTest.cs index 2a3bf34..686620f 100644 --- a/Cfg.Test/ShorthandTest.cs +++ b/Cfg.Test/ShorthandTest.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/TestClasses/AttributeCfg.cs b/Cfg.Test/TestClasses/AttributeCfg.cs index f77af00..c578605 100644 --- a/Cfg.Test/TestClasses/AttributeCfg.cs +++ b/Cfg.Test/TestClasses/AttributeCfg.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/TestClasses/AttributeSite.cs b/Cfg.Test/TestClasses/AttributeSite.cs index e4f33df..f9b46cc 100644 --- a/Cfg.Test/TestClasses/AttributeSite.cs +++ b/Cfg.Test/TestClasses/AttributeSite.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/TestClasses/Cfg.cs b/Cfg.Test/TestClasses/Cfg.cs index b95f436..56d1a43 100644 --- a/Cfg.Test/TestClasses/Cfg.cs +++ b/Cfg.Test/TestClasses/Cfg.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/TestClasses/CfgDatabase.cs b/Cfg.Test/TestClasses/CfgDatabase.cs index 1d17d21..a2f6131 100644 --- a/Cfg.Test/TestClasses/CfgDatabase.cs +++ b/Cfg.Test/TestClasses/CfgDatabase.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/TestClasses/CfgEnvironment.cs b/Cfg.Test/TestClasses/CfgEnvironment.cs index 71b8d44..5719b2a 100644 --- a/Cfg.Test/TestClasses/CfgEnvironment.cs +++ b/Cfg.Test/TestClasses/CfgEnvironment.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/TestClasses/CfgParameter.cs b/Cfg.Test/TestClasses/CfgParameter.cs index d43491c..82c09ea 100644 --- a/Cfg.Test/TestClasses/CfgParameter.cs +++ b/Cfg.Test/TestClasses/CfgParameter.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/TestClasses/CfgServer.cs b/Cfg.Test/TestClasses/CfgServer.cs index bbe6a8a..51fc971 100644 --- a/Cfg.Test/TestClasses/CfgServer.cs +++ b/Cfg.Test/TestClasses/CfgServer.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/ToJson.cs b/Cfg.Test/ToJson.cs index 6671040..cb1e4dc 100644 --- a/Cfg.Test/ToJson.cs +++ b/Cfg.Test/ToJson.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/ToXml.cs b/Cfg.Test/ToXml.cs index 6336b34..d21f134 100644 --- a/Cfg.Test/ToXml.cs +++ b/Cfg.Test/ToXml.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/TraceLogger.cs b/Cfg.Test/TraceLogger.cs index 8f42dfe..589763b 100644 --- a/Cfg.Test/TraceLogger.cs +++ b/Cfg.Test/TraceLogger.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/Trim.cs b/Cfg.Test/Trim.cs index a44204f..e5072ed 100644 --- a/Cfg.Test/Trim.cs +++ b/Cfg.Test/Trim.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/Cfg.Test/ValidatorTest.cs b/Cfg.Test/ValidatorTest.cs index 3c9338b..7e395a1 100644 --- a/Cfg.Test/ValidatorTest.cs +++ b/Cfg.Test/ValidatorTest.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -18,7 +19,6 @@ using System.Collections.Generic; using Cfg.Net; using Cfg.Net.Contracts; -using Cfg.Net.Shared; using NUnit.Framework; namespace Cfg.Test { diff --git a/Cfg.Test/Value.cs b/Cfg.Test/Value.cs index 16972f5..2191258 100644 --- a/Cfg.Test/Value.cs +++ b/Cfg.Test/Value.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -45,10 +46,10 @@ public void TestXml() { var problems = cfg.Errors(); Assert.AreEqual(4, problems.Length); - Assert.IsTrue(problems[0] == "The 'value' attribute value '5' is too small. The minimum value allowed is '6'."); - Assert.IsTrue(problems[1] == "The 'longvalue' attribute value '5' is too small. The minimum value allowed is '6'."); - Assert.IsTrue(problems[2] == "The 'stringvalue' attribute value '6' is too big. The maximum value allowed is '5'."); - Assert.IsTrue(problems[3] == "The 'stringvalue' attribute value '\"10\"' is too small. The minimum value allowed is '1'."); + Assert.IsTrue(problems[0] == "The value value 5 is too small. The minimum value allowed is 6."); + Assert.IsTrue(problems[1] == "The longvalue value 5 is too small. The minimum value allowed is 6."); + Assert.IsTrue(problems[2] == "The stringvalue value 6 is too big. The maximum value allowed is 5."); + Assert.IsTrue(problems[3] == "The stringvalue value \"10\" is too small. The minimum value allowed is 1."); } @@ -71,9 +72,9 @@ public void TestJson() { var problems = cfg.Errors(); Assert.AreEqual(3, problems.Length); - Assert.IsTrue(problems[0] == "The 'value' attribute value '5' is too small. The minimum value allowed is '6'."); - Assert.IsTrue(problems[1] == "The 'longvalue' attribute value '5' is too small. The minimum value allowed is '6'."); - Assert.IsTrue(problems[2] == "The 'stringvalue' attribute value '6' is too big. The maximum value allowed is '5'."); + Assert.IsTrue(problems[0] == "The value value 5 is too small. The minimum value allowed is 6."); + Assert.IsTrue(problems[1] == "The longvalue value 5 is too small. The minimum value allowed is 6."); + Assert.IsTrue(problems[2] == "The stringvalue value 6 is too big. The maximum value allowed is 5."); } diff --git a/Cfg.Test/YamlDotNet.cs b/Cfg.Test/YamlDotNet.cs index 6f0a5e4..b8c00fe 100644 --- a/Cfg.Test/YamlDotNet.cs +++ b/Cfg.Test/YamlDotNet.cs @@ -1,13 +1,14 @@ #region license // Cfg.Net -// Copyright 2015 Dale Newman -// +// An Alternative .NET Configuration Handler +// Copyright 2015-2017 Dale Newman +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// +// +// http://www.apache.org/licenses/LICENSE-2.0 +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/README.md b/README.md index b153cb4..bee29f0 100644 --- a/README.md +++ b/README.md @@ -186,20 +186,15 @@ cfg.Load(xml); As your configuration loads: -1. Corresponding objects are created. -1. List properties are initialized. -1. `required` confirms a property value is input -1. Default `value` is applied as necessary -1. [`PreValidate()`](#PreValidate) is executed -1. `toLower` or `toUpper` may modify the value -1. `trim`, `trimStart`, or `trimEnd` may trim the value -1. `domain` checks value against valid values -1. `minLength` checks value against a minimum length -1. `maxLength` checks value against a maximum length -1. `minValue` checks value against a minimum value -1. `maxValue` checks value against a maximum value -1. `unique` confirms attributes are unique within a list -1. `required` confirms a list has items +1. `value` replaces `null` +1. [`PreValidate()`](#PreValidate) runs +1. `toLower` or `toUpper` modifies +1. `trim`, `trimStart`, or `trimEnd` trims +1. `domain` validates allowed values +1. `minLength` and `maxLength` validate length +1. `minValue` and `maxValue` validate range +1. `unique` confirms uniqueness within lists +1. `required` confirms things exist 1. [`Validate`](#Validate) is executed 1. [`PostValidate`](#PostValidate) is executed @@ -235,7 +230,7 @@ so they can fix them. Here are some example errors: Remove the required fruit and... -> A **fruit** element with at least one item is required in **cfg**. +> **fruit** must be populated in **cfg**. Add another apple and... @@ -243,7 +238,7 @@ Add another apple and... Add the color pink... -> An invalid value of **pink** is in the **name** attribute. The valid domain is: red, yellow, green, purple, blue, orange. +> An invalid value of **pink** is in **name**. The valid domain is: red, yellow, green, purple, blue, orange. If Cfg-NET doesn't report issues, your configuration is valid. You can loop through your fruits and their @@ -267,17 +262,16 @@ property is never `null`. Play with the apples and bananas on [.NET Fiddle](https://dotnetfiddle.net/slRAf3). -Validation and Modification +Customization --------------------------- The `Cfg` attribute's optional properties -offer *configurable* validation. -If it's not enough, you have 4 ways to extend: +offer simple validation. If it's not enough, +you have ways to extend: 1. Overriding `PreValidate()` 1. Overriding `Validate()` 1. Overriding `PostValidate()` -1. Injecting customizer(s) into a model's contructor ### PreValidate() @@ -337,11 +331,12 @@ protected override void PostValidate() { } ``` -### Injecting Customizers into Model's Contructor +### Customization -If you want to inject customizers into -Cfg-NET, an interface is defined for this. -Read more about injecting [here](https://github.com/dalenewman/Cfg-NET/blob/master/Articles/Autofac.md). +If the attributes and methods aren't enough, +you may inject customizers (e.g. things +implementing `ICustomizer`) into +your model's contructor. ### Serialize @@ -385,9 +380,33 @@ This produces a result of: ``` -**Note**: Modifying your configuration code doesn't -set defaults for or validate your newly added objects. Of course, -you can serialize and load again if that's what you want. +### Configure with Code and Check + +Loading configurations is great. However, sometimes +you need to write a configuration in code and *still* be +able to check it for errors and/or warnings. To do this, +just create your object however you like, and the run the +`Check` method. + +```csharp +var cfg = new Cfg { + Fruit = new List { + new Fruit { + Name = "Apple", + Colors = new List { + new Color {Name = "red"}, + new Color {Name = "aqua"} + } + } + } +}; + +// Instead of using Load(), use Check() +cfg.Check(); + +// I put an error in there on purpose (hint: aqua is invalid) +Assert.AreEqual(1, cfg.Errors().Length); +``` ### Credits * a modified version of `NanoXmlParser` found [here](http://www.codeproject.com/Tips/682245/NanoXML-Simple-and-fast-XML-parser). diff --git a/appveyor.yml b/appveyor.yml index d2d9b79..923bdd0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 0.9.0.{build} +version: 0.9.3.{build} before_build: - cmd: nuget restore build: