<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[IntentSharp Engineering]]></title><description><![CDATA[IntentSharp Engineering]]></description><link>https://intentsharp.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 12 Nov 2026 07:57:47 GMT</lastBuildDate><atom:link href="https://intentsharp.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Compile and reuse .NET data mappings with IntentSharp]]></title><description><![CDATA[Run checked mappings in-process and reuse them across records. Verify provider-call counts with a runnable IntentSharp 1.0.0 example.]]></description><link>https://intentsharp.hashnode.dev/compile-and-reuse-net-data-mappings-with-intentsharp</link><guid isPermaLink="true">https://intentsharp.hashnode.dev/compile-and-reuse-net-data-mappings-with-intentsharp</guid><category><![CDATA[dotnet]]></category><category><![CDATA[c sharp]]></category><category><![CDATA[Artificial Intelligence]]></category><dc:creator><![CDATA[Michael Curtis]]></dc:creator><pubDate>Fri, 06 Nov 2026 17:46:56 GMT</pubDate><content:encoded><![CDATA[<p>A vendor feed calls a field <code>Code</code>. The application calls it <code>Id</code>. A display name arrives with padding that should be removed before it reaches the target record. The business meaning is simple, but the application still needs a precise, repeatable mapping.</p>
<p>IntentSharp can ask a model to propose that mapping as a set of defined operations, check it and reuse the compiled result for compatible inputs. The repeated work then runs inside the application without another model call.</p>
<p>I built IntentSharp at C2Consultants to let developers and coding agents express more of an application's intent, data definitions and mappings explicitly. Generating the initial plumbing is part of the goal. Keeping it understandable, detecting supported changes and repairing it through checked updates are equally useful parts.</p>
<p>This walkthrough isolates the runtime behavior with a scripted provider. It needs no model account, network call to a model service or provider key. The compilation and reuse path still runs through the real library. It does not measure a live model's ability to invent the mapping.</p>
<h2>Separate the mapping proposal from repeated execution</h2>
<p>For this example, the source record contains a code and display name. The target contains an identifier and normalized name. The intended operations are to copy one field and trim the other.</p>
<p>Both records are written explicitly so the example can be inspected. A coding agent can generate such declarations as part of building an application. The important boundary is that the resulting types and mapping have a defined contract that the runtime can check.</p>
<p>The scripted proposal uses the same mapping vocabulary that a live provider would be asked to produce. These steps are data describing supported operations. The runtime checks the proposal and then executes those operations in process.</p>
<h2>Create the sample</h2>
<p>Install the .NET 8 SDK, then create a console application and add the pinned package used here:</p>
<pre><code class="language-bash">dotnet new console --framework net8.0 -n MappingDemo
cd MappingDemo
dotnet add package IntentSharp --version 1.0.0
</code></pre>
<p>Replace <code>Program.cs</code> with this complete example:</p>
<pre><code class="language-csharp">using IntentSharp;
using IntentSharp.Mapping;
using IntentSharp.Testing;

var mapping = """
{"value":{"steps":[
  {"op":"copy","target":"/id","sources":["/code"]},
  {"op":"trim","target":"/name","sources":["/displayName"]}
]}}
""";

var provider = new ScriptedProvider(mapping);
using var client = new IntentClientBuilder()
    .UseProvider(provider)
    .WithMemory(null)
    .WithMappingStore(new InMemoryMappingStore(), "article-demo")
    .Build();

var options = new MappingOptions();
options.AddSample(new LegacyVendor("V-1", "  Acme  "), new Vendor("V-1", "Acme"));

var rows = new[]
{
    new LegacyVendor("V-2", "  Northwind  "),
    new LegacyVendor("V-3", "  Contoso  "),
    new LegacyVendor("V-4", "  Fabrikam  ")
};

foreach (var row in rows)
{
    var result = await client.MapByShapeAsync&lt;LegacyVendor, Vendor&gt;(
        row, "Copy Code to Id and trim DisplayName into Name.", options);

    if (!result.Success || result.Value != new Vendor(row.Code, row.DisplayName.Trim()))
        throw new InvalidOperationException("Mapping did not produce the expected vendor.");

    Console.WriteLine($"{result.Value.Id}: {result.Value.Name}; compiled={result.Compiled}; providerCalls={provider.CallCount}");
}

if (provider.CallCount != 1)
    throw new InvalidOperationException("Compatible rows should reuse the compiled mapping.");

Console.WriteLine("PASS: three mapped rows, one scripted compilation, no live model calls.");

public sealed record LegacyVendor(string Code, string DisplayName);
public sealed record Vendor(string Id, string Name);
</code></pre>
<p>Run it with <code>dotnet run</code>.</p>
<p>The golden sample declares an input and the exact output the mapping must produce. The three rows that follow use other values, so the example checks that the stored mapping is reusable beyond that initial sample.</p>
<p>The in-memory store makes this a small, self-contained demonstration. Its contents last for the life of the process. An application that needs persistence across restarts must supply an appropriate mapping store and protect its write access.</p>
<h2>Inspect what actually happened</h2>
<p>With .NET SDK 8.0.427 and IntentSharp 1.0.0, the sample produced:</p>
<pre><code class="language-text">V-2: Northwind; compiled=True; providerCalls=1
V-3: Contoso; compiled=False; providerCalls=1
V-4: Fabrikam; compiled=False; providerCalls=1
PASS: three mapped rows, one scripted compilation, no live model calls.
</code></pre>
<p>The first row compiled the mapping. The next two reused it, and the provider-call count stayed at one. The program also checks the resulting records and throws if the values or call count differ from what is expected.</p>
<p>Here, “one provider call” means one call to the in-process scripted provider. It is not a token-spend benchmark or a live-provider performance result. The useful observation is that compatible later rows did not request another mapping proposal.</p>
<h2>Check every result even when the mapping is reused</h2>
<p>The sample requires <code>Success</code> and the expected value before using a result. Production callers should preserve that boundary. A returned object should not become a business decision merely because a library method completed.</p>
<p>Golden samples help test the mapping's intended behavior during compilation. Output types and configured validators provide checks on returned values. These checks serve different purposes: a structurally valid result can still be wrong for the business.</p>
<p>For example, if two string fields can be swapped without breaking their types, the shape alone cannot identify the error. Distinct examples and business checks are needed to expose it. A successful check establishes that the configured checks passed, within their coverage.</p>
<h2>Make changes visible and repairable</h2>
<p>Reuse depends on more than the two record names. IntentSharp's mapping key includes the source and target shapes, intent, declarations, samples and other relevant compilation context. Changes to that context can lead to a new compilation.</p>
<p>There is also a recovery path for supported failures during reuse. The compiled-mapping guide documents a bounded replacement when a value no longer parses in the stored formats. A replacement must reproduce the declared golden samples. A value outside an explicitly allowed set fails rather than silently extending the set.</p>
<p>That distinction matters to self-healing. Repair should restore the intended behavior while retaining the contract that gives the application its meaning. Recompile limits and explicit failures keep a repair attempt from turning into an unlimited stream of model calls or an unnoticed change in what the application accepts.</p>
<p>The sample above verifies simple compilation and reuse. Date-format recovery and allowed-value failures are additional cases to test for a production mapping. They should be assessed using the actual formats, declarations and examples the application depends on.</p>
<h2>Apply the pattern where the work is structural</h2>
<p>Copying fields, trimming strings and applying declared conversions are good candidates for reusable mappings. Interpreting a new document or classifying free text may still require a model for each item. A system can use both kinds of work while making their costs and failure paths explicit.</p>
<p>The practical benefit is that a generated mapping can become a reusable execution artifact. It can carry its revision and provenance, run against new data, and return an explicit failure when its checks cannot establish an acceptable result. Developers and agents can then work on the change that actually needs attention.</p>
<p>For the full mapping contract, recovery behavior and store requirements, see the <a href="https://intentsharp.com/docs/guides/compiled-mappings">compiled-mapping guide</a>. The <a href="https://intentsharp.com/docs/quick-start?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=compiled_mappings">quick start</a> covers the broader runtime and versioned intent files.</p>
<p>IntentSharp is commercial software developed by my company, C2Consultants LLC. Review its <a href="https://intentsharp.com/pricing">current licensing terms</a> when evaluating it for business or production use.</p>
]]></content:encoded></item></channel></rss>