Exemplo n.º 1
0
        /// <summary>
        /// Creates an instance of the Template, attaches it to the Visual Tree, and calls "OnApplyTemplate". This method is intented to be called for ControlTemplates only (not DataTemplates).
        /// </summary>
        /// <param name="templateOwner">The owner of the template is the control to which the template is applied.</param>
        /// <returns>The instantiated control template.</returns>
        internal FrameworkElement INTERNAL_InstantiateAndAttachControlTemplate(Control templateOwner)
        {
            if (_methodToInstantiateFrameworkTemplate != null)
            {
                if (templateOwner != null)
                {
                    // Instantiate the ControlTemplate:
                    TemplateInstance templateInstance = _methodToInstantiateFrameworkTemplate(templateOwner);

                    // Attach it:
                    INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(templateInstance.TemplateContent, templateOwner);

                    // Raise the "OnApplyTemplate" property:
                    if (templateOwner != null)
                    {
                        templateOwner.RaiseOnApplyTemplate();
                    }
                    return(templateInstance.TemplateContent);
                }
                else
                {
                    throw new ArgumentNullException("templateOwner");
                }
            }
            else
            {
                throw new Exception("The FrameworkTemplate was not properly initialized.");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an instance of the Template, attaches it to the Visual Tree, and calls "OnApplyTemplate". This method is intented to be called for ControlTemplates only (not DataTemplates).
        /// </summary>
        /// <param name="templateOwner">The owner of the template is the control to which the template is applied.</param>
        /// <returns>The instantiated control template.</returns>
        internal FrameworkElement INTERNAL_InstantiateAndAttachControlTemplate(Control templateOwner)
        {
            if (templateOwner == null)
            {
                throw new ArgumentNullException("templateOwner");
            }

            templateOwner.INTERNAL_IsTemplated = true;

            if (_methodToInstantiateFrameworkTemplate != null)
            {
                // Instantiate the ControlTemplate:
                TemplateInstance templateInstance = _methodToInstantiateFrameworkTemplate(templateOwner);

                // Attach it:
#if REWORKLOADED
                templateOwner.AddVisualChild(templateInstance.TemplateContent);
#else
                INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(templateInstance.TemplateContent, templateOwner);
#endif

                // Raise the "OnApplyTemplate" property:
                if (templateOwner != null)
                {
                    templateOwner.RaiseOnApplyTemplate();
                }
                return(templateInstance.TemplateContent);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 3
0
        internal string ToHtml(TemplateInstance template)
        {
            string content = Content;

            foreach (var variable in template.vars)
            {
                content = content.Replace($"{{{variable.Key}}}", variable.Value.ToString());
            }

            return($"<meta name=\"{Html.Escape(Name)}\" content=\"{Html.Escape(content)}\" />");
        }
Exemplo n.º 4
0
        public void InitialiseTemplate(string name, EntityDefinition ent, TemplateInstance template, int firstTarget)
        {
            FieldName.Content = name;

            this.ent      = ent;
            this.template = template;

            this.firstTarget = firstTarget;
            ValueBox.Text    = template.GetParameter(firstTarget);

            ValueBox.TextChanged += Update;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Creates an instance of the Template.
 /// </summary>
 /// <param name="templateOwner">
 /// Owner of the template.
 /// Should be null if the template has no owner (for example,
 /// DataTemplate)
 /// </param>
 /// <returns></returns>
 internal FrameworkElement INTERNAL_InstantiateFrameworkTemplate(Control templateOwner)
 {
     if (_methodToInstantiateFrameworkTemplate != null)
     {
         TemplateInstance templateInstance = _methodToInstantiateFrameworkTemplate(templateOwner);
         return(templateInstance.TemplateContent);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates an instance of the Template. Intented to be called for templates that have no owner, such as DataTemplates (not ControlTemplates).
 /// </summary>
 /// <returns>The instantiated template.</returns>
 internal FrameworkElement INTERNAL_InstantiateFrameworkTemplate()
 {
     if (_methodToInstantiateFrameworkTemplate != null)
     {
         TemplateInstance templateInstance = _methodToInstantiateFrameworkTemplate(null); // We pass "null" in case of DataTemplate (unlike ControlTemplate), because there is no "templateOwner" for a DataTemplate.
         return(templateInstance.TemplateContent);
     }
     else
     {
         throw new Exception("The FrameworkTemplate was not properly initialized.");
     }
 }
Exemplo n.º 7
0
    public TemplateInstance CreateInstance()
    {
        // We want to move the object a bit forward of the menu
        Vector3          directionToMoveIn = (playerPosition.position - transform.position).normalized;
        Vector3          newPosition       = transform.position + (directionToMoveIn * 10);
        GameObject       instanceCreated   = Instantiate(instance.gameObject, newPosition, Quaternion.identity);
        TemplateInstance ti = instanceCreated.GetComponent <TemplateInstance>();

        ti.SetCreation(creation);
        ti.SetThumbnail(thumbnail);
        return(ti);
    }
Exemplo n.º 8
0
 //-----------------------------------------------------------------
 protected void OnTemplateEditChanged_UpdateObservers() //note: on edit changed.. component value is not taken into consideration
 {
     //note: can clear the _observersList, cause otherwise the _observersList elements are cloned from the template
     ObserversList.ForEach(x =>
     {
         TemplateInstance.CloneTo(x);
         x.IsInEditMode = false;
     });
     if (OnTemplateEditChanged != null)
     {
         OnTemplateEditChanged();
     }
 }
Exemplo n.º 9
0
            public UseContentTemplate()
            {
                SetMethodToInstantiateFrameworkTemplate(container =>
                {
                    TemplateInstance template = new TemplateInstance();

                    FrameworkElement root = ((ContentPresenter)container).Content as FrameworkElement;

                    template.TemplateContent = root;

                    return(template);
                });
            }
Exemplo n.º 10
0
            public UseContentTemplate()
            {
                this._methodToInstantiateFrameworkTemplate = owner =>
                {
                    TemplateInstance template = new TemplateInstance();

                    FrameworkElement root = ((ContentPresenter)owner).Content as FrameworkElement;

                    template.TemplateContent = root;

                    return(template);
                };
            }
Exemplo n.º 11
0
            public DefaultTemplate()
            {
                SetMethodToInstantiateFrameworkTemplate(container =>
                {
                    TemplateInstance template = new TemplateInstance();

                    ContentPresenter cp     = (ContentPresenter)container;
                    FrameworkElement result = DefaultExpansion(cp.Content, cp);

                    template.TemplateContent = result;

                    return(template);
                });
            }
        public void InitialiseTemplate(string name, EntityDefinition ent, TemplateInstance template, int firstTarget)
        {
            FieldName.Content = name;

            this.ent      = ent;
            this.template = template;

            this.firstTarget      = firstTarget;
            TextboxXPosition.Text = template.GetParameter(firstTarget);
            TextboxYPosition.Text = template.GetParameter(firstTarget + 1);

            UpdatePosition(null, null);

            TextboxXPosition.TextChanged += UpdatePosition;
            TextboxYPosition.TextChanged += UpdatePosition;
        }
Exemplo n.º 13
0
        public void TemplateComboBox_SelectionChanged(object sender, RoutedEventArgs e)
        {
            Template         template = GameState.GetLevel().Templates[TemplateComboBox.SelectedValue.ToString()];
            TemplateInstance instance = new TemplateInstance(template);

            entity.AddTemplate(instance);

            entity.ReloadTemplates();
            entity.ReloadMovement();

            TemplatePanel panel = new TemplatePanel(entity, instance);

            TemplatePanels.Children.Add(panel);

            entity.ForceNewPanel = true;
            GameState.Get().ReloadEntity(entity);
            GameState.Get().TextEditWindow.DrawLoadablePanels();
        }
Exemplo n.º 14
0
        internal static DataTemplate GetDataTemplateForDisplayMemberPath(string displayMemberPath)
        {
            DataTemplate template = new DataTemplate();

            template._methodToInstantiateFrameworkTemplate = control =>
            {
                TemplateInstance templateInstance = new TemplateInstance();

                TextBlock textBlock = new TextBlock();
                textBlock.SetBinding(TextBlock.TextProperty, new Binding(displayMemberPath ?? string.Empty));

                templateInstance.TemplateContent = textBlock;

                return(templateInstance);
            };

            return(template);
        }
Exemplo n.º 15
0
        static UserControl()
        {
            // UseContentTemplate
            ControlTemplate template = new ControlTemplate();

            template._methodToInstantiateFrameworkTemplate = (owner) =>
            {
                TemplateInstance instance = new TemplateInstance();

                instance.TemplateOwner   = owner;
                instance.TemplateContent = ((UserControl)owner).Content as FrameworkElement;

                return(instance);
            };
            template.Seal();

            UseContentTemplate = template;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Creates an instance of the Template, attaches it to the Visual Tree, and calls "OnApplyTemplate". This method is intented to be called for ControlTemplates only (not DataTemplates).
        /// </summary>
        /// <param name="templateOwner">The owner of the template is the control to which the template is applied.</param>
        /// <returns>The instantiated control template.</returns>
        internal FrameworkElement INTERNAL_InstantiateAndAttachControlTemplate(Control templateOwner)
        {
#if CSHTML5BLAZOR && DEBUG
            Console.WriteLine("OPEN SILVER DEBUG: FrameworkTemplate: INTERNAL_InstantiateAndAttachControlTemplate:" +
                              " template owner = " + templateOwner +
                              " template owner hash = " + (templateOwner != null ? templateOwner.GetHashCode().ToString() : ""));
#endif
            if (_methodToInstantiateFrameworkTemplate != null)
            {
                if (templateOwner != null)
                {
                    // Instantiate the ControlTemplate:
                    TemplateInstance templateInstance = _methodToInstantiateFrameworkTemplate(templateOwner);

                    // Attach it:
                    INTERNAL_VisualTreeManager.AttachVisualChildIfNotAlreadyAttached(templateInstance.TemplateContent, templateOwner);

                    // Raise the "OnApplyTemplate" property:
                    if (templateOwner != null)
                    {
                        templateOwner.RaiseOnApplyTemplate();
                    }
#if CSHTML5BLAZOR && DEBUG
                    else
                    {
                        Console.WriteLine("OPEN SILVER DEBUG: FrameworkTemplate: INTERNAL_InstantiateAndAttachControlTemplate: template owner is null");
                    }
#endif
                    return(templateInstance.TemplateContent);
                }
                else
                {
                    throw new ArgumentNullException("templateOwner");
                }
            }
            else
            {
                throw new Exception("The FrameworkTemplate was not properly initialized.");
            }
        }
Exemplo n.º 17
0
        public TemplatePanel(EntityDefinition entDef, TemplateInstance template)
        {
            InitializeComponent();

            Title.Content = template.Template.Name.Replace("_", "__").Substring(0, MAX_NAME_LENGTH);

            if (template.Template.ParameterNames is null)
            {
                return;
            }

            int templateIndex = 0;

            for (int i = 0; i < template.Template.ParameterNames.Count; i++)
            {
                ITemplateParameter templateParameterPanel = CreateTemplateParameterPanel(template.Template.ParameterTypes[i]);
                templateParameterPanel.InitialiseTemplate(template.Template.ParameterNames[i], entDef, template, templateIndex);
                TemplateStackPanel.Children.Add((UserControl)templateParameterPanel);

                templateIndex += templateParameterPanel.GetParameterCount();
            }
        }
Exemplo n.º 18
0
        //this allows us to generate a header to allow selection (and most importantly deselection) of elements in the Grid.
        private static TemplateInstance GenerateDefaultHeaderTemplateForExtendedSelectionMode(Control templateOwner = null) //The TemplateOwner parameter is made necessary by ControlTemplates but can be kept at null in DataTemplate.
        {
            TemplateInstance templateInstance = new TemplateInstance();

            templateInstance.TemplateOwner = templateOwner;
            Border border = new Border();

            border.HorizontalAlignment = HorizontalAlignment.Stretch;
            border.VerticalAlignment   = VerticalAlignment.Stretch;
            border.Background          = new SolidColorBrush(Colors.Gray);
            CheckBox checkbox = new CheckBox();

            checkbox.HorizontalAlignment = HorizontalAlignment.Center;
            checkbox.VerticalAlignment   = VerticalAlignment.Center;
            Binding b = new Binding("IsSelected");

            b.Mode = BindingMode.TwoWay;
            checkbox.SetBinding(CheckBox.IsCheckedProperty, b);
            border.Child = checkbox;
            templateInstance.TemplateContent = border;
            return(templateInstance);
        }
Exemplo n.º 19
0
        static ContentPresenter()
        {
            // Default template
            DataTemplate template = new DataTemplate();

            template._methodToInstantiateFrameworkTemplate = owner =>
            {
                TemplateInstance templateInstance = new TemplateInstance();

                TextBlock textBlock = new TextBlock();
                textBlock.SetBinding(TextBlock.TextProperty, new Binding(""));

                templateInstance.TemplateContent = textBlock;

                return(templateInstance);
            };
            template.Seal();
            _defaultTemplate = template;

            // Default template when content is UIElement.
            template = new UseContentTemplate();
            template.Seal();
            _uiElementTemplate = template;
        }
Exemplo n.º 20
0
 public virtual Expression VisitTemplateInstance(TemplateInstance templateInstance){
   if (templateInstance == null) return null;
   templateInstance.Expression = this.VisitExpression(templateInstance.Expression);
   templateInstance.TypeArguments = this.VisitTypeReferenceList(templateInstance.TypeArguments);
   return templateInstance;
 }
 /// <devdoc>
 /// </devdoc>
 public TemplateInstanceAttribute(TemplateInstance instances) {
     _instances = instances;
 }
Exemplo n.º 22
0
 public override Expression VisitTemplateInstance(TemplateInstance instance) {
   if (instance == null || instance.Expression == null) return null;
   if (instance.IsMethodTemplate) return instance;
   Member offendingMember = null;
   Literal lit = instance.Expression as Literal;
   if (lit != null) {
     offendingMember = lit.Value as Member;
   } else {
     MemberBinding mb = instance.Expression as MemberBinding;
     if (mb != null)
       offendingMember = mb.BoundMember;
     else {
       NameBinding nb = instance.Expression as NameBinding;
       if (nb != null) {
         for (int i = 0, n = nb.BoundMembers == null ? 0 : nb.BoundMembers.Count; i < n; i++) {
           Member mem = nb.BoundMembers[i];
           if (mem is Field || mem is TypeNode || mem is Event || 
             (mem is Property && (((Property)mem).Parameters == null || ((Property)mem).Parameters.Count == 0))) {
             offendingMember = mem; break;
           }
         }
       } else {
         MethodCall mc = instance.Expression as MethodCall; //Can happen when trying to apply type arguments to a property
         if (mc == null) return null;
         mb = mc.Callee as MemberBinding;
         if (mb != null && mb.BoundMember is Method) {
           Property p = ((Method)mb.BoundMember).DeclaringMember as Property;
           if (p != null) offendingMember = p;
         }
       }
     }
   }
   if (offendingMember == null) {
     this.HandleError(instance.Expression, Error.NotAType);
     return null;
   }
   TypeNode offendingType = offendingMember as TypeNode;
   if (offendingType != null) {
     if (offendingType.TemplateParameters == null || offendingType.TemplateParameters.Count == 0) {
       this.HandleError(instance.Expression, Error.NotATemplateType, this.GetTypeName(offendingType), "type");
       this.HandleRelatedError(offendingType);
     } else {
       //TODO: when does this happen?
       return null;
     }
     return null;
   }
   string offendingKind = this.ErrorHandler.GetMemberKind(offendingMember);
   this.HandleError(instance.Expression, Error.TypeArgsNotAllowed, offendingKind, this.GetMemberSignature(offendingMember));
   this.HandleRelatedError(offendingMember);
   return null;
 }
Exemplo n.º 23
0
 public string ToHtml(TemplateInstance template)
 {
     return(string.Join("\n", this.Select(i => i.ToHtml(template))));
 }
 // Constructors
 public TemplateInstanceAttribute(TemplateInstance instances)
 {
 }
Exemplo n.º 25
0
    public virtual Differences VisitTemplateInstance(TemplateInstance instance1, TemplateInstance instance2){
      Differences differences = new Differences(instance1, instance2);
      if (instance1 == null || instance2 == null){
        if (instance1 != instance2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      TemplateInstance changes = (TemplateInstance)instance2.Clone();
      TemplateInstance deletions = (TemplateInstance)instance2.Clone();
      TemplateInstance insertions = (TemplateInstance)instance2.Clone();

      Differences diff = this.VisitExpression(instance1.Expression, instance2.Expression);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Expression = diff.Changes as Expression;
      deletions.Expression = diff.Deletions as Expression;
      insertions.Expression = diff.Insertions as Expression;
      Debug.Assert(diff.Changes == changes.Expression && diff.Deletions == deletions.Expression && diff.Insertions == insertions.Expression);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      TypeNodeList typeChanges, typeDeletions, typeInsertions;
      diff = this.VisitTypeNodeList(instance1.TypeArguments, instance2.TypeArguments, out typeChanges, out typeDeletions, out typeInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.TypeArguments = typeChanges;
      deletions.TypeArguments = typeDeletions;
      insertions.TypeArguments = typeInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
Exemplo n.º 26
0
 public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_SingleOrg_ProgramMain_Works(TemplateInstance instance)
 => CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments, targetFramework: "netstandard2.1");
Exemplo n.º 27
0
 public virtual void VisitTemplateInstance(TemplateInstance templateInstance)
 {
   if (templateInstance == null) return;
   this.VisitExpression(templateInstance.Expression);
   this.VisitTypeReferenceList(templateInstance.TypeArguments);
 }
		public TemplateInstanceAttribute (TemplateInstance instance) {
			_instance = instance;
		}
Exemplo n.º 29
0
 public virtual TypeNode LookupType(TemplateInstance instance){
   if (instance == null) return null;
   if (instance.Expression == null) return null;
   int numArgs = instance.TypeArgumentExpressions == null ? 0 : instance.TypeArgumentExpressions.Count;
   TypeNode template = this.LookupType(instance.Expression, false, numArgs);
   if (template == null) return null;
   if (template.TemplateParameters == null || template.TemplateParameters.Count == 0){
     this.HandleError(instance.Expression, Error.NotATemplateType, this.GetTypeName(template), "type");
     this.HandleRelatedError(template);
     return null;
   }
   instance.TypeArguments = this.VisitTypeReferenceList(instance.TypeArguments);
   TypeNode result = template.GetTemplateInstance(this.currentModule, this.currentType, template.DeclaringType, instance.TypeArguments);
   this.AddTemplateInstanceToList(result);
   result.TemplateExpression = new TypeExpression(instance.Expression, instance.Expression.SourceContext);
   result.TemplateExpression.TemplateArgumentExpressions = instance.TypeArgumentExpressions;
   return result;
 }
Exemplo n.º 30
0
 public TemplateInstanceAttribute(TemplateInstance instance)
 {
     _instance = instance;
 }
Exemplo n.º 31
0
 public virtual Expression VisitTemplateInstance(TemplateInstance genericInstance1, TemplateInstance genericInstance2)
 {
     if (genericInstance1 == null) return null;
     if (genericInstance2 == null)
     {
         genericInstance1.Expression = this.VisitExpression(genericInstance1.Expression, null);
         genericInstance1.TypeArguments = this.VisitTypeReferenceList(genericInstance1.TypeArguments, null);
     }
     else
     {
         genericInstance1.Expression = this.VisitExpression(genericInstance1.Expression, genericInstance2.Expression);
         genericInstance1.TypeArguments = this.VisitTypeReferenceList(genericInstance1.TypeArguments, genericInstance2.TypeArguments);
     }
     return genericInstance1;
 }
Exemplo n.º 32
0
 public override Expression VisitTemplateInstance(TemplateInstance templateInstance){
   if (templateInstance == null) return null;
   int n = templateInstance.TypeArgumentExpressions == null ? 0 : templateInstance.TypeArgumentExpressions.Count;
   TypeNode template = this.LookupType(templateInstance.Expression, false, n);
   if (template == null)
     templateInstance.Expression = this.VisitExpression(templateInstance.Expression);
   templateInstance.TypeArguments = this.VisitTypeReferenceList(templateInstance.TypeArguments);
   this.AddNodePositionAndInfo(templateInstance.Expression, templateInstance, templateInstance.IsMethodTemplate ? IdentifierContexts.AllContext : IdentifierContexts.TypeContext);
   this.AddNodePositionAndInfo(templateInstance, templateInstance, templateInstance.IsMethodTemplate ? IdentifierContexts.AllContext : IdentifierContexts.TypeContext);
   if (template != null) {
     if (template.TemplateParameters != null && template.TemplateParameters.Count == n) {
       TypeNode instance = template.GetTemplateInstance(this.currentType, templateInstance.TypeArguments);
       this.AddTemplateInstanceToList(instance);
       return new Literal(instance, SystemTypes.Type, templateInstance.SourceContext);
     }
     templateInstance.Expression = new Literal(template, SystemTypes.Type, templateInstance.Expression.SourceContext);
   }
   return templateInstance;
 }
Exemplo n.º 33
0
 public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_Works(TemplateInstance instance)
 => CreateBuildPublishAsync(instance.Name, args: instance.Arguments, targetFramework: "netstandard2.1");
Exemplo n.º 34
0
 public Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_SingleOrg_NoHttps_ProgramMain_Works(TemplateInstance instance)
 => CreateBuildPublishAsync(auth: instance.Auth, args: instance.Arguments.Union(new[] { ArgConstants.NoHttps }).ToArray(), targetFramework: "netstandard2.1");
Exemplo n.º 35
0
 public override  Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations){
   if (localDeclarations == null) return null;
   this.AbstractSealedUsedAsType = Error.AbstractSealedLocalType;
   TypeNode type = localDeclarations.Type = this.VisitTypeReference(localDeclarations.Type, true);
   if (type == null){
     TypeExpression texpr = localDeclarations.TypeExpression as TypeExpression;
     if (texpr != null && texpr.ConsolidatedTemplateArguments != null && this.identifierInfos != null &&
       texpr.SourceContext.Document != null && texpr.SourceContext.Document.Text != null && texpr.SourceContext.EndPos == texpr.SourceContext.Document.Text.Length-1) {
       //Could be a call to a generic method.
       TemplateInstance ti = new TemplateInstance(texpr.Expression, texpr.ConsolidatedTemplateArguments);
       ti.SourceContext = texpr.SourceContext;
       ti.IsMethodTemplate = true;
       MethodCall mcall = new MethodCall(ti, new ExpressionList(0));
       mcall.SourceContext = texpr.SourceContext;
       return (Statement)this.Visit(new ExpressionStatement(mcall, mcall.SourceContext));
     }
   }
   this.AbstractSealedUsedAsType = Error.NotAType;
   LocalDeclarationList decls = localDeclarations.Declarations;
   int n = decls.Count;
   if (localDeclarations.Constant || localDeclarations.InitOnly){
     for (int i = 0; i < n; i++){
       LocalDeclaration decl = decls[i];
       if (decl == null) continue;
       decl = this.VisitLocalDeclaration(decl);
       Field f = decl.Field;
       if (f == null) continue;
       f.Type = type;
       f.Initializer = decl.InitialValue = this.VisitExpression(f.Initializer);
     }
     return localDeclarations;
   }else{
     StatementList statements = new StatementList(n+1);
     statements.Add(localDeclarations);
     for (int i = 0; i < n; i++){
       LocalDeclaration decl = decls[i];
       if (decl == null) continue;
       decl = this.VisitLocalDeclaration(decl);
       Field f = decl.Field;
       if (f == null) continue;
       f.Type = type;
       f.Initializer = null;
       MemberBinding mb = new MemberBinding(new ImplicitThis(this.scope, 0), f);
       mb.Type = type;
       mb.SourceContext = decl.Name.SourceContext;
       Expression initVal = decl.InitialValue = this.VisitExpression(decl.InitialValue);
       if (initVal == null) continue;
       AssignmentStatement aStat = new AssignmentStatement(mb, initVal, decl.AssignmentNodeType);
       aStat.SourceContext = localDeclarations.SourceContext;
       if (decl.SourceContext.Document != null) {
         aStat.SourceContext = decl.SourceContext;
         Debug.Assert(aStat.SourceContext.EndPos >= aStat.SourceContext.StartPos);
       }
       statements.Add(aStat);
     }
     Block b = new Block(statements);
     b.SourceContext = localDeclarations.SourceContext;
     return b;
   }
 }
Exemplo n.º 36
0
        public async Task BlazorWasmHostedTemplate_AzureActiveDirectoryTemplate_Works(TemplateInstance instance)
        {
            var project = await ProjectFactory.GetOrCreateProject(instance.Name, Output);

            project.TargetFramework = "netstandard2.1";

            var createResult = await project.RunDotNetNewAsync("blazorwasm", args : instance.Arguments);

            Assert.True(0 == createResult.ExitCode, ErrorMessages.GetFailedProcessMessage("create/restore", project, createResult));

            var publishResult = await project.RunDotNetPublishAsync();

            Assert.True(0 == publishResult.ExitCode, ErrorMessages.GetFailedProcessMessage("publish", project, publishResult));

            // Run dotnet build after publish. The reason is that one uses Config = Debug and the other uses Config = Release
            // The output from publish will go into bin/Release/netcoreappX.Y/publish and won't be affected by calling build
            // later, while the opposite is not true.

            var buildResult = await project.RunDotNetBuildAsync();

            Assert.True(0 == buildResult.ExitCode, ErrorMessages.GetFailedProcessMessage("build", project, buildResult));
        }
Exemplo n.º 37
0
 public virtual Expression VisitTemplateInstance(TemplateInstance instance, TemplateInstance changes, TemplateInstance deletions, TemplateInstance insertions){
   this.UpdateSourceContext(instance, changes);
   if (instance == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
     }
   }else if (deletions != null)
     return null;
   return instance;
 }
 public TemplateInstanceAttribute(TemplateInstance instances)
 {
     this._instances = instances;
 }
Exemplo n.º 39
0
 public override Expression VisitTemplateInstance(TemplateInstance instance){
   if (instance == null) return null;
   if (instance.IsMethodTemplate) return instance;
   return base.VisitTemplateInstance(instance);
 }
Exemplo n.º 40
0
 public override Expression VisitTemplateInstance(TemplateInstance templateInstance){
   if (templateInstance == null) return null;
   this.VisitResolvedTypeReferenceList(templateInstance.TypeArguments, templateInstance.TypeArgumentExpressions);
   return base.VisitTemplateInstance(templateInstance);
 }
Exemplo n.º 41
0
        /// <summary>
        /// Construct an instance of a ReflectedControlProperty, given the control for this property and the
        /// pre-reflected PropertyInfo for the property in question.
        /// </summary>
        /// <param name="reflectedControl">The control that owns this property.</param>
        /// <param name="propertyInfo">The pre-reflected PropertyInfo for this property.</param>
        public ReflectedControlProperty(ReflectedControl reflectedControl, PropertyInfo propertyInfo)
        {
            ReflectedControl = reflectedControl;
            PropertyInfo     = propertyInfo;


            var custAtts = CustomAttributeData.GetCustomAttributes(PropertyInfo).Where(a => a.AttributeType == typeof(System.Web.UI.PersistenceModeAttribute));

            if (custAtts.Any())
            {
                var parseAtt = custAtts.First();

                // public PersistenceModeAttribute(PersistenceMode mode);
                if (parseAtt.ConstructorArguments.Count == 1)
                {
                    PersistenceMode val = (PersistenceMode)parseAtt.ConstructorArguments[0].Value;
                    PersistenceModeAttribute = new System.Web.UI.PersistenceModeAttribute(val);
                    //public ParseChildrenAttribute();
                }
            }
            else
            {
                PersistenceModeAttribute = null;
            }



            //System.Web.UI.PersistenceModeAttribute[] persistenceModeAttributes = (System.Web.UI.PersistenceModeAttribute[])propertyInfo.GetCustomAttributes(typeof(System.Web.UI.PersistenceModeAttribute), true);
            //PersistenceModeAttribute = persistenceModeAttributes.Length == 0 ? null : persistenceModeAttributes[0];

            IsTemplateProperty   = typeof(System.Web.UI.ITemplate).IsAssignableFrom(PropertyInfo.PropertyType);
            IsCollectionProperty = typeof(IEnumerable).IsAssignableFrom(PropertyInfo.PropertyType) && !IsTemplateProperty;

            if (IsTemplateProperty)
            {
                var custTemplateInstanceAtts = CustomAttributeData.GetCustomAttributes(PropertyInfo).Where(a => a.AttributeType == typeof(System.Web.UI.TemplateInstanceAttribute));
                if (custTemplateInstanceAtts.Any())
                {
                    var parseAtt = custTemplateInstanceAtts.First();

                    // public TemplateInstanceAttribute(TemplateInstance instances);
                    if (parseAtt.ConstructorArguments.Count == 1)
                    {
                        TemplateInstance val = (TemplateInstance)parseAtt.ConstructorArguments[0].Value;
                        TemplateInstanceAttribute = new System.Web.UI.TemplateInstanceAttribute(val);
                        //public ParseChildrenAttribute();
                    }
                }
                else
                {
                    TemplateInstanceAttribute = null;
                }


                //System.Web.UI.TemplateInstanceAttribute[] templateInstanceAttributes = (System.Web.UI.TemplateInstanceAttribute[])propertyInfo.GetCustomAttributes(typeof(System.Web.UI.TemplateInstanceAttribute), true);
                //TemplateInstanceAttribute = templateInstanceAttributes.Length == 0 ? null : templateInstanceAttributes[0];


                var custTemplateContainerAtts = CustomAttributeData.GetCustomAttributes(PropertyInfo).Where(a => a.AttributeType == typeof(System.Web.UI.TemplateContainerAttribute));
                if (custTemplateContainerAtts.Any())
                {
                    var parseAtt = custTemplateContainerAtts.First();


                    if (parseAtt.ConstructorArguments.Count == 1)
                    {
                        // public TemplateContainerAttribute(Type containerType);
                        Type val = (Type)parseAtt.ConstructorArguments[0].Value;
                        TemplateContainerAttribute = new System.Web.UI.TemplateContainerAttribute(val);
                    }
                    else if (parseAtt.ConstructorArguments.Count == 2)
                    {
                        // public TemplateContainerAttribute(Type containerType, BindingDirection bindingDirection);
                        Type             val = (Type)parseAtt.ConstructorArguments[0].Value;
                        BindingDirection dir = (BindingDirection)parseAtt.ConstructorArguments[1].Value;
                        TemplateContainerAttribute = new System.Web.UI.TemplateContainerAttribute(val, dir);
                    }
                }
                else
                {
                    TemplateContainerAttribute = null;
                }

                //System.Web.UI.TemplateContainerAttribute[] templateContainerAttributes = (System.Web.UI.TemplateContainerAttribute[])propertyInfo.GetCustomAttributes(typeof(System.Web.UI.TemplateContainerAttribute), true);
                //TemplateContainerAttribute = templateContainerAttributes.Length == 0 ? null : templateContainerAttributes[0];
            }
            else if (IsCollectionProperty)
            {
                CollectionItemTypes = GetCollectionItemTypes(PropertyInfo.PropertyType);
            }
        }
Exemplo n.º 42
0
 protected virtual MemberList GetMembers(int line, int col, TemplateInstance templateInstance, Scope scope){
   if (templateInstance == null) return null;
   return this.FilterOutIncassessibleMembers(templateInstance.BoundMembers, scope);
 }