Exemplo n.º 1
0
 protected DictionaryDdbConverterBase(DdbConverter <TKey> keyConverter, DdbConverter <TValue> valueConverter)
 {
     KeyConverter           = keyConverter;
     ValueConverter         = valueConverter;
     KeyDictionaryConverter = keyConverter as IDictionaryKeyConverter <TKey> ??
                              throw new DdbException($"{KeyConverter.GetType().Name} must implement IDictionaryKeyConverter in order to store value as a dictionary key.");
 }
Exemplo n.º 2
0
 protected DictionaryDdbConverterBase(DynamoDbContextMetadata metadata)
 {
     KeyConverter           = metadata.GetOrAddConverter <TKey>();
     ValueConverter         = metadata.GetOrAddConverter <TValue>();
     KeyDictionaryConverter = KeyConverter as IDictionaryKeyConverter <TKey> ??
                              throw new DdbException($"{KeyConverter.GetType().Name} must implement IDictionaryKeyConverter in order to store value as a dictionary key.");
 }
Exemplo n.º 3
0
        public DdbPropertyInfo(PropertyInfo propertyInfo, string attributeName, DynamoDbAttributeType attributeType, DdbConverter <T> converter, DynamoDbContextMetadata metadata) : base(propertyInfo, attributeName, attributeType)
        {
            Converter = converter;

            Get = EmitMemberAccessor.CreatePropertyGetter <T>(propertyInfo);
            Set = propertyInfo.SetMethod != null?EmitMemberAccessor.CreatePropertySetter <T>(propertyInfo) : null;

            RuntimeClassInfo = metadata.GetOrAddClassInfo(propertyInfo.PropertyType, converter);
        }
Exemplo n.º 4
0
 public IReadOnlyCollectionDdbConverter(DdbConverter <T> elementConverter) : base(elementConverter)
 {
 }
Exemplo n.º 5
0
 protected DictionaryDdbConverter(DdbConverter <TKey> keyConverter, DdbConverter <TValue> valueConverter) : base(keyConverter, valueConverter)
 {
 }
Exemplo n.º 6
0
        public DdbClassInfo(Type type, DynamoDbContextMetadata metadata, DdbConverter converter)
        {
            Type = type;

            var properties     = new Dictionary <string, DdbPropertyInfo>();
            var jsonProperties = new JsonReaderDictionary <DdbPropertyInfo>();

            ConverterBase = converter;
            ConverterType = converter.GetType();
            ClassType     = ConverterBase.ClassType;

            switch (ClassType)
            {
            case DdbClassType.Object:
            {
                for (var currentType = type; currentType != null; currentType = currentType.BaseType)
                {
                    const BindingFlags bindingFlags =
                        BindingFlags.Instance |
                        BindingFlags.Public |
                        BindingFlags.NonPublic |
                        BindingFlags.DeclaredOnly;

                    foreach (PropertyInfo propertyInfo in currentType.GetProperties(bindingFlags))
                    {
                        var attribute = propertyInfo.GetCustomAttribute <DynamoDbPropertyAttribute>();
                        if (attribute == null)
                        {
                            continue;
                        }

                        if (properties.ContainsKey(attribute.Name))
                        {
                            continue;
                        }

                        var propertyConverter = metadata.GetOrAddConverter(propertyInfo.PropertyType, attribute.DdbConverterType);

                        var ddbPropertyInfo = propertyConverter.CreateDdbPropertyInfo(propertyInfo, attribute.Name, attribute.AttributeType, metadata);
                        properties.Add(attribute.Name, ddbPropertyInfo);
                        jsonProperties.Add(attribute.Name, ddbPropertyInfo);

                        switch (attribute.AttributeType)
                        {
                        case DynamoDbAttributeType.PartitionKey:
                            if (PartitionKey != null)
                            {
                                throw new DdbException($"An entity {Type.FullName} contains multiple partition key attributes");
                            }
                            PartitionKey = ddbPropertyInfo;
                            break;

                        case DynamoDbAttributeType.SortKey:
                            if (SortKey != null)
                            {
                                throw new DdbException($"An entity {Type.FullName} contains multiple sort key attributes");
                            }
                            SortKey = ddbPropertyInfo;
                            break;
                        }

                        if (Version == null && propertyInfo.GetCustomAttribute <DynamoDbVersionAttribute>() != null)
                        {
                            Version = ddbPropertyInfo;
                        }
                    }

                    TableName ??= currentType.GetCustomAttribute <DynamoDbTableAttribute>()?.TableName;
                }
                Constructor = EmitMemberAccessor.CreateConstructor(type) ?? throw new InvalidOperationException($"Can't generate constructor delegate for type '{type}'.");

                break;
            }

            case DdbClassType.Enumerable:
            case DdbClassType.Dictionary:
            {
                ElementType      = ConverterBase.ElementType;
                ElementClassInfo = metadata.GetOrAddClassInfo(ElementType !);
                break;
            }
            }


            AttributesMap  = properties;
            PropertiesMap  = properties.Values.ToDictionary(x => x.PropertyInfo.Name);
            JsonProperties = jsonProperties;
            Properties     = properties.Values.ToArray();
        }
Exemplo n.º 7
0
 protected JsonCollectionDdbConverter(DdbConverter <TElement> elementConverter)
 {
     ElementConverter = elementConverter;
 }
Exemplo n.º 8
0
 public IListDdbConverter(DdbConverter <T> elementConverter) : base(elementConverter)
 {
 }
Exemplo n.º 9
0
 protected SetDdbConverter(DynamoDbContextMetadata metadata)
 {
     ElementConverter         = metadata.GetOrAddConverter <TElement>();
     ElementSetValueConverter = ElementConverter as ISetValueConverter <TElement> ??
                                throw new DdbException($"{ElementConverter.GetType().Name} must implement ISetValueConverter in order to store value as a part of dynamodb set.");
 }
Exemplo n.º 10
0
 public NullableValueTypeDdbConverter(DdbConverter <T> converter) : base(true)
 {
     _converter = converter;
 }
 public JsonIReadOnlyListDdbConverter(DdbConverter <TValue> elementConverter) : base(elementConverter)
 {
 }
 public JsonIReadOnlyDictionaryDdbConverter(DynamoDbContextMetadata metadata)
 {
     _keyConverter  = metadata.GetOrAddConverter <TKey>();
     ValueConverter = metadata.GetOrAddConverter <TValue>();
 }
Exemplo n.º 13
0
 public JsonListHintDdbConverter(DdbConverter <T> elementConverter)
 {
     _elementConverter = elementConverter;
 }
 public JsonIReadOnlyListHintDdbConverter(DdbConverter <T> elementConverter)
 {
     _elementConverter = elementConverter;
 }
 public IReadOnlyListDdbConverter(DdbConverter <T> elementConverter) : base(elementConverter)
 {
 }
Exemplo n.º 16
0
 public ArrayDdbConverter(DdbConverter <T> elementConverter) : base(elementConverter)
 {
 }