Esempio n. 1
0
        private static PythonEditorServices CreatePythonEditorServices(IServiceContainer site, MockComponentModel model)
        {
            var services = new PythonEditorServices(site);

            // We don't have a full composition service availabe, to this code emulates
            // ComponentModel.DefaultCompositionService.SatisfyImportsOnce(services)
            // *just* enough for PythonEditorServices.
            foreach (var field in services.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                if (!field.GetCustomAttributes().OfType <ImportAttribute>().Any())
                {
                    continue;
                }
                if (!field.FieldType.IsGenericType || field.FieldType.GetGenericTypeDefinition() != typeof(Lazy <>))
                {
                    field.SetValue(services, model.GetService(field.FieldType));
                }
                else
                {
                    var svcType = field.FieldType.GetGenericArguments()[0];
                    var svc     = model.GetService(svcType);
                    field.SetValue(
                        services,
                        Activator.CreateInstance(typeof(LazyComponentGetter <>).MakeGenericType(svcType), model)
                        );
                }
            }
            return(services);
        }
Esempio n. 2
0
 public LazyComponentGetter(MockComponentModel model) : base(() => (T)model.GetService(typeof(T)))
 {
 }