public PropertyInfo IdInfo(Type type)
        {
            ElasticTypeAttribute elasticTypeAttribute = ElasticAttributes.Type(type);

            if (elasticTypeAttribute != null && !string.IsNullOrWhiteSpace(elasticTypeAttribute.IdProperty))
            {
                return(this.GetPropertyCaseInsensitive(type, elasticTypeAttribute.IdProperty));
            }
            const string propertyName             = "Id";
            PropertyInfo propertyCaseInsensitive1 = this.GetPropertyCaseInsensitive(type, propertyName);

            if (propertyCaseInsensitive1 != (PropertyInfo)null)
            {
                return(propertyCaseInsensitive1);
            }
            PropertyInfo propertyCaseInsensitive2 = this.GetPropertyCaseInsensitive(type, type.Name + propertyName);

            if (propertyCaseInsensitive2 != (PropertyInfo)null)
            {
                return(propertyCaseInsensitive2);
            }
            PropertyInfo propertyCaseInsensitive3 = this.GetPropertyCaseInsensitive(type, type.Name + "_" + propertyName);

            if (propertyCaseInsensitive3 != (PropertyInfo)null)
            {
                return(propertyCaseInsensitive3);
            }
            else
            {
                return(propertyCaseInsensitive3);
            }
        }
Exemplo n.º 2
0
        public static ElasticTypeAttribute Type(Type type)
        {
            ElasticTypeAttribute attr = null;

            if (CachedTypeLookups.TryGetValue(type, out attr))
            {
                return(attr);
            }

            var attributes = type.GetCustomAttributes(typeof(ElasticTypeAttribute), true);

            if (attributes.HasAny())
            {
                attr = ((ElasticTypeAttribute)attributes.First());
            }
            CachedTypeLookups.TryAdd(type, attr);
            return(attr);
        }
Exemplo n.º 3
0
        private static ElasticTypeAttribute _Type(Type type)
        {
            ElasticTypeAttribute attr = null;

            if (CachedTypeLookups.TryGetValue(type, out attr))
            {
                return(attr);
            }

            if (!type.IsClass && !type.IsInterface)
            {
                throw new ArgumentException("Type is not a class or interface", "type");
            }

            var attributes = type.GetCustomAttributes(typeof(ElasticTypeAttribute), true);

            if (attributes.HasAny())
            {
                attr = ((ElasticTypeAttribute)attributes.First());
            }
            CachedTypeLookups.TryAdd(type, attr);
            return(attr);
        }