-
Notifications
You must be signed in to change notification settings - Fork 46
.NET projects
Sergey Zwezdin edited this page Jun 18, 2016
·
4 revisions
It's possible to use Magic Chunks in your .NET applications.
Steps to setup config transformations at .NET app:
Step 1: Install MagicChunks package from Nuget:
Install-Package MagicChunksStep 2: Create new instance of MagicChunks.Core.Transformer object:
using MagicChunks.Core;
var transformer = new Transformer();Step 3: Read source file and pass it together with transformations list to Transformer:
string result = transformer.Transform(File.ReadAllText(@"Web.config"),
new TransformationCollection
{
{"configuration/system.web/authentication/@mode", "Forms"},
{"configuration/system.web/httpRuntime", "125"}
});Step 4: Write result to output file.
There are few overloads for Transform method:
string Transform(source, transformations)string Transform(type, source, transformations)
TransformConfig alias parameters:
-
source− path to source file. -
type− document type handler implementingIDocumentinterface. There are three objects implements this iterface -XmlDocument,JsonDocument,YamlDocument(default value:auto- library will detect document type automatically). -
transformations− key-valued collection of transformations.
Return value of Transform method is transformed document.
You can find complete sample .net app here.