/// <devdoc> // //// </devdoc> private void AddProperty(string filter, string name, string value, bool mainDirectiveMode) { Debug.Assert(!String.IsNullOrEmpty(name)); //Second check is a hack to make the intellisense work with strongly typed controls. Existence of ModelType property //should force creation of code to make the intellisense to work, so far this is the only property //that is required to be identified at design time. //If there's atleast one more property, this hack should be removed and another way should be figured out. if (IgnoreControlProperty && !name.Equals(ItemTypeProperty, StringComparison.OrdinalIgnoreCase)) { return; } string objectModelName = String.Empty; MemberInfo memberInfo = null; // This _controlType can be null if we're using a StringPropertyBuilder that has designer expandos if (_controlType != null) { if (String.Equals(name, BaseTemplateCodeDomTreeGenerator.skinIDPropertyName, StringComparison.OrdinalIgnoreCase) && flags[controlTypeIsControl]) { // Make sure there isn't filter for skinID property. if (!String.IsNullOrEmpty(filter)) { throw new InvalidOperationException(SR.GetString(SR.Illegal_Device, BaseTemplateCodeDomTreeGenerator.skinIDPropertyName)); } SkinID = value; return; } memberInfo = PropertyMapper.GetMemberInfo(_controlType, name, out objectModelName); } if (memberInfo != null) { // Found a property on the object, so start building a simple property setter SimplePropertyEntry entry = new SimplePropertyEntry(); entry.Filter = filter; entry.Name = objectModelName; entry.PersistedValue = value; Type memberType = null; if (memberInfo is PropertyInfo) { PropertyInfo propInfo = ((PropertyInfo)memberInfo); entry.PropertyInfo = propInfo; // If the property is read-only if (propInfo.GetSetMethod() == null) { if (!SupportsAttributes) { // If it doesn't support attributes, throw an exception throw new HttpException(SR.GetString(SR.Property_readonly, name)); } else { // Otherwise, use the attribute accessor entry.UseSetAttribute = true; // Use the original casing of the name from the parsed data entry.Name = name; } } ValidatePersistable(propInfo, entry.UseSetAttribute, mainDirectiveMode, true, filter); memberType = propInfo.PropertyType; } else { Debug.Assert(memberInfo is FieldInfo); memberType = ((FieldInfo)memberInfo).FieldType; } entry.Type = memberType; if (entry.UseSetAttribute) { entry.Value = value; } else { // Get the actual value for the property and store it in the entry object objectValue = PropertyConverter.ObjectFromString(memberType, memberInfo, value); DesignTimePageThemeParser themeParser = Parser as DesignTimePageThemeParser; if (themeParser != null) { object[] attrs = memberInfo.GetCustomAttributes(typeof(UrlPropertyAttribute), true); if (attrs.Length > 0) { string url = objectValue.ToString(); // Do not combine the url if it's apprelative, let controls resolve the url. if (UrlPath.IsRelativeUrl(url) && !UrlPath.IsAppRelativePath(url)) { objectValue = themeParser.ThemePhysicalPath + url; } } } entry.Value = objectValue; // if (memberType.IsEnum) { if (objectValue == null) { throw new HttpException(SR.GetString(SR.Invalid_enum_value, value, name, entry.Type.FullName)); } entry.PersistedValue = Enum.Format(memberType, objectValue, "G"); } else if (memberType == typeof(Boolean)) { // if (objectValue == null) { entry.Value = true; } } } AddEntry(SimplePropertyEntriesInternal, entry); } else { bool foundEvent = false; // Check if the property is actually an event handler if (StringUtil.StringStartsWithIgnoreCase(name, "on")) { string eventName = name.Substring(2); EventDescriptor eventDesc = EventDescriptors.Find(eventName, true); if (eventDesc != null) { if (InPageTheme) { throw new HttpException(SR.GetString(SR.Property_theme_disabled, eventName, ControlType.FullName)); } if (value != null) value = value.Trim(); if (String.IsNullOrEmpty(value)) { throw new HttpException(SR.GetString(SR.Event_handler_cant_be_empty, name)); } if (filter.Length > 0) { throw new HttpException(SR.GetString(SR.Events_cant_be_filtered, filter, name)); } foundEvent = true; // First, give the PageParserFilter a chance to handle the event hookup if (!Parser.PageParserFilterProcessedEventHookupAttribute(ID, eventDesc.Name, value)) { // Make sure event handlers are allowed. In no-compile pages, they aren't. (VSWhidbey 450297) Parser.OnFoundEventHandler(name); EventEntry entry = new EventEntry(); entry.Name = eventDesc.Name; entry.HandlerType = eventDesc.EventType; entry.HandlerMethodName = value; EventEntriesInternal.Add(entry); } } } // If we didn't find an eventhandler, we need to use the IAttributeAccessor if (!foundEvent) { // Allow the designer filter expandos for simple attributes if (!SupportsAttributes && (filter != DesignerFilter)) { if (_controlType != null) { throw new HttpException(SR.GetString(SR.Type_doesnt_have_property, _controlType.FullName, name)); } else { throw new HttpException(SR.GetString(SR.Property_doesnt_have_property, TagName, name)); } } SimplePropertyEntry entry = new SimplePropertyEntry(); entry.Filter = filter; entry.Name = name; entry.PersistedValue = value; entry.UseSetAttribute = true; entry.Value = value; AddEntry(SimplePropertyEntriesInternal, entry); } } }
private void AddEventEntry(EventEntry entry) { _eventEntries.Add(entry); }
private void AddProperty(string filter, string name, string value, bool mainDirectiveMode) { if (!this.IgnoreControlProperty) { string nameForCodeGen = string.Empty; MemberInfo propertyInfo = null; if (this._controlType != null) { if (string.Equals(name, "SkinID", StringComparison.OrdinalIgnoreCase) && this.flags[0x2000]) { if (!string.IsNullOrEmpty(filter)) { throw new InvalidOperationException(System.Web.SR.GetString("Illegal_Device", new object[] { "SkinID" })); } this.SkinID = value; return; } propertyInfo = PropertyMapper.GetMemberInfo(this._controlType, name, out nameForCodeGen); } if (propertyInfo != null) { SimplePropertyEntry entry = new SimplePropertyEntry { Filter = filter, Name = nameForCodeGen, PersistedValue = value }; Type objType = null; if (propertyInfo is PropertyInfo) { PropertyInfo propInfo = (PropertyInfo) propertyInfo; entry.PropertyInfo = propInfo; if (propInfo.GetSetMethod() == null) { if (!this.SupportsAttributes) { throw new HttpException(System.Web.SR.GetString("Property_readonly", new object[] { name })); } entry.UseSetAttribute = true; entry.Name = name; } this.ValidatePersistable(propInfo, entry.UseSetAttribute, mainDirectiveMode, true, filter); objType = propInfo.PropertyType; } else { objType = ((FieldInfo) propertyInfo).FieldType; } entry.Type = objType; if (entry.UseSetAttribute) { entry.Value = value; } else { object obj2 = PropertyConverter.ObjectFromString(objType, propertyInfo, value); DesignTimePageThemeParser parser = this.Parser as DesignTimePageThemeParser; if ((parser != null) && (propertyInfo.GetCustomAttributes(typeof(UrlPropertyAttribute), true).Length > 0)) { string virtualPath = obj2.ToString(); if (UrlPath.IsRelativeUrl(virtualPath) && !UrlPath.IsAppRelativePath(virtualPath)) { obj2 = parser.ThemePhysicalPath + virtualPath; } } entry.Value = obj2; if (objType.IsEnum) { if (obj2 == null) { throw new HttpException(System.Web.SR.GetString("Invalid_enum_value", new object[] { value, name, entry.Type.FullName })); } entry.PersistedValue = Enum.Format(objType, obj2, "G"); } else if ((objType == typeof(bool)) && (obj2 == null)) { entry.Value = true; } } this.AddEntry(this.SimplePropertyEntriesInternal, entry); } else { bool flag = false; if (StringUtil.StringStartsWithIgnoreCase(name, "on")) { string str3 = name.Substring(2); EventDescriptor descriptor = this.EventDescriptors.Find(str3, true); if (descriptor != null) { if (this.InPageTheme) { throw new HttpException(System.Web.SR.GetString("Property_theme_disabled", new object[] { str3, this.ControlType.FullName })); } if (value != null) { value = value.Trim(); } if (string.IsNullOrEmpty(value)) { throw new HttpException(System.Web.SR.GetString("Event_handler_cant_be_empty", new object[] { name })); } if (filter.Length > 0) { throw new HttpException(System.Web.SR.GetString("Events_cant_be_filtered", new object[] { filter, name })); } flag = true; if (!this.Parser.PageParserFilterProcessedEventHookupAttribute(this.ID, descriptor.Name, value)) { this.Parser.OnFoundEventHandler(name); EventEntry entry2 = new EventEntry { Name = descriptor.Name, HandlerType = descriptor.EventType, HandlerMethodName = value }; this.EventEntriesInternal.Add(entry2); } } } if (!flag) { if (!this.SupportsAttributes && (filter != DesignerFilter)) { if (this._controlType != null) { throw new HttpException(System.Web.SR.GetString("Type_doesnt_have_property", new object[] { this._controlType.FullName, name })); } throw new HttpException(System.Web.SR.GetString("Property_doesnt_have_property", new object[] { this.TagName, name })); } SimplePropertyEntry entry3 = new SimplePropertyEntry { Filter = filter, Name = name, PersistedValue = value, UseSetAttribute = true, Value = value }; this.AddEntry(this.SimplePropertyEntriesInternal, entry3); } } } }