コード例 #1
0
		public static Node GetPropertyValueNode(this string propertyAccessor)
		{
			string objectName = propertyAccessor.GetObjectName();
			var conditionNode = new ConditionNode(string.Format("{0}!=null", objectName));
			conditionNode.Nodes.Add(new ExpressionNode(propertyAccessor));
			return conditionNode;
		}
コード例 #2
0
		public static Node GetCreateUriSnippet(this string entity, bool isType)
		{
			if (isType)
			{
				entity = "typeof(" + entity + ")";
				return new ExpressionNode(entity + ".CreateUri()");
			}
			var nullCheck = new ConditionNode(entity.GetIsNotNullExpression());
			nullCheck.Nodes.Add(new ExpressionNode(entity + ".CreateUri()"));
			return nullCheck;
		}
コード例 #3
0
		public static Node GetSelectedSnippet(this string propertyAccessor, string currentSelectedState, string optionValue)
		{
			string propertyNullTest = propertyAccessor.GetObjectName().GetIsNotNullExpression();
			string currentSelectedValueTest = string.Format(@"(""{0}""!="""")", currentSelectedState);
			string propertyValueTest = string.Format("({0}==\"{1}\")", propertyAccessor, optionValue);
			// argh
			// if ((propertyNullTest)&&(propertyValueTest))||(currentSelectedValueTest))
			string conidtion = string.Format("({0}&&{1})||{2}",
			                                 propertyNullTest, propertyValueTest, currentSelectedValueTest);
			var node = new ConditionNode(conidtion);
			node.Nodes.Add(new TextNode("true"));
			return node;
		}
コード例 #4
0
 private void AddCheckedAttribute(ElementNode elementNode, AttributeNode valueNode)
 {
     if (valueNode != null)
     {
         string entity = valueNode.Value.Split('.').First();
         string code = string.Format("({0}!= null)&&({1})", entity, valueNode.Value);
         ConditionNode conditionNode = new ConditionNode(code)
                                       	{
                                       		Nodes = new List<Node>()
                                       		        	{
                                       		        		new TextNode("true")
                                       		        	}
                                       	};
         elementNode.Attributes.Add(new AttributeNode("checked",
                                    		new List<Node>{conditionNode}
                                    	));
     }
 }
コード例 #5
0
ファイル: ChunkBuilderVisitor.cs プロジェクト: otac0n/spark
        private static void MovePriorNodesUnderCondition(ConditionNode condition, ICollection<Node> priorNodes)
        {
            while (priorNodes.Count != 0)
            {
                var priorNode = priorNodes.Last();
                priorNodes.Remove(priorNode);
                if (!(priorNode is TextNode))
                {
                    condition.Nodes.Insert(0, priorNode);
                    continue;
                }

                // for text, extend back to and include the last whitespace
                var priorText = ((TextNode)priorNode).Text;
                var finalPieceIndex = priorText.LastIndexOfAny(new[] { ' ', '\t', '\r', '\n' }) + 1;
                if (finalPieceIndex == 0)
                {
                    condition.Nodes.Insert(0, priorNode);
                    continue;
                }

                while (finalPieceIndex != 0 && char.IsWhiteSpace(priorText[finalPieceIndex - 1]))
                    --finalPieceIndex;

                condition.Nodes.Insert(0, new TextNode(priorText.Substring(finalPieceIndex)) { OriginalNode = priorNode });
                if (finalPieceIndex != 0)
                {
                    priorNodes.Add(new TextNode(priorText.Substring(0, finalPieceIndex)) { OriginalNode = priorNode });
                }

                return;
            }
        }
コード例 #6
0
ファイル: ChunkBuilderVisitor.cs プロジェクト: otac0n/spark
        protected override void Visit(ConditionNode conditionNode)
        {
            var conditionChunk = new ConditionalChunk
                                     {
                                         Condition = conditionNode.Code,
                                         Type = ConditionalType.If,
                                         Position = Locate(conditionNode)
                                     };
            Chunks.Add(conditionChunk);

            if (_sendAttributeOnce != null)
                conditionChunk.Body.Add(_sendAttributeOnce);
            if (_sendAttributeIncrement != null)
                conditionChunk.Body.Add(_sendAttributeIncrement);

            using (new Frame(this, conditionChunk.Body))
            {
                Accept(conditionNode.Nodes);
            }
        }
コード例 #7
0
ファイル: AbstractNodeVisitor.cs プロジェクト: Eilon/spark
 protected abstract void Visit(ConditionNode node);
コード例 #8
0
ファイル: TestElseElementVisitor.cs プロジェクト: Eilon/spark
 protected override void Visit(ConditionNode node)
 {
     throw new System.NotImplementedException();
 }
コード例 #9
0
        private void Transform(ElementNode node, IList<Node> body)
        {
            AttributeNode forAttribute = node.GetAttribute("for");
            AttributeNode forType = node.GetAttribute("fortype");
            AttributeNode forProperty = node.GetAttribute("forproperty");

            if(forAttribute!=null)
            {
                // put in as content property
                node.Attributes.Remove(forAttribute);
                node.RemoveAttributesByName("name");
                node.RemoveAttributesByName("value");
                var nameNode = new ExpressionNode(forAttribute.Value.GetPropertyNameSnippet());

                var valueNode = new ConditionNode("resource!=null")
                                     	{
                                     		Nodes = new List<Node>()
                                     		        	{
                                     		        		new ExpressionNode(forAttribute.Value)
                                     		        	}
                                     	};
                 SetNodeNameAndValue(node, valueNode, nameNode, body, forAttribute);
            }
            else if(forType!=null)
            {
                if(forProperty==null)
                {
                    throw new Exception("Must have both a forProperty attribute if using the forType attribute.");
                }
                node.Attributes.Remove(forType);
                node.Attributes.Remove(forProperty);
                node.RemoveAttributesByName("name");
                 SetNodeNameAndValue(node, null, new TextNode(string.Concat(forType.Value, ".", forProperty.Value)), body, forAttribute);
            }
        }
 private void GivenAnExpressionNode(ConditionNode node)
 {
     Context.Target = new SparkConditionNodeWrapper(node);
 }