Esempio n. 1
0
        private static Dictionary <string, MemberInfo> GetMembersDictionary(ITypeInfo typeInfo)
        {
            Dictionary <string, MemberInfo> dictionary = new Dictionary <string, MemberInfo>(StringComparer.Ordinal);

            var members = typeInfo
                          .GetMembers()
                          .Where(IsValidMemberInfo)
                          .ToList();

            foreach (var member in members)
            {
                InternalSDKUtils.AddToDictionary(dictionary, member.Name, member);
            }

            return(dictionary);
        }
Esempio n. 2
0
        public static IEnumerable <IMemberInfo> GetAllMembers(this ITypeInfo typeInfo)
        {
            if (typeInfo == typeof(void))
            {
                yield break;
            }
            foreach (var item in typeInfo.GetMembers())
            {
                yield return(item);
            }
            var baseType = typeInfo.BaseTypeInfo;

            if (baseType != null && baseType != typeInfo)
            {
                foreach (var item in baseType.GetAllMembers())
                {
                    yield return(item);
                }
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
 public IEnumerable <IMemberInfo> GetMembers()
 {
     return(Info.GetMembers());
 }