예제 #1
0
        public virtual void TemplateSetup()
        {
            // Let the Dll Know about uFrame Binding Specific Types
            uFrameBindingType.ObservablePropertyType = typeof(IObservableProperty);
            uFrameBindingType.UFGroupType            = typeof(UFGroup);
            uFrameBindingType.ICommandType           = typeof(ISignal);
            foreach (var property in Ctx.Data.Element.PersistedItems.OfType <ITypedItem>())
            {
                var type = InvertApplication.FindTypeByNameExternal(property.RelatedTypeName);
                if (type == null)
                {
                    continue;
                }

                Ctx.TryAddNamespace(type.Namespace);
            }

            if (Ctx.IsDesignerFile && Ctx.Data.BaseNode == null)
            {
                Ctx.SetBaseType(typeof(ViewBase));
            }
            // Add namespaces based on the types used for properties
            Ctx.AddIterator("ViewComponentProperty", _ => _.OutputsTo <ViewComponentNode>());
            // Add the iterators for template method/property
            if (Ctx.Data.BaseNode == null)
            {
                Ctx.AddIterator("ExecuteCommand",
                                _ => _.Element.InheritedCommandsWithLocal.Where(p => !p.HasArgument));
                Ctx.AddIterator("ExecuteCommandOverload", _ => _.Element.InheritedCommandsWithLocal);
                Ctx.AddIterator("ExecuteCommandWithArg",
                                _ =>
                                _.Element.InheritedCommandsWithLocal.Where(
                                    p => p.HasArgument && p.OutputCommand == null));
            }
            else
            {
                Ctx.AddIterator("ExecuteCommand",
                                _ => _.Element.LocalCommands.Where(p => !p.HasArgument));
                Ctx.AddIterator("ExecuteCommandOverload", _ => _.Element.LocalCommands);
                Ctx.AddIterator("ExecuteCommandWithArg",
                                _ =>
                                _.Element.LocalCommands.Where(
                                    p => p.HasArgument && p.OutputCommand == null));
            }

            Ctx.AddIterator("ResetProperty", _ => _.SceneProperties);
            Ctx.AddIterator("CalculateProperty", _ => _.SceneProperties);
            Ctx.AddIterator("GetPropertyObservable", _ => _.SceneProperties);
            Ctx.AddCondition("ViewModelProperty", _ => !_.IsDerivedOnly);
            Ctx.AddCondition("DefaultIdentifier", _ => !_.IsDerivedOnly);
            Ctx.AddCondition("ViewModelType", _ => !_.IsDerivedOnly);
            if (Ctx.IsDesignerFile)
            {
                return;
            }

            // For each binding lets do some magic
            foreach (var item in Ctx.Data.Bindings)
            {
                // Cast the source of our binding (ie: Property, Collection, Command..etc)
                var source = item.SourceItem as ITypedItem;
                if (source == null)
                {
                    continue;
                }

                // Grab the uFrame Binding Type
                var bindingType = item.BindingType;
                // Create the binding signature based on the Method Info
                bindingType.CreateBindingSignature(new CreateBindingSignatureParams(
                                                       Ctx.CurrentDeclaration, _ => source.RelatedTypeName.ToCodeReference(), Ctx.Data, source)
                {
                    Ctx = Ctx,
                    BindingsReference = item,
                    DontImplement     = true
                });
            }
        }