

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# コンバーター
<a name="converters"></a>

場合によっては、DynamoDB データベースの保存中または読み取り中にデータを変更または変換する必要があります。このようなシナリオでは、次のようなコードを使用して、[Amazon.DynamoDBv2.DataModel](https://docs.aws.amazon.com/sdkfornet1/latest/apidocs/html/N_Amazon_DynamoDBv2_DataModel.htm) 名前空間の [IPropertyConverter](https://docs.aws.amazon.com/sdkfornet1/latest/apidocs/html/T_Amazon_DynamoDBv2_DataModel_IPropertyConverter.htm) インターフェイスを使用できます。

```
   // Converts the null values of a string property to a valid string and vice versa.
    public class NullOrStringConverter : IPropertyConverter
    {
        // Called when creating the JSON / DynamoDB item from the model
        public DynamoDBEntry ToEntry(object value)
        {
            var entry = new Primitive
            {
                  value = new DynamoDBNull()
            };
            if(value != null)
            {
                  entry.Value = value.ToString();
            }
            return entry;
        }
       // Called when populating the model from the JSON / DynamoDB item
        public object FromEntry(DynamoDBEntry entry)
        {
            if(entry is DynamoDBNull)
            {
                  return string.Empty;
            }
            else
            {
                  return entry.ToString();
            }
        }
    }
```

モデルでのコンバーターの使用：

```
[DynamoDBTable(“AppLibrary")]
public class ProdApp
{
        . . .
 
        [DynamoDBProperty (typeof(NullOrString))]
        public string AppConfigId { get; set; }     
         . . . 
}
```