Esempio n. 1
0
        protected override object Create(MarkupExtensionParts parameter)
        {
            var type = DetermineType(parameter);

            var candidates = parameter.Arguments.Select(Get)
                             .ToArray();
            var constructor = DetermineConstructor(parameter, candidates, type);

            var members    = _members.Get(type);
            var evaluator  = new PropertyEvaluator(type, members.ToDictionary(x => x.Name), this);
            var dictionary = parameter.Properties.ToDictionary(x => x.Key, evaluator.Get);
            var arguments  = constructor.GetParameters()
                             .Select(x => x.ParameterType.GetTypeInfo())
                             .Zip(candidates, (info, evaluation) => evaluation.Get(info))
                             .ToArray();
            var activator = new ConstructedActivator(constructor, arguments);
            var context   = new MemberContext(constructor.ReflectedType.GetTypeInfo(), members);
            var extension = new ActivationContexts(_accessors, context, activator, _defaults)
                            .Get(dictionary)
                            .Get()
                            .AsValid <IMarkupExtension>();
            var result = extension.ProvideValue(new Provider(_provider, _services.Appending(parameter)
                                                             .ToArray()));

            return(result);
        }
        ActivationContextActivator Activator(ConstructorInfo constructor, ImmutableArray <IMember> members)
        {
            var activator = new Source(constructor).ToDelegate();
            var contexts  = new ActivationContexts(_accessors, members, activator);
            var defaults  = constructor.GetParameters()
                            .Where(x => x.IsOptional)
                            .Select(x => Pairs.Create(x.Name, x.DefaultValue))
                            .ToImmutableArray();
            var result = new ActivationContextActivator(contexts, defaults);

            return(result);
        }