本文整理汇总了C#中System.Web.UI.ControlBuilder.GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# ControlBuilder.GetAttribute方法的具体用法?C# ControlBuilder.GetAttribute怎么用?C# ControlBuilder.GetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.UI.ControlBuilder
的用法示例。
在下文中一共展示了ControlBuilder.GetAttribute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterBindingInfo
void RegisterBindingInfo (ControlBuilder builder, string propName, ref string value)
{
string str = TrimDB (value, false);
if (StrUtils.StartsWith (str, "Bind", true)) {
Match match = bindRegex.Match (str);
if (match.Success) {
string bindingName = match.Groups [1].Value;
TemplateBuilder templateBuilder = builder.ParentTemplateBuilder;
if (templateBuilder == null)
throw new HttpException ("Bind expression not allowed in this context.");
if (templateBuilder.BindingDirection == BindingDirection.OneWay)
return;
string id = builder.GetAttribute ("ID");
if (String.IsNullOrEmpty (id))
throw new HttpException ("Control of type '" + builder.ControlType + "' using two-way binding on property '" + propName + "' must have an ID.");
templateBuilder.RegisterBoundProperty (builder.ControlType, propName, id, bindingName);
}
}
}
示例2: CreateControlTree
//.........这里部分代码省略.........
if (!singleInstance)
builder.ID = builder.GetNextID (null);
else
doCheck = true;
CreateField (builder, doCheck);
}
InitMethod (builder, isTemplate, childrenAsProperties);
if (!isTemplate || builder.GetType () == typeof (RootBuilder))
CreateAssignStatementsFromAttributes (builder);
if (builder.Children != null && builder.Children.Count > 0) {
StringBuilder sb = new StringBuilder ();
foreach (object b in builder.Children) {
if (b is string) {
sb.Append ((string) b);
continue;
}
FlushText (builder, sb);
if (b is ObjectTagBuilder) {
ProcessObjectTag ((ObjectTagBuilder) b);
} else if (b is StringPropertyBuilder) {
StringPropertyBuilder pb = b as StringPropertyBuilder;
if (pb.Children != null && pb.Children.Count > 0) {
StringBuilder asb = new StringBuilder ();
foreach (string s in pb.Children)
asb.Append (s);
CodeMemberMethod method = builder.Method;
CodeAssignStatement assign = new CodeAssignStatement ();
assign.Left = new CodePropertyReferenceExpression (ctrlVar, pb.PropertyName);
assign.Right = new CodePrimitiveExpression (asb.ToString ());
method.Statements.Add (AddLinePragma (assign, builder));
}
} else if (b is ContentBuilderInternal) {
ContentBuilderInternal cb = (ContentBuilderInternal) b;
CreateControlTree (cb, false, true);
AddContentTemplateInvocation (cb, builder.Method, cb.Method.Name);
continue;
}
// Ignore TemplateBuilders - they are processed in InitMethod
else if (b is TemplateBuilder) {
} else if (b is CodeRenderBuilder) {
AddCodeRender (builder, (CodeRenderBuilder) b);
} else if (b is DataBindingBuilder) {
AddDataBindingLiteral (builder, (DataBindingBuilder) b);
} else if (b is ControlBuilder) {
ControlBuilder child = (ControlBuilder) b;
CreateControlTree (child, inTemplate, builder.ChildrenAsProperties);
AddChildCall (builder, child);
continue;
} else
throw new Exception ("???");
ControlBuilder bldr = b as ControlBuilder;
bldr.ProcessGeneratedCode (CompileUnit, BaseType, DerivedType, bldr.Method, bldr.DataBindingMethod);
}
FlushText (builder, sb);
}
ControlBuilder defaultPropertyBuilder = builder.DefaultPropertyBuilder;
if (defaultPropertyBuilder != null) {
CreateControlTree (defaultPropertyBuilder, false, true);
AddChildCall (builder, defaultPropertyBuilder);
}
if (builder.HasAspCode) {
CodeMemberMethod renderMethod = builder.RenderMethod;
CodeMethodReferenceExpression m = new CodeMethodReferenceExpression ();
m.TargetObject = thisRef;
m.MethodName = renderMethod.Name;
CodeDelegateCreateExpression create = new CodeDelegateCreateExpression ();
create.DelegateType = new CodeTypeReference (typeof (RenderMethod));
create.TargetObject = thisRef;
create.MethodName = renderMethod.Name;
CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression ();
invoke.Method = new CodeMethodReferenceExpression (ctrlVar, "SetRenderMethodDelegate");
invoke.Parameters.Add (create);
builder.MethodStatements.Add (invoke);
}
if (builder is RootBuilder)
if (!String.IsNullOrEmpty (parser.MetaResourceKey))
AssignPropertiesFromResources (builder, parser.BaseType, parser.MetaResourceKey);
if ((!isTemplate || builder is RootBuilder) && !String.IsNullOrEmpty (builder.GetAttribute ("meta:resourcekey")))
CreateAssignStatementFromAttribute (builder, "meta:resourcekey");
if ((childrenAsProperties && builder.PropertyBuilderShouldReturnValue) || (!childrenAsProperties && typeof (Control).IsAssignableFrom (builder.ControlType)))
builder.Method.Statements.Add (new CodeMethodReturnStatement (ctrlVar));
builder.ProcessGeneratedCode (CompileUnit, BaseType, DerivedType, builder.Method, builder.DataBindingMethod);
}
示例3: InitMethod
//.........这里部分代码省略.........
CodeMethodInvokeExpression initAsControl = new CodeMethodInvokeExpression (mref);
initAsControl.Parameters.Add (new CodePropertyReferenceExpression (thisRef, "Page"));
method.Statements.Add (initAsControl);
}
if (builder.ParentTemplateBuilder is System.Web.UI.WebControls.ContentBuilderInternal) {
PropertyInfo pi;
try {
pi = type.GetProperty ("TemplateControl");
} catch (Exception) {
pi = null;
}
if (pi != null && pi.CanWrite) {
// __ctrl.TemplateControl = this;
assign = new CodeAssignStatement ();
assign.Left = new CodePropertyReferenceExpression (ctrlVar, "TemplateControl");;
assign.Right = thisRef;
method.Statements.Add (assign);
}
}
// _ctrl.SkinID = $value
// _ctrl.ApplyStyleSheetSkin (this);
//
// the SkinID assignment needs to come
// before the call to
// ApplyStyleSheetSkin, for obvious
// reasons. We skip SkinID in
// CreateAssignStatementsFromAttributes
// below.
//
string skinid = builder.GetAttribute ("skinid");
if (!String.IsNullOrEmpty (skinid))
CreateAssignStatementFromAttribute (builder, "skinid");
if (typeof (WebControl).IsAssignableFrom (type)) {
CodeMethodInvokeExpression applyStyleSheetSkin = new CodeMethodInvokeExpression (ctrlVar, "ApplyStyleSheetSkin");
if (typeof (Page).IsAssignableFrom (parser.BaseType))
applyStyleSheetSkin.Parameters.Add (thisRef);
else
applyStyleSheetSkin.Parameters.Add (new CodePropertyReferenceExpression (thisRef, "Page"));
method.Statements.Add (applyStyleSheetSkin);
}
// Process template children before anything else
ProcessTemplateChildren (builder);
// process ID here. It should be set before any other attributes are
// assigned, since the control code may rely on ID being set. We
// skip ID in CreateAssignStatementsFromAttributes
string ctl_id = builder.GetAttribute ("id");
if (ctl_id != null && ctl_id.Length != 0)
CreateAssignStatementFromAttribute (builder, "id");
if (typeof (ContentPlaceHolder).IsAssignableFrom (type)) {
List <string> placeHolderIds = MasterPageContentPlaceHolders;
string cphID = builder.ID;
if (!placeHolderIds.Contains (cphID))
placeHolderIds.Add (cphID);
CodeConditionStatement condStatement;
// Add the __Template_* field
示例4: CreateAssignStatementFromAttribute
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));
}
}