当前位置: 首页>>代码示例>>C#>>正文


C# IInternalContextAdapter类代码示例

本文整理汇总了C#中IInternalContextAdapter的典型用法代码示例。如果您正苦于以下问题:C# IInternalContextAdapter类的具体用法?C# IInternalContextAdapter怎么用?C# IInternalContextAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IInternalContextAdapter类属于命名空间,在下文中一共展示了IInternalContextAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Value

		/// <summary>
		/// Computes the result of the division. Currently limited to Integers.
		/// </summary>
		/// <returns>Integer(value) or null</returns>
		public override Object Value(IInternalContextAdapter context)
		{
			// get the two args
			Object left = GetChild(0).Value(context);
			Object right = GetChild(1).Value(context);

			// if either is null, lets log and bail
			if (left == null || right == null)
			{
				runtimeServices.Error(
					string.Format(
						"{0} side ({1}) of division operation has null value. Operation not possible. {2} [line {3}, column {4}]",
						(left == null ? "Left" : "Right"), GetChild((left == null ? 0 : 1)).Literal, context.CurrentTemplateName, Line,
						Column));
				return null;
			}

			Type maxType = MathUtil.ToMaxType(left.GetType(), right.GetType());
			if (maxType == null)
			{
				return null;
			}

			try
			{
				return MathUtil.Div(maxType, left, right);
			}
			catch (DivideByZeroException)
			{
				runtimeServices.Error("Right side of division operation is zero. Must be non-zero. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]");
			}
			return null;
		}
开发者ID:modulexcite,项目名称:Transformalize,代码行数:37,代码来源:ASTDivNode.cs

示例2: Evaluate

        public override bool Evaluate(IInternalContextAdapter context)
        {
            // get the two args
            Object left = GetChild(0).Value(context);
            Object right = GetChild(1).Value(context);

            // if either is null, lets log and bail
            if (left == null || right == null)
            {
                runtimeServices.Error(
                    string.Format(
                        "{0} side ({1}) of '>=' operation has null value. Operation not possible. {2} [line {3}, column {4}]",
                        (left == null ? "Left" : "Right"), GetChild((left == null ? 0 : 1)).Literal, context.CurrentTemplateName, Line,
                        Column));
                return false;
            }

            try
            {
                return ObjectComparer.CompareObjects(left, right) >= 0;
            }
            catch(ArgumentException ae)
            {
                runtimeServices.Error(ae.Message);

                return false;
            }
        }
开发者ID:rasmus-toftdahl-olesen,项目名称:NVelocity,代码行数:28,代码来源:ASTGENode.cs

示例3: Value

		/// <summary>
		/// Computes the sum of the two nodes.
		/// Currently only integer operations are supported.
		/// </summary>
		/// <returns>Integer object with value, or null</returns>
		public override Object Value(IInternalContextAdapter context)
		{
			// get the two addends
			Object left = GetChild(0).Value(context);
			Object right = GetChild(1).Value(context);

			// if either is null, lets log and bail
			if (left == null || right == null)
			{
				runtimeServices.Error(
					string.Format(
						"{0} side ({1}) of addition operation has null value. Operation not possible. {2} [line {3}, column {4}]",
						(left == null ? "Left" : "Right"), GetChild((left == null ? 0 : 1)).Literal, context.CurrentTemplateName, Line,
						Column));
				return null;
			}

			Type maxType = MathUtil.ToMaxType(left.GetType(), right.GetType());

			if (maxType == null)
			{
				return null;
			}

			return MathUtil.Add(maxType, left, right);

			// if not an Integer, not much we can do either
//			if (!(left is Int32) || !(right is Int32))
//			{
//				runtimeServices.Error((!(left is Int32) ? "Left" : "Right") + " side of addition operation is not a valid type. " + "Currently only integers (1,2,3...) and Integer type is supported. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]");
//
//				return null;
//			}
//			return ((Int32) left) + ((Int32) right);
		}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:40,代码来源:ASTAddNode.cs

示例4: Render

		public override bool Render(IInternalContextAdapter context, TextWriter writer, INode node)
		{
			if (node.ChildrenCount != 2)
			{
				throw new MonoRailException("#capturefor directive expects an id attribute and a template block");
			}

			var idNode = (ASTWord) node.GetChild(0);
			var bodyNode = (ASTBlock) node.GetChild(1);

			var id = idNode.Literal;

			var buffer = new StringWriter();
			var sb = buffer.GetStringBuilder();

			bodyNode.Render(context, buffer);

			var currentContent = context[id] as string;

			if( currentContent != null )
			{
				sb.Append(currentContent);
			}

			context[id] = sb.ToString();

			return true;
		}
开发者ID:smoothdeveloper,项目名称:Castle.MonoRail,代码行数:28,代码来源:CaptureForDirective.cs

示例5: Render

		public override bool Render(IInternalContextAdapter context, TextWriter writer)
		{
			// Check if the #if(expression) construct evaluates to true:
			// if so render and leave immediately because there
			// is nothing left to do!
			if (GetChild(0).Evaluate(context))
			{
				GetChild(1).Render(context, writer);
				return true;
			}

			int totalNodes = ChildrenCount;

			// Now check the remaining nodes left in the
			// if construct. The nodes are either elseif
			// nodes or else nodes. Each of these node
			// types knows how to evaluate themselves. If
			// a node evaluates to true then the node will
			// render itself and this method will return
			// as there is nothing left to do.
			for(int i = 2; i < totalNodes; i++)
			{
				if (GetChild(i).Evaluate(context))
				{
					GetChild(i).Render(context, writer);
					return true;
				}
			}

			// This is reached when an ASTIfStatement
			// consists of an if/elseif sequence where
			// none of the nodes evaluate to true.
			return true;
		}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:34,代码来源:ASTIfStatement.cs

示例6: Evaluate

		public override bool Evaluate(IInternalContextAdapter context)
		{
			// get the two args
			Object left = GetChild(0).Value(context);
			Object right = GetChild(1).Value(context);

			// if either is null, lets log and bail
			if (left == null || right == null)
			{
				rsvc.Error((left == null ? "Left" : "Right") + " side (" + GetChild((left == null ? 0 : 1)).Literal +
				           ") of '>' operation has null value." + " Operation not possible. " + context.CurrentTemplateName +
				           " [line " + Line + ", column " + Column + "]");
				return false;
			}

			try
			{
				return ObjectComparer.CompareObjects(left, right) == ObjectComparer.Greater;
			}
			catch(ArgumentException ae)
			{
				rsvc.Error(ae.Message);

				return false;
			}
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:26,代码来源:ASTGTNode.cs

示例7: Evaluate

		public override bool Evaluate(IInternalContextAdapter context)
		{
			if (GetChild(0).Evaluate(context))
				return false;
			else
				return true;
		}
开发者ID:ralescano,项目名称:castle,代码行数:7,代码来源:ASTNotNode.cs

示例8: Value

		/// <summary>
		/// Computes the value of the subtraction.
		/// Currently limited to integers.
		/// </summary>
		/// <returns>Integer(value) or null</returns>
		public override Object Value(IInternalContextAdapter context)
		{
			// get the two args
			Object left = GetChild(0).Value(context);
			Object right = GetChild(1).Value(context);

			// if either is null, lets log and bail
			if (left == null || right == null)
			{
				rsvc.Error((left == null ? "Left" : "Right") + " side (" + GetChild((left == null ? 0 : 1)).Literal +
				           ") of subtraction operation has null value." + " Operation not possible. " + context.CurrentTemplateName +
				           " [line " + Line + ", column " + Column + "]");
				return null;
			}

			Type maxType = MathUtil.ToMaxType(left.GetType(), right.GetType());

			if (maxType == null)
			{
				return null;
			}

			return MathUtil.Sub(maxType, left, right);

			// if not an Integer, not much we can do either
//			if (!(left is Int32) || !(right is Int32))
//			{
//				rsvc.Error((!(left is Int32) ? "Left" : "Right") + " side of subtraction operation is not a valid type. " + "Currently only integers (1,2,3...) and Integer type is supported. " + context.CurrentTemplateName + " [line " + Line + ", column " + Column + "]");
//
//				return null;
//			}
//
//			return ((Int32) left) - ((Int32) right);
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:39,代码来源:ASTSubtractNode.cs

示例9: Render

		/// <summary>   puts the value of the RHS into the context under the key of the LHS
		/// </summary>
		public override bool Render(IInternalContextAdapter context, TextWriter writer)
		{
			/*
	    *  get the RHS node, and it's value
	    */

			Object value = right.Value(context);

			/*
	    * it's an error if we don't have a value of some sort
	    */

			if (value == null)
			{
				/*
				*  first, are we supposed to say anything anyway?
				*/
				if (blather)
				{
					EventCartridge eventCartridge = context.EventCartridge;

					bool doIt = true;

					/*
		    *  if we have an EventCartridge...
		    */
					if (eventCartridge != null)
					{
						doIt = eventCartridge.ShouldLogOnNullSet(left.Literal, right.Literal);
					}

					if (doIt)
					{
						runtimeServices.Error(
							string.Format("RHS of #set statement is null. Context will not be modified. {0} [line {1}, column {2}]",
							              context.CurrentTemplateName, Line, Column));
					}
				}

				return false;
			}

			/*
	    *  if the LHS is simple, just punch the value into the context
	    *  otherwise, use the setValue() method do to it.
	    *  Maybe we should always use setValue()
	    */

			if (left.ChildrenCount == 0)
			{
				context.Put(leftReference, value);
			}
			else
			{
				left.SetValue(context, value);
			}

			return true;
		}
开发者ID:modulexcite,项目名称:Transformalize,代码行数:61,代码来源:ASTSetDirective.cs

示例10: Init

		/// <summary>
		/// How this directive is to be initialized.
		/// </summary>
		public virtual void Init(IRuntimeServices rs, IInternalContextAdapter context, INode node)
		{
			runtimeServices = rs;

//			int i, k = node.jjtGetNumChildren();
//			for (i = 0; i < k; i++)
//				node.jjtGetChild(i).init(context, rs);
		}
开发者ID:modulexcite,项目名称:Transformalize,代码行数:11,代码来源:Directive.cs

示例11: Init

		public override Object Init(IInternalContextAdapter context, Object data)
		{
			Token t = FirstToken;

			text = NodeUtils.tokenLiteral(t);

			return data;
		}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:8,代码来源:ASTText.cs

示例12: Init

		/// <summary>
		/// simple init - don't do anything that is context specific.
		/// just get what we need from the AST, which is static.
		/// </summary>
		public override Object Init(IInternalContextAdapter context, Object data)
		{
			base.Init(context, data);

			identifier = FirstToken.Image;

			uberInfo = new Info(context.CurrentTemplateName, Line, Column);
			return data;
		}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:13,代码来源:ASTIdentifier.cs

示例13: Init

		/// <summary>
		/// simple init - init our subtree and get what we can from
		/// the AST
		/// </summary>
		public override Object Init(IInternalContextAdapter context, Object data)
		{
			base.Init(context, data);

			methodName = FirstToken.Image;
			paramCount = ChildrenCount - 1;

			return data;
		}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:13,代码来源:ASTMethod.cs

示例14: Render

		public override bool Render(IInternalContextAdapter context, TextWriter writer)
		{
			int i, k = ChildrenCount;

			for(i = 0; i < k; i++)
				GetChild(i).Render(context, writer);

			return true;
		}
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:9,代码来源:ASTBlock.cs

示例15: Init

		/// <summary>  init : we don't have to do much.  Init the tree (there
		/// shouldn't be one) and then see if interpolation is turned on.
		/// </summary>
		public override Object Init(IInternalContextAdapter context, Object data)
		{
			base.Init(context, data);

			/*
			*  the stringlit is set at template parse time, so we can 
			*  do this here for now.  if things change and we can somehow 
			* create stringlits at runtime, this must
			*  move to the runtime execution path
			*
			*  so, only if interpolation is turned on AND it starts 
			*  with a " AND it has a  directive or reference, then we 
			*  can  interpolate.  Otherwise, don't bother.
			*/

			interpolate = FirstToken.Image.StartsWith("\"") &&
			              ((FirstToken.Image.IndexOf('$') != - 1) ||
			               (FirstToken.Image.IndexOf('#') != - 1));

			/*
			*  get the contents of the string, minus the '/" at each end
			*/

			image = FirstToken.Image.Substring(1, (FirstToken.Image.Length - 1) - (1));
			/*
			* tack a space on the end (dreaded <MORE> kludge)
			*/

			interpolateimage = image + " ";

			if (interpolate)
			{
				/*
				*  now parse and init the nodeTree
				*/
				TextReader br = new StringReader(interpolateimage);

				/*
				* it's possible to not have an initialization context - or we don't
				* want to trust the caller - so have a fallback value if so
				*
				*  Also, do *not* dump the VM namespace for this template
				*/

				nodeTree = rsvc.Parse(br, (context != null) ? context.CurrentTemplateName : "StringLiteral", false);

				/*
				*  init with context. It won't modify anything
				*/

				nodeTree.Init(context, rsvc);
			}

			return data;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:58,代码来源:ASTStringLiteral.cs


注:本文中的IInternalContextAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。