public Dictionary <int, PropertyInfo> GetPropertyDic() { Dictionary <int, PropertyInfo> canSearchEleDic = new Dictionary <int, PropertyInfo>(); Type type = _doc.GetType(); PropertyInfo[] propertys = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); if (propertys != null) { foreach (PropertyInfo property in propertys) { object[] attributes = property.GetCustomAttributes(typeof(EditorAttribute), false); if (attributes.Length > 0) { EditorAttribute ediAttribute = (EditorAttribute)attributes[0]; if (ediAttribute.IsCanFind) { canSearchEleDic.Add(dicKey, property); dicKey++; } } } } return(canSearchEleDic); }
public static IEnumerable <object[]> Equals_TestData() { var attribute = new EditorAttribute("typeName", "baseTypeName"); yield return(new object[] { attribute, attribute, true }); yield return(new object[] { attribute, new EditorAttribute("typeName", "baseTypeName"), true }); yield return(new object[] { attribute, new EditorAttribute("typename", "baseTypeName"), false }); yield return(new object[] { attribute, new EditorAttribute("typeName", "basetypename"), false }); yield return(new object[] { attribute, new EditorAttribute("typeName", (string)null), false }); yield return(new object[] { new EditorAttribute("typeName", (string)null), new EditorAttribute("typeName", (string)null), true }); yield return(new object[] { new EditorAttribute("typeName", (string)null), new EditorAttribute("typename", (string)null), false }); yield return(new object[] { new EditorAttribute("typeName", (string)null), new EditorAttribute("typeName", "baseTypeName"), false }); yield return(new object[] { attribute, new object(), false }); yield return(new object[] { attribute, null, false }); }
private static Attribute[] GetAttributesForVariable(VariableListSave variableList) { mListOfAttributes.Clear(); EditorAttribute editorAttribute = new EditorAttribute( //"System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(VariableListConverter), typeof(UITypeEditor)); mListOfAttributes.Add(editorAttribute); if (!string.IsNullOrEmpty(variableList.Category)) { mListOfAttributes.Add(new CategoryAttribute(variableList.Category)); } if (variableList.IsHiddenInPropertyGrid) { mListOfAttributes.Add(new BrowsableAttribute(false)); } return(mListOfAttributes.ToArray()); }
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { PropertyDescriptorCollection ps = TypeDescriptor.GetProperties(this, attributes, true); if (IsBrowsable(attributes)) { createInputs(); if (_variables.Count > 0) { List <PropertyDescriptor> list = new List <PropertyDescriptor>(); foreach (PropertyDescriptor p in ps) { list.Add(p); } int n = 0; if (attributes != null) { n = attributes.Length; } Attribute[] attrs = new Attribute[n + 2]; if (n > 0) { attributes.CopyTo(attrs, 0); } attrs[n] = new EditorAttribute(typeof(PropEditorMathPropertyPointer), typeof(UITypeEditor)); attrs[n + 1] = new TypeConverterAttribute(typeof(TypeConverterMathPropertyPointer)); foreach (string s in _variables.Keys) { PropertyDescriptorPropertyPointer p = new PropertyDescriptorPropertyPointer(s, attrs); list.Add(p); } ps = new PropertyDescriptorCollection(list.ToArray()); } } return(ps); }
/// ----------------------------------------------------------------------------- /// <summary> /// GetEditorInfo builds an EditorInfo object for a propoerty. /// </summary> /// ----------------------------------------------------------------------------- private EditorInfo GetEditorInfo(object dataSource, PropertyInfo objProperty) { var editInfo = new EditorInfo(); // Get the Name of the property editInfo.Name = objProperty.Name; // Get the value of the property editInfo.Value = objProperty.GetValue(dataSource, null); // Get the type of the property editInfo.Type = objProperty.PropertyType.AssemblyQualifiedName; // Get the Custom Attributes for the property editInfo.Attributes = objProperty.GetCustomAttributes(true); // Get Category Field editInfo.Category = string.Empty; object[] categoryAttributes = objProperty.GetCustomAttributes(typeof(CategoryAttribute), true); if (categoryAttributes.Length > 0) { var category = (CategoryAttribute)categoryAttributes[0]; editInfo.Category = category.Category; } // Get EditMode Field if (!objProperty.CanWrite) { editInfo.EditMode = PropertyEditorMode.View; } else { object[] readOnlyAttributes = objProperty.GetCustomAttributes(typeof(IsReadOnlyAttribute), true); if (readOnlyAttributes.Length > 0) { var readOnlyMode = (IsReadOnlyAttribute)readOnlyAttributes[0]; if (readOnlyMode.IsReadOnly) { editInfo.EditMode = PropertyEditorMode.View; } } } // Get Editor Field editInfo.Editor = "UseSystemType"; object[] editorAttributes = objProperty.GetCustomAttributes(typeof(EditorAttribute), true); if (editorAttributes.Length > 0) { EditorAttribute editor = null; for (int i = 0; i <= editorAttributes.Length - 1; i++) { if (((EditorAttribute)editorAttributes[i]).EditorBaseTypeName.IndexOf("DotNetNuke.UI.WebControls.EditControl") >= 0) { editor = (EditorAttribute)editorAttributes[i]; break; } } if (editor != null) { editInfo.Editor = editor.EditorTypeName; } } // Get Required Field editInfo.Required = false; object[] requiredAttributes = objProperty.GetCustomAttributes(typeof(RequiredAttribute), true); if (requiredAttributes.Length > 0) { // The property may contain multiple edit mode types, so make sure we only use DotNetNuke editors. var required = (RequiredAttribute)requiredAttributes[0]; if (required.Required) { editInfo.Required = true; } } // Get Css Style editInfo.ControlStyle = new Style(); object[] StyleAttributes = objProperty.GetCustomAttributes(typeof(ControlStyleAttribute), true); if (StyleAttributes.Length > 0) { var attribute = (ControlStyleAttribute)StyleAttributes[0]; editInfo.ControlStyle.CssClass = attribute.CssClass; editInfo.ControlStyle.Height = attribute.Height; editInfo.ControlStyle.Width = attribute.Width; } // Get LabelMode Field editInfo.LabelMode = LabelMode.Left; object[] labelModeAttributes = objProperty.GetCustomAttributes(typeof(LabelModeAttribute), true); if (labelModeAttributes.Length > 0) { var mode = (LabelModeAttribute)labelModeAttributes[0]; editInfo.LabelMode = mode.Mode; } // Set ResourceKey Field editInfo.ResourceKey = string.Format("{0}_{1}", dataSource.GetType().Name, objProperty.Name); // Get Validation Expression Field editInfo.ValidationExpression = string.Empty; object[] regExAttributes = objProperty.GetCustomAttributes(typeof(RegularExpressionValidatorAttribute), true); if (regExAttributes.Length > 0) { var regExAttribute = (RegularExpressionValidatorAttribute)regExAttributes[0]; editInfo.ValidationExpression = regExAttribute.Expression; } // Set Visibility editInfo.ProfileVisibility = new ProfileVisibility { VisibilityMode = UserVisibilityMode.AllUsers, }; return(editInfo); }
public void GetHashCode_Invoke_ReturnsConsistentValue() { var attribute = new EditorAttribute(); Assert.Equal(attribute.GetHashCode(), attribute.GetHashCode()); }
public void Equals_Object_ReturnsExpected(EditorAttribute attribute, object other, bool expected) { Assert.Equal(expected, attribute.Equals(other)); }
protected override void OnSelectedGridItemChanged(SelectedGridItemChangedEventArgs e) { base.OnSelectedGridItemChanged(e); if (_editbox == null) { AddTextEditorFocusWatcher(); } bool isItems = false; if (e == null) { return; } if (e.NewSelection == null) { return; } if (e.NewSelection.PropertyDescriptor == null) { return; } PropertyDescriptor pd = e.NewSelection.PropertyDescriptor; if (pd.PropertyType != null && pd.PropertyType.GetInterface("ICollection") != null) { FieldInfo[] fifs = pd.Attributes.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic); for (int i = 0; i < fifs.Length; i++) { if (string.CompareOrdinal(fifs[i].Name, "_attributes") == 0) { Attribute[] attrs = fifs[i].GetValue(pd.Attributes) as Attribute[]; if (attrs != null) { for (int j = 0; j < attrs.Length; j++) { EditorAttribute ea = attrs[j] as EditorAttribute; if (ea != null) { try { Type t = Type.GetType(ea.EditorTypeName); if (t != null) { if (typeof(CollectionEditor).IsAssignableFrom(t)) { isItems = true; break; } } } catch { } } } } } } } if (_items != null) { if (e.NewSelection.Value != _items) { if (LeaveItems != null) { LeaveItems(this, EventArgs.Empty); } } } if (isItems) { _items = e.NewSelection.Value; _component = this.SelectedObject; } else { _items = null; } }
public MainForm() { this.Font = SystemFonts.MessageBoxFont; InitializeComponent(); SimulationHandler = new MySimulationHandler(backgroundWorker); SimulationHandler.StateChanged += SimulationHandler_StateChanged; SimulationHandler.ProgressChanged += SimulationHandler_ProgressChanged; // must be created in advance to grab possible error logs ConsoleView = new ConsoleForm(this); var assemblyName = Assembly.GetExecutingAssembly().GetName(); MyLog.INFO.WriteLine(assemblyName.Name + " version " + assemblyName.Version); try { SimulationHandler.Simulation = new MyLocalSimulation(); } catch (Exception e) { MessageBox.Show("An error occured when initializing simulation. Please make sure you have a supported CUDA-enabled graphics card and apropriate drivers." + "Technical details: " + e.Message, "Simulation Initialization Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // this way you do not have to tweak form Close and Closing events and it works even with any worker threads still running Environment.Exit(1); } MyConfiguration.SetupModuleSearchPath(); MyConfiguration.ProcessCommandParams(); try { MyConfiguration.LoadModules(); } catch (Exception e) { MessageBox.Show(e.Message, "Fatal error occured during initialization", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } Documentation = new MyDocProvider(); foreach (MyModuleConfig module in MyConfiguration.Modules) { Documentation.LoadXMLDoc(module.Assembly); } NodePropertyView = new NodePropertyForm(this); MemoryBlocksView = new MemoryBlocksForm(this); TaskView = new TaskForm(this); TaskPropertyView = new TaskPropertyForm(this); GraphViews = new Dictionary <MyNodeGroup, GraphLayoutForm>(); ObserverViews = new List <ObserverForm>(); ValidationView = new ValidationForm(this); HelpView = new NodeHelpForm(this); HelpView.StartPosition = FormStartPosition.CenterScreen; DebugView = new DebugForm(this); PopulateWorldList(); CreateNewProject(); CreateNetworkView(); m_views = new List <DockContent>() { NetworkView, NodePropertyView, MemoryBlocksView, TaskView, TaskPropertyView, ConsoleView, ValidationView, DebugView, HelpView }; foreach (DockContent view in m_views) { ToolStripMenuItem viewMenuItem = new ToolStripMenuItem(view.Text); viewMenuItem.Click += viewToolStripMenuItem_Click; viewMenuItem.Tag = view; viewMenuItem.Name = view.Text; viewToolStripMenuItem.DropDownItems.Add(viewMenuItem); } ((ToolStripMenuItem)viewToolStripMenuItem.DropDownItems.Find(HelpView.Text, false).First()).ShortcutKeys = Keys.F1; viewToolStripMenuItem.DropDownItems.Add(new ToolStripSeparator()); ToolStripMenuItem resetViewsMenuItem = new ToolStripMenuItem("Reset Views Layout"); resetViewsMenuItem.ShortcutKeys = Keys.Control | Keys.W; resetViewsMenuItem.Click += resetViewsMenuItem_Click; viewToolStripMenuItem.DropDownItems.Add(resetViewsMenuItem); ToolStripMenuItem nodeSettingsMenuItem = new ToolStripMenuItem("Configure node selection..."); nodeSettingsMenuItem.ShortcutKeys = Keys.Control | Keys.L; nodeSettingsMenuItem.Click += nodeSettingsMenuItem_Click; viewToolStripMenuItem.DropDownItems.Add(nodeSettingsMenuItem); modeDropDownList.SelectedIndex = 0; AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 0); AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 10); AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 20); AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 50); AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 100); AddTimerMenuItem(timerToolStripSplitButton, timerItem_Click, 500); timerItem_Click(timerToolStripSplitButton.DropDownItems[Properties.Settings.Default.StepDelay], EventArgs.Empty); AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 0); AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 20); AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 100); AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 500); AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 1000); AddTimerMenuItem(observerTimerToolButton, observerTimerItem_Click, 5000); observerTimerItem_Click(observerTimerToolButton.DropDownItems[Properties.Settings.Default.ObserverPeriod], EventArgs.Empty); PropertyDescriptor descriptor = TypeDescriptor.GetProperties(typeof(MyWorkingNode))["DataFolder"]; EditorAttribute editor = (EditorAttribute)descriptor.Attributes[typeof(EditorAttribute)]; editor.GetType().GetField("typeName", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(editor, typeof(MyFolderDialog).AssemblyQualifiedName); editor.GetType().GetField("baseTypeName", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(editor, typeof(UITypeEditor).AssemblyQualifiedName); autosaveTextBox.Text = Properties.Settings.Default.AutosaveInterval.ToString(); autosaveTextBox_Validating(this, new CancelEventArgs()); autosaveButton.Checked = Properties.Settings.Default.AutosaveEnabled; }
public CustomProperty(string sName, object value, Type type, bool bReadOnly, bool bVisible, string description = null, string category = null, EditorAttribute editor = null) { this.Name = sName; this.Value = value; this.Type = type; this.ReadOnly = bReadOnly; this.Visible = bVisible; this.Description = description; this.Category = category; if (editor != null) { var editorName = editor.EditorTypeName; var editorType = Type.GetType(editorName); Editor = Activator.CreateInstance(editorType) as UITypeEditor; } }
public void TypeId_NullBaseTypeName_ThrowsNullReferenceException() { var attribute = new EditorAttribute("Type", (string)null); Assert.Throws <NullReferenceException>(() => attribute.TypeId); }
private void ExpandBrowsableProperties(object obj) { Type type = obj.GetType(); PropertyInfo[] properties = type.GetProperties(); for (int i = 0; i < properties.Length; i++) { PropertyInfo property = properties[i]; string name = property.Name; object[] attributes = property.GetCustomAttributes(true); bool browsable = true; string category = null; string description = null; string editor = null; string typeConverter = null; for (int j = 0; j < attributes.Length; j++) { BrowsableAttribute browsableAttr = attributes[j] as BrowsableAttribute; if (browsableAttr != null) { browsable = browsableAttr.Browsable; } CategoryAttribute categoryAttr = attributes[j] as CategoryAttribute; if (categoryAttr != null) { category = categoryAttr.Category; } DescriptionAttribute descriptionAttr = attributes[j] as DescriptionAttribute; if (descriptionAttr != null) { description = descriptionAttr.Description; } } if (browsable) { Type propertyType = property.PropertyType; attributes = propertyType.GetCustomAttributes(true); for (int j = 0; j < attributes.Length; j++) { EditorAttribute editorAttr = attributes[j] as EditorAttribute; if (editorAttr != null) { editor = editorAttr.EditorTypeName; } TypeConverterAttribute typeConverterAttr = attributes[j] as TypeConverterAttribute; if (typeConverterAttr != null) { typeConverter = typeConverterAttr.ConverterTypeName; } } // skip the indexer if (property.Name.Equals("Item")) { continue; } if (property.Name.Equals("Chars")) { continue; } // skip non-getter properties if (property.GetGetMethod() == null) { continue; } object value = null; try { value = property.GetValue(obj, null); } catch (TargetInvocationException) { log.Debug("Unable to get value for " + property.Name + " on type = " + type.FullName + " using default type of " + propertyType.Name); value = 0; } switch (state) { case State.Begin: SetupProperty(obj, name, propertyType, value, category, description, editor, typeConverter); break; case State.AfterInitialize: SetupPropertyAfterInitialize(obj, name, propertyType, value, category, description, editor, typeConverter); break; case State.FromProjectFile: SetPropertyFromProjectFile(obj, name, propertyType, value, category, description, editor, typeConverter); break; } } } }
/// <summary> /// Function to retrieve any attributes from this property. /// </summary> private void GetAttributes() { DefaultValueAttribute defaultValue = null; ReadOnlyAttribute readOnly = null; RefreshPropertiesAttribute refresh = null; DescriptionAttribute description = null; CategoryAttribute category = null; EditorAttribute editor = null; TypeConverterAttribute typeConverter = null; DisplayNameAttribute displayName = null; foreach (Attribute attribute in _descriptor.Attributes.Cast <Attribute>()) { if (defaultValue == null) { defaultValue = attribute as DefaultValueAttribute; } if (readOnly == null) { readOnly = attribute as ReadOnlyAttribute; } if (refresh == null) { refresh = attribute as RefreshPropertiesAttribute; } if (description == null) { description = attribute as DescriptionAttribute; } if (category == null) { category = attribute as CategoryAttribute; } if (editor == null) { editor = attribute as EditorAttribute; } if (typeConverter == null) { typeConverter = attribute as TypeConverterAttribute; } if (displayName == null) { displayName = attribute as DisplayNameAttribute; } } if (defaultValue != null) { DefaultValue = defaultValue.Value; } if (readOnly != null) { IsReadOnly = readOnly.IsReadOnly; } if (refresh != null) { RefreshProperties = refresh.RefreshProperties; } if (description != null) { Description = description.Description; } if (category != null) { Category = category.Category; } if (editor != null) { _editorBase = editor.EditorBaseTypeName; Editor = editor.EditorTypeName; } if (displayName != null) { DisplayName = displayName.DisplayName; } if (typeConverter != null) { Converter = typeConverter.ConverterTypeName; } }
public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { PropertyDescriptor[] newProps = new PropertyDescriptor[this.Count]; for (int i = 0; i < this.Count; i++) { CustomProperty prop = (CustomProperty)this[i]; Attribute[] propAttributes = new Attribute[attributes.Length + prop.CustomAttributes.Length]; attributes.CopyTo(propAttributes, 0); prop.CustomAttributes.CopyTo(propAttributes, attributes.Length); for (int p = 0; p < propAttributes.Length; p++) { if (propAttributes[p] is UseColorPicker) { propAttributes[p] = new EditorAttribute(typeof(ColorTypeEditor), typeof(System.Drawing.Design.UITypeEditor)); break; } if (propAttributes[p] is UseWidthPicker) { propAttributes[p] = new EditorAttribute(typeof(PenWidthTypeEditor), typeof(System.Drawing.Design.UITypeEditor)); break; } if (propAttributes[p] is UseDashStylePicker) { propAttributes[p] = new EditorAttribute(typeof(DashStyleTypeEditor), typeof(System.Drawing.Design.UITypeEditor)); break; } if (propAttributes[p] is UseHatchStylePicker) { propAttributes[p] = new EditorAttribute(typeof(HatchStyleTypeEditor), typeof(System.Drawing.Design.UITypeEditor)); break; } if (propAttributes[p] is UseLineSymbolPicker) { propAttributes[p] = new EditorAttribute(typeof(LineSymbolTypeEditor), typeof(System.Drawing.Design.UITypeEditor)); break; } if (propAttributes[p] is UsePointSymbolPicker) { propAttributes[p] = new EditorAttribute(typeof(PointSymbolTypeEditor), typeof(System.Drawing.Design.UITypeEditor)); break; } if (propAttributes[p] is UseCharacterPicker) { propAttributes[p] = new EditorAttribute(typeof(CharacterTypeEditor), typeof(System.Drawing.Design.UITypeEditor)); break; } if (propAttributes[p] is UseFilePicker) { propAttributes[p] = new EditorAttribute(typeof(FileTypeEditor), typeof(System.Drawing.Design.UITypeEditor)); break; } if (propAttributes[p] is UseColorGradientPicker) { propAttributes[p] = new EditorAttribute(typeof(ColorGradientEditor), typeof(System.Drawing.Design.UITypeEditor)); break; } } newProps[i] = new CustomPropertyDescriptor(ref prop, propAttributes); } return(new PropertyDescriptorCollection(newProps)); }