System.Web.Compilation.TemplateControlCompiler.CreateAssignStatementFromAttribute C# (CSharp) Method

CreateAssignStatementFromAttribute() static private method

static private CreateAssignStatementFromAttribute ( ControlBuilder builder, string id ) : void
builder System.Web.UI.ControlBuilder
id string
return void
		void CreateAssignStatementFromAttribute (ControlBuilder builder, string id)
		{
			EventInfo [] ev_info = null;
			Type type = builder.ControlType;
			
			string attvalue = builder.GetAttribute (id);
			if (id.Length > 2 && String.Compare (id.Substring (0, 2), "ON", true, Helpers.InvariantCulture) == 0){
				if (ev_info == null)
					ev_info = type.GetEvents ();

				string id_as_event = id.Substring (2);
				foreach (EventInfo ev in ev_info){
					if (InvariantCompareNoCase (ev.Name, id_as_event)){
						AddEventAssign (builder.Method,
								builder,
								ev.Name,
								ev.EventHandlerType,
								attvalue);
						
						return;
					}
				}

			}

			if (String.Compare (id, "meta:resourcekey", StringComparison.OrdinalIgnoreCase) == 0) {
				AssignPropertiesFromResources (builder, attvalue);
				return;
			}
			
			int hyphen = id.IndexOf ('-');
			string alt_id = id;
			if (hyphen != -1)
				alt_id = id.Substring (0, hyphen);

			MemberInfo fop = GetFieldOrProperty (type, alt_id);
			if (fop != null) {
				if (ProcessPropertiesAndFields (builder, fop, id, attvalue, null))
					return;
			}

			if (!typeof (IAttributeAccessor).IsAssignableFrom (type))
				throw new ParseException (builder.Location, "Unrecognized attribute: " + id);

			CodeMemberMethod method = builder.Method;
			bool isDatabound = BaseParser.IsDataBound (attvalue);
			bool isExpression = !isDatabound && BaseParser.IsExpression (attvalue);

			if (isDatabound) {
				string value = attvalue.Substring (3, attvalue.Length - 5).Trim ();
				CodeExpression valueExpression = null;
				if (startsWithBindRegex.Match (value).Success)
					valueExpression = CreateEvalInvokeExpression (bindRegexInValue, value, true);
				else
					if (StrUtils.StartsWith (value, "Eval", true))
						valueExpression = CreateEvalInvokeExpression (evalRegexInValue, value, false);
				
				if (valueExpression == null && value != null && value.Trim () != String.Empty)
					valueExpression = new CodeSnippetExpression (value);
				
				CreateDBAttributeMethod (builder, id, valueExpression);
			} else {
				CodeCastExpression cast;
				CodeMethodReferenceExpression methodExpr;
				CodeMethodInvokeExpression expr;

				cast = new CodeCastExpression (typeof (IAttributeAccessor), ctrlVar);
				methodExpr = new CodeMethodReferenceExpression (cast, "SetAttribute");
				expr = new CodeMethodInvokeExpression (methodExpr);
				expr.Parameters.Add (new CodePrimitiveExpression (id));

				CodeExpression valueExpr = null;
				if (isExpression)
					valueExpr = CompileExpression (null, typeof (string), attvalue, true);

				if (valueExpr == null)
					valueExpr = new CodePrimitiveExpression (attvalue);
				
				expr.Parameters.Add (valueExpr);
				method.Statements.Add (AddLinePragma (expr, builder));
			}
		}
TemplateControlCompiler