Ejemplo n.º 1
0
        /// <summary>
        /// Load the mapping attributes for the specified type.
        /// </summary>
        /// <param name="assembly"></param>
        static RedisEntityMapping LoadMapping(Type type)
        {
            // Check if this mapping has already been loaded.
            if (!_mappings.ContainsKey(type))
            {
                object[] attributes = type.GetCustomAttributes(typeof(RedisEntityAttribute), false);
                if (attributes.Length > 0)
                {
                    RedisEntityAttribute attribute = attributes[0] as RedisEntityAttribute;

                    if (attribute == null || String.IsNullOrEmpty(attribute.BaseKey))
                    {
                        throw new Exception(String.Format("Cannot load mappings for type [{0}].", type.FullName));
                    }

                    _mappings.Add(type, new RedisEntityMapping(attribute, type));
                }
            }

            return(_mappings[type]);
        }
Ejemplo n.º 2
0
            public RedisEntityMapping(RedisEntityAttribute attribute, Type type)
            {
                this.PrimaryKey    = attribute.BaseKey;
                this.SecondaryKey  = attribute.SecondaryKey;
                this.KeyProperties = new List <RedisKeyMapping>();

                // Load all of the redis key/field property attributes.
                foreach (PropertyInfo property in type.GetProperties())
                {
                    object[] propertyAttrs = property.GetCustomAttributes(typeof(RedisKeyAttribute), true);
                    if (propertyAttrs.Length > 0)
                    {
                        this.KeyProperties.Add(new RedisKeyMapping(property, propertyAttrs[0] as RedisKeyAttribute));
                    }

                    propertyAttrs = property.GetCustomAttributes(typeof(RedisFieldAttribute), true);
                    if (propertyAttrs.Length > 0)
                    {
                        this.FieldProperty = new RedisFieldMapping(property, propertyAttrs[0] as RedisFieldAttribute);
                    }
                }
            }