public Result.IfSuccess <XamlModificationCollection> Visit(IBindingNode bindingNode, Parameters parameters, Context context)
        {
            var result = bindingNode.Visit(this, parameters, context);

            if (result)
            {
                return(Result.Success(new XamlModificationCollection(context.XamlModificationInfos, context.BindingRootTypes)));
            }

            return(Result.Error());
        }
Beispiel #2
0
        private static MemberBinding CreateBindingExpressions(
            IList <Expression> expressions,
            VaribalesCollection variables,
            IBindingNode binding,
            Expression ifNull)
        {
            switch (binding)
            {
            case MemberAssignmentNode memberAssignment:
            {
                var expression = CreateVariableExpressions(expressions, variables, memberAssignment.Nodes, ifNull);
                return(Expression.Bind(memberAssignment.Binding.Member, expression));
            }

            case MemberListBindingNode memberListBinding:
            {
                var memberInitCollection = new List <ElementInit>();
                foreach (var initializer in memberListBinding.Initializers)
                {
                    var args = new List <Expression>();
                    foreach (var argument in initializer.Arguments)
                    {
                        var expression = CreateVariableExpressions(expressions, variables, argument, ifNull);
                        args.Add(expression);
                    }

                    memberInitCollection.Add(Expression.ElementInit(initializer.ElementInit.AddMethod, args));
                }

                return(Expression.ListBind(memberListBinding.Binding.Member, memberInitCollection));
            }

            case MemberMemberBindingNode memberMemberBindingElement:
            {
                var m = memberMemberBindingElement.Bindings.Select(s =>
                                                                   CreateBindingExpressions(expressions, variables, s, ifNull));
                return(Expression.MemberBind(memberMemberBindingElement.MemberMemberBinding.Member, m));
            }

            default:
                throw new ArgumentOutOfRangeException($"{binding}");
            }
        }
Beispiel #3
0
        public Result.IfSuccess <IReadOnlyList <GeneratedBindingContainer> > Visit(IBindingNode bindingNode, Parameters parameters, Context context)
        {
            var result = bindingNode.Visit(this, parameters, context);

            if (result)
            {
                var generatedContainers = new List <GeneratedBindingContainer>();
                foreach (var bindingContainerInfo in context.BindingContainerInfos)
                {
                    var bindingContainerBaseType = this.typeResolver.GetType("Sundew.Xaml.Optimizations.BindingConnector`1");
                    context.ExternAliases.TryAdd(bindingContainerBaseType);
                    var sourceCode = $@"{GetNamespacesAndExternalAliases(this.bindingXamlPlatformInfo.DefaultUsingStatements, bindingContainerInfo.ExternalAliases)}

namespace {parameters.Namespace}
{{
    [global::System.CodeDom.Compiler.GeneratedCode(""Sundew.Xaml.Optimizations.Bindings"", ""{ToolVersion}"")]
    [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
    public class {bindingContainerInfo.BindingContainerType.TypeName} : {this.typeResolver.GetAliasQualifiedGenericType(bindingContainerBaseType, this.typeResolver.GetType(bindingContainerInfo.NamespaceQualifiedBindingRootType))}
    {{
        protected override void OnConnect()
        {{
{bindingContainerInfo.CodeBuilder}
        }}

        public override object ProvideValue(System.IServiceProvider serviceProvider)
        {{
            return new {bindingContainerInfo.BindingContainerType.TypeName}();
        }}
    }}
}}";
                    generatedContainers.Add(new GeneratedBindingContainer(parameters.OutputPath, bindingContainerInfo.BindingContainerType, sourceCode));
                }

                return(Result.Success((IReadOnlyList <GeneratedBindingContainer>)generatedContainers));
            }

            return(Result.Error());
        }
Beispiel #4
0
 public ReusableWatcherFactory(Binder <TContext> .BindingAction[] actions, IBindingNode <TContext> root)
 {
     _actions = actions;
     _root    = root;
 }
Beispiel #5
0
 public DefaultWatcherFactory(Binder <TContext> .BindingAction[] actions, IBindingNode <TContext> rootNode)
 {
     _actions  = actions;
     _rootNode = rootNode;
 }
 public void VisitUnknown(IBindingNode bindingNode, StringBuilder stringBuilder, int indent)
 {
     throw VisitException.Create(bindingNode, stringBuilder, indent);
 }
 public string Visit(IBindingNode bindingNode, StringBuilder stringBuilder, int indent)
 {
     stringBuilder ??= new StringBuilder();
     bindingNode.Visit(this, stringBuilder, indent);
     return(stringBuilder.ToString());
 }
Beispiel #8
0
 public void VisitUnknown(IBindingNode bindingNode, Parameters parameters, Context context)
 {
     throw VisitException.Create(bindingNode, parameters, context);
 }
 public CollectionBindingNode(int[] indexes, IBindingNode <TItem> itemNode)
 {
     Indexes  = indexes;
     ItemNode = itemNode;
 }