private void AddBoundProperty(string filter, string name, string expressionPrefix, string expression, ExpressionBuilder expressionBuilder, object parsedExpressionData, bool generated, string fieldName, string formatString, bool twoWayBound) { string iD = this.ParseTimeData.ID; IDesignerHost designerHost = this.DesignerHost; if (string.IsNullOrEmpty(expressionPrefix)) { if (string.IsNullOrEmpty(iD)) { if (this.CompilationMode == System.Web.UI.CompilationMode.Never) { throw new HttpException(System.Web.SR.GetString("NoCompileBinding_requires_ID", new object[] { this._controlType.Name, fieldName })); } if (twoWayBound) { throw new HttpException(System.Web.SR.GetString("TwoWayBinding_requires_ID", new object[] { this._controlType.Name, fieldName })); } } if (!this.flags[0x2000] && (TargetFrameworkUtil.GetEvent(this.ControlType, "DataBinding") == null)) { throw new InvalidOperationException(System.Web.SR.GetString("ControlBuilder_DatabindingRequiresEvent", new object[] { this._controlType.FullName })); } } else if (expressionBuilder == null) { expressionBuilder = ExpressionBuilder.GetExpressionBuilder(expressionPrefix, this.VirtualPath, designerHost); } BoundPropertyEntry entry = new BoundPropertyEntry { Filter = filter, Expression = expression, ExpressionBuilder = expressionBuilder, ExpressionPrefix = expressionPrefix, Generated = generated, FieldName = fieldName, FormatString = formatString, ControlType = this._controlType, ControlID = iD, TwoWayBound = twoWayBound, ParsedExpressionData = parsedExpressionData }; this.FillUpBoundPropertyEntry(entry, name); foreach (BoundPropertyEntry entry2 in this.BoundPropertyEntriesInternal) { if (string.Equals(entry2.Name, entry.Name, StringComparison.OrdinalIgnoreCase) && string.Equals(entry2.Filter, entry.Filter, StringComparison.OrdinalIgnoreCase)) { string str2 = entry.Name; if (!string.IsNullOrEmpty(entry.Filter)) { str2 = entry.Filter + ":" + str2; } throw new InvalidOperationException(System.Web.SR.GetString("ControlBuilder_CannotHaveMultipleBoundEntries", new object[] { str2, this.ControlType })); } } this.AddBoundProperty(entry); }
/// <devdoc> /// /// </devdoc> private void AddBoundProperty(string filter, string name, string expressionPrefix, string expression, ExpressionBuilder expressionBuilder, object parsedExpressionData, bool generated, string fieldName, string formatString, bool twoWayBound, bool encode, int line = 0, int column = 0) { Debug.Assert(!String.IsNullOrEmpty(name)); string controlID = ParseTimeData.ID; // Get the IDesignerHost in case we need it to find ExpressionBuilders IDesignerHost host = DesignerHost; if (String.IsNullOrEmpty(expressionPrefix)) { // This is a databinding entry if (String.IsNullOrEmpty(controlID)) { if (CompilationMode == CompilationMode.Never) { throw new HttpException(SR.GetString(SR.NoCompileBinding_requires_ID, _controlType.Name, fieldName)); } if (twoWayBound) { throw new HttpException(SR.GetString(SR.TwoWayBinding_requires_ID, _controlType.Name, fieldName)); } } Debug.Assert(ControlType != null, "ControlType should not be null if we're adding a property entry"); // We only support databindings on objects that have an event named "DataBinding" if (!flags[controlTypeIsControl]) { if (TargetFrameworkUtil.GetEvent(ControlType, "DataBinding") == null) { throw new InvalidOperationException(SR.GetString(SR.ControlBuilder_DatabindingRequiresEvent, _controlType.FullName)); } } } else { // If we don't have an expression builder yet, go get it if (expressionBuilder == null) { expressionBuilder = ExpressionBuilder.GetExpressionBuilder(expressionPrefix, VirtualPath, host); } } Debug.Assert(!(String.IsNullOrEmpty(expressionPrefix) ^ (expressionBuilder == null)), "expressionBuilder should be non-null iff expressionPrefix is non-empty"); // Set up a BoundPropertyEntry since we know this is an expression BoundPropertyEntry entry = new BoundPropertyEntry(); entry.Filter = filter; entry.Expression = expression; entry.ExpressionBuilder = expressionBuilder; entry.ExpressionPrefix = expressionPrefix; entry.Generated = generated; entry.FieldName = fieldName; entry.FormatString = formatString; entry.ControlType = _controlType; entry.ControlID = controlID; entry.TwoWayBound = twoWayBound; entry.ParsedExpressionData = parsedExpressionData; entry.IsEncoded = encode; entry.Line = line; entry.Column = column; FillUpBoundPropertyEntry(entry, name); // Check for duplicate bound property entries and throws if it finds one. // This is done here rather than on AddBoundProperty(BoundPropertyEntry entry) since // that overload can be called by other control builders in two-way binding scenarios. // In that case it is valid to have duplicate bound property entries since they are on // the BindableTemplateBuilder, not the control's ControlBuilder. foreach (BoundPropertyEntry bpe in BoundPropertyEntriesInternal) { if (String.Equals(bpe.Name, entry.Name, StringComparison.OrdinalIgnoreCase) && String.Equals(bpe.Filter, entry.Filter, StringComparison.OrdinalIgnoreCase)) { string fullPropertyName = entry.Name; if (!String.IsNullOrEmpty(entry.Filter)) { fullPropertyName = entry.Filter + ":" + fullPropertyName; } throw new InvalidOperationException(SR.GetString(SR.ControlBuilder_CannotHaveMultipleBoundEntries, fullPropertyName, ControlType)); } } // Add these to the bound entries AddBoundProperty(entry); }
private void AddBoundProperty(string filter, string name, string expressionPrefix, string expression, ExpressionBuilder expressionBuilder, object parsedExpressionData, string fieldName, string formatString, bool twoWayBound, bool encode, int line = 0, int column = 0) { AddBoundProperty(filter, name, expressionPrefix, expression, expressionBuilder, parsedExpressionData, false, fieldName, formatString, twoWayBound, encode, line, column); }
private void AddBoundProperty(string filter, string name, string expressionPrefix, string expression, ExpressionBuilder expressionBuilder, object parsedExpressionData, string fieldName, string formatString, bool twoWayBound) { this.AddBoundProperty(filter, name, expressionPrefix, expression, expressionBuilder, parsedExpressionData, false, fieldName, formatString, twoWayBound); }
internal static ExpressionBuilder GetExpressionBuilder(string expressionPrefix, VirtualPath virtualPath, IDesignerHost host) { // If there is no expressionPrefix, it's a v1 style databinding expression if (expressionPrefix.Length == 0) { if (dataBindingExpressionBuilder == null) { dataBindingExpressionBuilder = new DataBindingExpressionBuilder(); } return(dataBindingExpressionBuilder); } CompilationSection config = null; // If we are in the designer, we need to access IWebApplication config instead #if !FEATURE_PAL // FEATURE_PAL does not support designer-based features if (host != null) { IWebApplication webapp = (IWebApplication)host.GetService(typeof(IWebApplication)); if (webapp != null) { config = webapp.OpenWebConfiguration(true).GetSection("system.web/compilation") as CompilationSection; } } #endif // !FEATURE_PAL // If we failed to get config from the designer, fall back on runtime config always if (config == null) { config = MTConfigUtil.GetCompilationConfig(virtualPath); } System.Web.Configuration.ExpressionBuilder builder = config.ExpressionBuilders[expressionPrefix]; if (builder == null) { throw new HttpParseException(SR.GetString(SR.InvalidExpressionPrefix, expressionPrefix)); } Type expressionBuilderType = null; if (host != null) { // If we are in the designer, we have to use the type resolution service ITypeResolutionService ts = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService)); if (ts != null) { expressionBuilderType = ts.GetType(builder.Type); } } if (expressionBuilderType == null) { expressionBuilderType = builder.TypeInternal; } Debug.Assert(expressionBuilderType != null, "expressionBuilderType should not be null"); if (!typeof(ExpressionBuilder).IsAssignableFrom(expressionBuilderType)) { throw new HttpParseException(SR.GetString(SR.ExpressionBuilder_InvalidType, expressionBuilderType.FullName)); } ExpressionBuilder expressionBuilder = (ExpressionBuilder)HttpRuntime.FastCreatePublicInstance(expressionBuilderType); return(expressionBuilder); }