

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 변환기
<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; }     
         . . . 
}
```