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;
		}
		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;
		}
		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;
		}
 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
        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
        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
 protected abstract void Visit(ConditionNode node);
示例#8
0
 protected override void Visit(ConditionNode node)
 {
     throw new System.NotImplementedException();
 }
        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);
 }