System.Web.UI.ControlBuilder.GetNextLocalVariableName C# (CSharp) Method

GetNextLocalVariableName() private method

private GetNextLocalVariableName ( string baseName ) : string
baseName string
return string
		internal string GetNextLocalVariableName (string baseName)
		{
			localVariableCount++;
			return baseName + localVariableCount.ToString ();
		}

Usage Example

示例#1
0
		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);
		}