示例#1
0
        public void Transform(Dictionary <string, object> dictionary = null, List <Type> allowedTransformers = null)
        {
            if (dictionary == null)
            {
                dictionary = new Dictionary <string, object>();
            }
            if (Attributes == null)
            {
                Attributes = new object[] { }
            }
            ;
            if (ParentListAttributes == null)
            {
                ParentListAttributes = new object[] { }
            }
            ;

            //lower case keys
            //Key = Key.ToLower();

            //find field settings
            var settings           = Attributes.Where(x => x.GetType() == typeof(IndexSettings));
            var parentListSettings = ParentListAttributes.Where(x => x.GetType() == typeof(IndexSettings));

            if (!settings.Any() && parentListSettings.Any())
            {
                settings = parentListSettings;
            }
            if (settings.Any())
            {
                var sattr = (IndexSettings)settings.First();
                KeepValueCasing   = !sattr.LowerCaseValue;
                Ignore            = sattr.Ignore;
                Spatial           = sattr.Spatial;
                FieldIndexSetting = sattr.FieldIndexSetting;
                FieldStoreSetting = sattr.FieldStoreSetting;
                if (sattr.Analyzer != null)
                {
                    if (sattr.Analyzer == typeof(SnowballAnalyzer))
                    {
                        Analyzer = new SnowballAnalyzer(Lucene.Net.Util.LuceneVersion.LUCENE_48, "English");
                    }
                    else
                    {
                        try
                        {
                            Analyzer = (Analyzer)Activator.CreateInstance(sattr.Analyzer, Lucene.Net.Util.LuceneVersion.LUCENE_48);
                        }
                        catch (MissingMethodException mmex) {
                            Analyzer = (Analyzer)Activator.CreateInstance(sattr.Analyzer);
                        }
                    }
                }
            }
            else
            {
                KeepValueCasing   = true;
                FieldIndexSetting = FieldSettings.FieldIndexSetting;
                FieldStoreSetting = FieldSettings.FieldStoreSetting;
            }

            //apply transforms
            var tattr = Attributes
                        .Where(x => x.GetType().GetInterfaces()
                               .Any(y => y.IsGenericType && y.GetGenericTypeDefinition() == typeof(I_Property_Transformer <,>))
                               ).ToList();

            OriginalValue = Value;
            var task = ObjectDumper.DoTransform(tattr, Type, Model, Key, UniqueKey, Value, dictionary, allowedTransformers: allowedTransformers);

            task.GetAwaiter().GetResult();
            Value = task.Result;
        }
    }