private static void PopulateConfigFromType(ItemStorageConfig config, ITypeInfo typeInfo)
{
DynamoDBTableAttribute tableAttribute = Utils.GetTableAttribute(typeInfo);
if (tableAttribute == null)
{
config.TableName = typeInfo.Name;
}
else
{
if (string.IsNullOrEmpty(tableAttribute.TableName))
{
throw new InvalidOperationException("DynamoDBTableAttribute.Table is empty or null");
}
config.TableName = tableAttribute.TableName;
config.LowerCamelCaseProperties = tableAttribute.LowerCamelCaseProperties;
}
string tableAlias;
if (AWSConfigsDynamoDB.Context.TableAliases.TryGetValue(config.TableName, out tableAlias))
{
config.TableName = tableAlias;
}
foreach (var member in typeInfo.GetMembers())
{
if (!StorageConfig.IsValidMemberInfo(member))
{
continue;
}
// prepare basic info
PropertyStorage propertyStorage = new PropertyStorage(member);
propertyStorage.AttributeName = GetAccurateCase(config, member.Name);
// run through all DDB attributes
List <DynamoDBAttribute> allAttributes = Utils.GetAttributes(member);
foreach (var attribute in allAttributes)
{
// filter out ignored properties
if (attribute is DynamoDBIgnoreAttribute)
{
propertyStorage.IsIgnored = true;
}
if (attribute is DynamoDBVersionAttribute)
{
propertyStorage.IsVersion = true;
}
DynamoDBPropertyAttribute propertyAttribute = attribute as DynamoDBPropertyAttribute;
if (propertyAttribute != null)
{
if (!string.IsNullOrEmpty(propertyAttribute.AttributeName))
{
propertyStorage.AttributeName = GetAccurateCase(config, propertyAttribute.AttributeName);
}
if (propertyAttribute.Converter != null)
{
propertyStorage.ConverterType = propertyAttribute.Converter;
}
if (propertyAttribute is DynamoDBHashKeyAttribute)
{
var gsiHashAttribute = propertyAttribute as DynamoDBGlobalSecondaryIndexHashKeyAttribute;
if (gsiHashAttribute != null)
{
propertyStorage.IsGSIHashKey = true;
propertyStorage.AddIndex(gsiHashAttribute);
}
else
{
propertyStorage.IsHashKey = true;
}
}
if (propertyAttribute is DynamoDBRangeKeyAttribute)
{
var gsiRangeAttribute = propertyAttribute as DynamoDBGlobalSecondaryIndexRangeKeyAttribute;
if (gsiRangeAttribute != null)
{
propertyStorage.IsGSIRangeKey = true;
propertyStorage.AddIndex(gsiRangeAttribute);
}
else
{
propertyStorage.IsRangeKey = true;
}
}
DynamoDBLocalSecondaryIndexRangeKeyAttribute lsiRangeKeyAttribute = propertyAttribute as DynamoDBLocalSecondaryIndexRangeKeyAttribute;
if (lsiRangeKeyAttribute != null)
{
propertyStorage.IsLSIRangeKey = true;
propertyStorage.AddIndex(lsiRangeKeyAttribute);
}
}
}
config.Properties.Add(propertyStorage);
}
}