

As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.

# Conversores
<a name="converters"></a>

Em alguns casos, talvez seja necessário modificar ou transformar dados ao salvar ou ler o banco de dados do DynamoDB. Nesses cenários, você pode usar a interface [IPropertyConverter](https://docs.aws.amazon.com/sdkfornet1/latest/apidocs/html/T_Amazon_DynamoDBv2_DataModel_IPropertyConverter.htm) do [DBv2Amazon.Dynamo. DataModel](https://docs.aws.amazon.com/sdkfornet1/latest/apidocs/html/N_Amazon_DynamoDBv2_DataModel.htm)namespace, usando um código semelhante ao seguinte:

```
   // 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();
            }
        }
    }
```

Uso do conversor no modelo:

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