public bool FilterAttributes (IComponent component,IDictionary attributes) { Attribute ea = new DefaultEventAttribute ("AnEvent"); attributes [ea.TypeId] = ea; ea = new DefaultPropertyAttribute ("TestProperty"); attributes [ea.TypeId] = ea; ea = new EditorAttribute (); attributes [ea.TypeId] = ea; return true; }
public void CanGetEditorAttributeFromCollection() { BindableAttribute bindableAttribute = new BindableAttribute(false); EditorAttribute editorAttribute = new EditorAttribute(); Attribute[] attributes = new Attribute[] { bindableAttribute, editorAttribute }; AttributeCollection attributeCollection = new AttributeCollection(attributes); Assert.AreSame(editorAttribute, WixBindingTestsHelper.GetEditorAttribute(attributeCollection)); }
/// <summary> /// Adds the <see cref="EditorAttribute"/>s for the given <see cref="Type"/>s. /// </summary> /// <param name="items">The <see cref="Type"/>s and <see cref="Type"/> of the editor.</param> public static void AddEditorsHelper(params EditorTypes[] items) { if (items == null) return; foreach (var item in items) { var attrib = new EditorAttribute(item.EditorType, typeof(UITypeEditor)); TypeDescriptor.AddAttributes(item.Type, attrib); } }
public static Type GetCategoryEditorType(EditorAttribute attribute, IMessageLogger exceptionLogger) { try { Type editorType = Type.GetType(attribute.EditorTypeName); if (editorType != null && typeof(CategoryEditor).IsAssignableFrom(editorType)) { return editorType; } } catch (Exception e) { if (exceptionLogger != null) { exceptionLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, ExceptionStringTable.CategoryEditorTypeLoadFailed, ExtensibilityMetadataHelper.GetExceptionMessage(e))); } } return null; }
internal AttributeCollection GetAttributes(object component) { ArrayList list = new ArrayList(); if (component is System.Windows.Forms.NativeMethods.IManagedPerPropertyBrowsing) { object[] componentAttributes = Com2IManagedPerPropertyBrowsingHandler.GetComponentAttributes((System.Windows.Forms.NativeMethods.IManagedPerPropertyBrowsing) component, -1); for (int i = 0; i < componentAttributes.Length; i++) { list.Add(componentAttributes[i]); } } if (Com2ComponentEditor.NeedsComponentEditor(component)) { EditorAttribute attribute = new EditorAttribute(typeof(Com2ComponentEditor), typeof(ComponentEditor)); list.Add(attribute); } if ((list == null) || (list.Count == 0)) { return this.staticAttrs; } Attribute[] array = new Attribute[list.Count]; list.CopyTo(array, 0); return new AttributeCollection(array); }
/// <summary> /// Retrieves the editor for the given base type. /// </summary> internal object GetEditor(object instance, Type editorBaseType) { EditorAttribute typeAttr; // For instances, the design time object for them may want to redefine the // attributes. So, we search the attribute here based on the instance. If found, // we then search on the same attribute based on type. If the two don't match, then // we cannot cache the value and must re-create every time. It is rare for a designer // to override these attributes, so we want to be smart here. // if (instance != null) { typeAttr = GetEditorAttribute(TypeDescriptor.GetAttributes(_type), editorBaseType); EditorAttribute instanceAttr = GetEditorAttribute(TypeDescriptor.GetAttributes(instance), editorBaseType); if (typeAttr != instanceAttr) { Type editorType = GetTypeFromName(instanceAttr.EditorTypeName); if (editorType != null && editorBaseType.GetTypeInfo().IsAssignableFrom(editorType)) { return(ReflectTypeDescriptionProvider.CreateInstance(editorType, _type)); } } } // If we got here, we return our type-based editor. // lock (this) { for (int idx = 0; idx < _editorCount; idx++) { if (_editorTypes[idx] == editorBaseType) { return(_editors[idx]); } } } // Editor is not cached yet. Look in the attributes. // object editor = null; typeAttr = GetEditorAttribute(TypeDescriptor.GetAttributes(_type), editorBaseType); if (typeAttr != null) { Type editorType = GetTypeFromName(typeAttr.EditorTypeName); if (editorType != null && editorBaseType.GetTypeInfo().IsAssignableFrom(editorType)) { editor = ReflectTypeDescriptionProvider.CreateInstance(editorType, _type); } } // Editor is not in the attributes. Search intrinsic tables. // if (editor == null) { Hashtable intrinsicEditors = ReflectTypeDescriptionProvider.GetEditorTable(editorBaseType); if (intrinsicEditors != null) { editor = ReflectTypeDescriptionProvider.SearchIntrinsicTable(intrinsicEditors, _type); } // As a quick sanity check, check to see that the editor we got back is of // the correct type. // if (editor != null && !editorBaseType.GetTypeInfo().IsInstanceOfType(editor)) { Debug.Fail($"Editor {editor.GetType().FullName} is not an instance of {editorBaseType.FullName} but it is in that base types table."); editor = null; } } if (editor != null) { lock (this) { if (_editorTypes == null || _editorTypes.Length == _editorCount) { int newLength = (_editorTypes == null ? 4 : _editorTypes.Length * 2); Type[] newTypes = new Type[newLength]; object[] newEditors = new object[newLength]; if (_editorTypes != null) { _editorTypes.CopyTo(newTypes, 0); _editors.CopyTo(newEditors, 0); } _editorTypes = newTypes; _editors = newEditors; _editorTypes[_editorCount] = editorBaseType; _editors[_editorCount++] = editor; } } } return(editor); }
public void SetUpFixture() { WixXmlAttribute attribute = new WixXmlAttribute("Id", WixXmlAttributeType.Text, new string[] {"a", "b"}, null); propertyDescriptor = new WixXmlAttributePropertyDescriptor(attribute); editorAttribute = WixBindingTestsHelper.GetEditorAttribute(propertyDescriptor.Attributes); }
/// <devdoc> /// <para> /// Gets an editor of the specified type. /// </para> /// </devdoc> public virtual object GetEditor(Type editorBaseType) { object editor = null; // Always grab the attribute collection first here, because if the metadata version // changes it will invalidate our editor cache. AttributeCollection attrs = Attributes; // Check the editors we've already created for this type. // if (editorTypes != null) { for (int i = 0; i < editorCount; i++) { if (editorTypes[i] == editorBaseType) { return(editors[i]); } } } // If one wasn't found, then we must go through the attributes. // if (editor == null) { for (int i = 0; i < attrs.Count; i++) { EditorAttribute attr = attrs[i] as EditorAttribute; if (attr == null) { continue; } Type editorType = GetTypeFromName(attr.EditorBaseTypeName); if (editorBaseType == editorType) { Type type = GetTypeFromName(attr.EditorTypeName); if (type != null) { editor = CreateInstance(type); break; } } } // Now, if we failed to find it in our own attributes, go to the // component descriptor. // if (editor == null) { editor = TypeDescriptor.GetEditor(PropertyType, editorBaseType); } // Now, another slot in our editor cache for next time // if (editorTypes == null) { editorTypes = new Type[5]; editors = new object[5]; } if (editorCount >= editorTypes.Length) { Type[] newTypes = new Type[editorTypes.Length * 2]; object[] newEditors = new object[editors.Length * 2]; Array.Copy(editorTypes, newTypes, editorTypes.Length); Array.Copy(editors, newEditors, editors.Length); editorTypes = newTypes; editors = newEditors; } editorTypes[editorCount] = editorBaseType; editors[editorCount++] = editor; } return(editor); }
private static Attribute[] CreateAttributes(IImageProperty imageProperty) { CategoryAttribute category = new CategoryAttribute(imageProperty.Category); DescriptionAttribute description = new DescriptionAttribute(imageProperty.Description); EditorAttribute editor = new EditorAttribute(typeof(ShowValueEditor), typeof(UITypeEditor)); return new Attribute[] { category, description, editor }; }
protected override void PreFilterAttributes(IDictionary attributes) { base.PreFilterAttributes(attributes); EditorAttribute attribute = new EditorAttribute(typeof(StyleSheetComponentEditor), typeof(ComponentEditor)); attributes[attribute.TypeId] = attribute; }
/// <include file='doc\PropertyDescriptor.uex' path='docs/doc[@for="PropertyDescriptor.GetEditor"]/*' /> /// <devdoc> /// <para> /// Gets an editor of the specified type. /// </para> /// </devdoc> public virtual object GetEditor(Type editorBaseType) { object editor = null; // Check the editors we've already created for this type. // if (editorTypes != null) { for (int i = 0; i < editorCount; i++) { if (editorTypes[i] == editorBaseType) { return(editors[i]); } } } // If one wasn't found, then we must go through the attributes. // if (editor == null) { for (int i = 0; i < Attributes.Count; i++) { if (!(Attributes[i] is EditorAttribute)) { continue; } EditorAttribute attr = (EditorAttribute)Attributes[i]; Type editorType = GetTypeFromName(attr.EditorBaseTypeName); if (editorBaseType == editorType) { Type type = GetTypeFromName(attr.EditorTypeName); if (type != null) { editor = CreateInstance(type); break; } } } // Now, if we failed to find it in our own attributes, go to the // component descriptor. // if (editor == null) { editor = TypeDescriptor.GetEditor(PropertyType, editorBaseType); } // Now, another slot in our editor cache for next time // if (editorTypes == null) { editorTypes = new Type[5]; editors = new object[5]; } if (editorCount >= editorTypes.Length) { Type[] newTypes = new Type[editorTypes.Length * 2]; object[] newEditors = new object[editors.Length * 2]; Array.Copy(editorTypes, newTypes, editorTypes.Length); Array.Copy(editors, newEditors, editors.Length); editorTypes = newTypes; editors = newEditors; } editorTypes[editorCount] = editorBaseType; editors[editorCount++] = editor; } return(editor); }
protected void InitEditors() { _Editors.Add (typeof (string), new EditorAttribute (typeof (SimpleStringEditor), typeof (qf4net.IQEventEditor))); string editorsFileName = GetEditorsFileName (); if (System.IO.File.Exists (editorsFileName)) { using (System.IO.StreamReader sr = new System.IO.StreamReader (editorsFileName)) { while (sr.Peek () != -1) { string line = sr.ReadLine ().Trim (); string[] strList = line.Split (new char[] {';'}, 2); if (strList.Length != 2) { throw new ArgumentException ("[" + line + "] does not contain a typename;editorname pair"); } string typeName = strList [0].Trim (); string editorName = strList [1].Trim (); Type type = Type.GetType (typeName); Type editorType = Type.GetType (editorName); EditorAttribute attr = new EditorAttribute (editorType, typeof (qf4net.IQEventEditor)); _Editors [type] = attr; } } } }
public void SetUpFixture() { WixXmlAttribute attribute = new WixXmlAttribute("Id", WixXmlAttributeType.ComponentGuid); propertyDescriptor = new WixXmlAttributePropertyDescriptor(attribute); editorAttribute = WixBindingTestsHelper.GetEditorAttribute(propertyDescriptor.Attributes); }
private static void InternalSetAttribute(System.ComponentModel.MemberDescriptor memb, string property, System.Attribute newattrib, bool on) { System.Attribute oldattrib = memb.Attributes[newattrib.GetType()]; System.Reflection.BindingFlags getflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; System.Reflection.BindingFlags setflags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.SetField | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance; System.Attribute[] oldattribs = (System.Attribute[]) typeof(System.ComponentModel.MemberDescriptor).InvokeMember("attributes", getflags, null, memb, null); if (oldattrib != null) { if (on) { for (int i = 0; i < oldattribs.Length; i++) { if (oldattribs[i].GetType().FullName == newattrib.GetType().FullName) { oldattribs[i] = newattrib; break; } } typeof(System.ComponentModel.MemberDescriptor).InvokeMember("attributeCollection", setflags, null, memb, new object[] { new System.ComponentModel.AttributeCollection(oldattribs) }); typeof(System.ComponentModel.MemberDescriptor).InvokeMember("originalAttributes", setflags, null, memb, new object[] { oldattribs }); if (newattrib is System.ComponentModel.EditorAttribute) { object[] editors = new object[1]; System.ComponentModel.EditorAttribute editor = (System.ComponentModel.EditorAttribute)newattrib; editors[0] = Type.GetType(editor.EditorTypeName).GetConstructors()[0].Invoke(new object[] { }); typeof(System.ComponentModel.PropertyDescriptor).InvokeMember("editors", setflags, null, memb, new object[] { editors }); typeof(System.ComponentModel.PropertyDescriptor).InvokeMember("editorCount", setflags, null, memb, new object[] { 1 }); Type[] editorTypes = new Type[1] { Type.GetType(editor.EditorBaseTypeName) }; typeof(System.ComponentModel.PropertyDescriptor).InvokeMember("editorTypes", setflags, null, memb, new object[] { editorTypes }); } } else { System.Attribute[] newattribs = new System.Attribute[oldattribs.Length - 1]; int i = 0; foreach (System.Attribute a in oldattribs) { if (a.GetType().FullName != newattrib.GetType().FullName) { newattribs[i++] = a; } } typeof(System.ComponentModel.MemberDescriptor).InvokeMember("attributes", setflags, null, memb, new object[] { newattribs }); typeof(System.ComponentModel.MemberDescriptor).InvokeMember("originalAttributes", setflags, null, memb, new object[] { newattribs }); typeof(System.ComponentModel.MemberDescriptor).InvokeMember("attributeCollection", setflags, null, memb, new object[] { new System.ComponentModel.AttributeCollection(newattribs) }); } } else if (on) { System.Attribute[] newattribs = new System.Attribute[oldattribs.Length + 1]; int i = 0; foreach (System.Attribute a in oldattribs) { newattribs[i++] = a; } newattribs[i++] = newattrib; typeof(System.ComponentModel.MemberDescriptor).InvokeMember("attributes", setflags, null, memb, new object[] { newattribs }); typeof(System.ComponentModel.MemberDescriptor).InvokeMember("originalAttributes", setflags, null, memb, new object[] { newattribs }); typeof(System.ComponentModel.MemberDescriptor).InvokeMember("attributeCollection", setflags, null, memb, new object[] { new System.ComponentModel.AttributeCollection(newattribs) }); } }
/// <include file='doc\ComNativeDescriptor.uex' path='docs/doc[@for="ComNativeDescriptor.GetAttributes"]/*' /> /// <devdoc> /// Got attributes? /// </devdoc> internal AttributeCollection GetAttributes(Object component) { ArrayList attrs = new ArrayList(); if (component is NativeMethods.IManagedPerPropertyBrowsing) { Object[] temp = Com2IManagedPerPropertyBrowsingHandler.GetComponentAttributes((NativeMethods.IManagedPerPropertyBrowsing)component, NativeMethods.MEMBERID_NIL); for (int i = 0; i < temp.Length; ++i) { attrs.Add(temp[i]); } } if (Com2ComponentEditor.NeedsComponentEditor(component)) { EditorAttribute a = new EditorAttribute(typeof(Com2ComponentEditor), typeof(ComponentEditor)); attrs.Add(a); } if (attrs == null || attrs.Count == 0) { return staticAttrs; } else { Attribute[] temp = new Attribute[attrs.Count]; attrs.CopyTo(temp, 0); return new AttributeCollection(temp); } }
public WidgetProps ParseXml(string xmlfilename) { WidgetProps props = null; string elemType = ""; string elemName = ""; object elemValue = null; string elemCategory = ""; string elemDesc = ""; bool elemBrowsable = true; bool elemReadOnly = false; string elemEditor = ""; string elemTypeConv = ""; // Parse XML file System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream str = a.GetManifestResourceStream("mkdb.Properties.wxprops.xsd"); xsd_settings = new XmlReaderSettings(); xsd_settings.ValidationType = ValidationType.Schema; xsd_settings.Schemas.Add("wxprops", new XmlTextReader(str)); // xsd_settings.Schemas.Add("props", xsdfilename); using (r = XmlReader.Create(xmlfilename, xsd_settings)) while (r.Read()) { switch (r.NodeType) { case XmlNodeType.Element: if (r.Name == "Catalog") { // Set Name if (props == null) { props = new WidgetProps(); } props.Name = r["Name"]; // this.name = r["Name"]; // this.basecontainername = r["Base"]; } if (r.Name == "Category") { elemCategory = GetElemString(r); } if (r.Name == "Property") { // Parse the data... elemType = ""; elemName = r["Name"]; elemValue = null; elemDesc = ""; elemBrowsable = true; elemReadOnly = false; elemEditor = ""; elemTypeConv = ""; } if (r.Name == "Type") elemType = GetElemString(r); if (r.Name == "Description") elemDesc = GetElemString(r); if (r.Name == "Editor") elemEditor = GetElemString(r); if (r.Name == "TypeConverter") elemTypeConv = GetElemString(r); if (r.Name == "Value") GetElemValue(r, elemType, out elemValue); break; case XmlNodeType.EndElement: if (r.Name == "Property") { // We should have all the info... // build this GenericProperty int attCount = 2; if (elemEditor != "") attCount++; if (elemTypeConv != "") attCount++; Attribute[] attr = new Attribute[attCount]; attr[0] = new BrowsableAttribute(elemBrowsable); attr[1] = new ReadOnlyAttribute(elemReadOnly); attCount = 2; if (elemEditor != "") { attr[attCount++] = new EditorAttribute(elemEditor, "UITypeEditor"); } if (elemTypeConv != "") { attr[attCount++] = new TypeConverterAttribute(elemTypeConv); } if (elemValue == null) { GetElemDefault(r, elemType, elemValue); } props.Properties.AddProperty(new GenericProperty(elemName, elemValue, elemCategory, elemDesc, attr)); } if (r.Name == "Category") { elemCategory = ""; } break; case XmlNodeType.Text: case XmlNodeType.CDATA: case XmlNodeType.Comment: case XmlNodeType.XmlDeclaration: break; case XmlNodeType.DocumentType: break; default: break; } } _wplist.Add(props); return props; }