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


C# ControlBuilder.GetNextLocalVariableName方法代码示例

本文整理汇总了C#中System.Web.UI.ControlBuilder.GetNextLocalVariableName方法的典型用法代码示例。如果您正苦于以下问题:C# ControlBuilder.GetNextLocalVariableName方法的具体用法?C# ControlBuilder.GetNextLocalVariableName怎么用?C# ControlBuilder.GetNextLocalVariableName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.UI.ControlBuilder的用法示例。


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

示例1: AddChildCall

		protected void AddChildCall (ControlBuilder parent, ControlBuilder child)
		{
			if (parent == null || child == null)
				return;

			CodeStatementCollection methodStatements = parent.MethodStatements;
			CodeMethodReferenceExpression m = new CodeMethodReferenceExpression (thisRef, child.Method.Name);
			CodeMethodInvokeExpression expr = new CodeMethodInvokeExpression (m);

			object [] atts = null;

			if (child.ControlType != null)
				atts = child.ControlType.GetCustomAttributes (typeof (PartialCachingAttribute), true);
			
			if (atts != null && atts.Length > 0) {
				PartialCachingAttribute pca = (PartialCachingAttribute) atts [0];
				CodeTypeReferenceExpression cc = new CodeTypeReferenceExpression("System.Web.UI.StaticPartialCachingControl");
				CodeMethodInvokeExpression build = new CodeMethodInvokeExpression (cc, "BuildCachedControl");
				CodeExpressionCollection parms = build.Parameters;
				
				parms.Add (new CodeArgumentReferenceExpression("__ctrl"));
				parms.Add (new CodePrimitiveExpression (child.ID));

				if (pca.Shared)
					parms.Add (new CodePrimitiveExpression (child.ControlType.GetHashCode ().ToString ()));
				else
					parms.Add (new CodePrimitiveExpression (Guid.NewGuid ().ToString ()));
					
				parms.Add (new CodePrimitiveExpression (pca.Duration));
				parms.Add (new CodePrimitiveExpression (pca.VaryByParams));
				parms.Add (new CodePrimitiveExpression (pca.VaryByControls));
				parms.Add (new CodePrimitiveExpression (pca.VaryByCustom));
				parms.Add (new CodePrimitiveExpression (pca.SqlDependency));
				parms.Add (new CodeDelegateCreateExpression (
							      new CodeTypeReference (typeof (System.Web.UI.BuildMethod)),
							      thisRef, child.Method.Name));
#if NET_4_0
				string value = pca.ProviderName;
				if (!String.IsNullOrEmpty (value) && String.Compare (OutputCache.DEFAULT_PROVIDER_NAME, value, StringComparison.Ordinal) != 0)
					parms.Add (new CodePrimitiveExpression (value));
				else
					parms.Add (new CodePrimitiveExpression (null));
#endif
				methodStatements.Add (AddLinePragma (build, parent));
				if (parent.HasAspCode)
					AddRenderControl (parent);
				return;
			}
                                
			if (child.IsProperty || parent.ChildrenAsProperties) {
				if (!child.PropertyBuilderShouldReturnValue) {
					expr.Parameters.Add (new CodeFieldReferenceExpression (ctrlVar, child.TagName));
					parent.MethodStatements.Add (AddLinePragma (expr, parent));
				} else {
					string localVarName = parent.GetNextLocalVariableName ("__ctrl");
					methodStatements.Add (new CodeVariableDeclarationStatement (child.Method.ReturnType, localVarName));
					CodeVariableReferenceExpression localVarRef = new CodeVariableReferenceExpression (localVarName);
					CodeAssignStatement assign = new CodeAssignStatement ();
					assign.Left = localVarRef;
					assign.Right = expr;
					methodStatements.Add (AddLinePragma (assign, parent));

					assign = new CodeAssignStatement ();
					assign.Left = new CodeFieldReferenceExpression (ctrlVar, child.TagName);
					assign.Right = localVarRef;
					methodStatements.Add (AddLinePragma (assign, parent));
				}
				
				return;
			}

			methodStatements.Add (AddLinePragma (expr, parent));
			CodeFieldReferenceExpression field = new CodeFieldReferenceExpression (thisRef, child.ID);
			if (parent.ControlType == null || typeof (IParserAccessor).IsAssignableFrom (parent.ControlType))
				AddParsedSubObjectStmt (parent, field);
			else {
				CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (ctrlVar, "Add");
				invoke.Parameters.Add (field);
				methodStatements.Add (AddLinePragma (invoke, parent));
			}
				
			if (parent.HasAspCode)
				AddRenderControl (parent);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:84,代码来源:TemplateControlCompiler.cs


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