Generated Code¶
The generator emits explicit ToItem/FromItem implementations that call the runtime extension methods. The example below is a real-world output.
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
#nullable enable
using DynamoMapper.Runtime;
using System.Collections.Generic;
using Amazon.DynamoDBv2.Model;
namespace Trivia.Manager.Shared.Models;
internal static partial class DuplicateResultMapper
{
[global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "1.0.0.0")]
internal static partial global::System.Collections.Generic.Dictionary<string, global::Amazon.DynamoDBv2.Model.AttributeValue> ToItem(global::Trivia.Manager.Shared.Models.DuplicateResult duplicateResult) =>
new Dictionary<string, AttributeValue>(2)
.SetString("id", duplicateResult.Id, false, true)
.Set("score", ScoreToAttribute(duplicateResult));
[global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "1.0.0.0")]
internal static partial global::Trivia.Manager.Shared.Models.DuplicateResult FromItem(global::System.Collections.Generic.Dictionary<string, global::Amazon.DynamoDBv2.Model.AttributeValue> item)
{
var duplicateResult = new global::Trivia.Manager.Shared.Models.DuplicateResult
{
Id = item.GetString("id", Requiredness.InferFromNullability),
Score = item.GetFloat("score", Requiredness.InferFromNullability),
};
return duplicateResult;
}
}
Notes: - Generated code uses SetX/GetX helpers from DynamoMapper.Runtime. - Class-level [DynamoField]/[DynamoIgnore] configuration influences argument values.
Constructor-Based FromItem¶
If your model type uses a constructor (records, get-only properties, or an explicitly attributed constructor), DynamoMapper will generate FromItem with constructor arguments.
See Basic Mapping for the full constructor selection rules and gotchas.
[global::System.CodeDom.Compiler.GeneratedCode("DynamoMapper", "REPLACED")]
public static partial global::MyNamespace.Product FromItem(
global::System.Collections.Generic.Dictionary<string, global::Amazon.DynamoDBv2.Model.AttributeValue> item
)
{
var product = new global::MyNamespace.Product(
Id: item.GetString("id", Requiredness.InferFromNullability),
Name: item.GetString("name", Requiredness.InferFromNullability)
)
{
Price = item.GetDecimal("price", Requiredness.InferFromNullability),
Quantity = item.GetInt("quantity", Requiredness.InferFromNullability),
};
return product;
}