Ejemplo n.º 1
0
        private static List <LuceneIndexModel> EntityToLuceneIndexModel <T>(T t, dynamic propertyGetDict, List <string> propertyList) where T : class
        {
            List <LuceneIndexModel> modelList = new List <LuceneIndexModel>();

            ReflectionGenericHelper.Foreach <T>((PropertyInfo propertyInfo) =>
            {
                if (propertyList == null || propertyList.IndexOf(propertyInfo.Name) < 0)
                {
                    object value = null;
                    if (propertyGetDict != null && propertyGetDict.ContainsKey(propertyInfo.Name))
                    {
                        value = propertyGetDict[propertyInfo.Name](t);
                    }
                    else
                    {
                        value = ReflectionHelper.GetPropertyValue(t, propertyInfo);
                    }
                    LuceneIndexTAttribute attribute = propertyInfo.GetCustomAttribute <LuceneIndexTAttribute>();
                    if (attribute != null)
                    {
                        LuceneIndexModel model = new LuceneIndexModel()
                        {
                            Name      = propertyInfo.Name,
                            Value     = value != null ? value.ToString() : "",
                            StoreEnum = GetIndexStoreEnum(attribute.StoreEnum),
                            IndexEnum = GetIndexIndexEnum(attribute.IndexEnum)
                        };
                        modelList.Add(model);
                    }
                }
            });

            return(modelList);
        }
Ejemplo n.º 2
0
        private static T DocumentToEntity <T>(Document document, dynamic propertySetDict) where T : class, new()
        {
            T t = ReflectionGenericHelper.New <T>();

            ReflectionGenericHelper.Foreach <T>((PropertyInfo propertyInfo) =>
            {
                LuceneIndexTAttribute attribute = propertyInfo.GetCustomAttribute <LuceneIndexTAttribute>();
                if (attribute != null)
                {
                    string field = document.Get(propertyInfo.Name);
                    if (!string.IsNullOrEmpty(field))
                    {
                        if (propertySetDict != null && propertySetDict.ContainsKey(propertyInfo.Name))
                        {
                            ReflectionGenericHelper.SetPropertyValue(propertySetDict[propertyInfo.Name], t, field, propertyInfo);
                        }
                        else
                        {
                            ReflectionHelper.SetPropertyValue(t, field, propertyInfo);
                        }
                    }
                }
            });

            return(t);
        }