/// <summary> /// Applies the value resulting from this property onto the given Component instance. /// </summary> public void ApplyValue(Component Component) { //Component Component = Entity.Components[ComponentName]; PropertyInfo Property = Component.GetType().GetProperty(PropertyName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy); if(Property == null) throw new KeyNotFoundException("Unable to find a property named '" + PropertyName + "' on Component of type '" + Component.GetType().Name + "'."); object Value = Argument.GetValue(Component, Property); if(!Property.PropertyType.IsAssignableFrom(Value.GetType())) Value = Convert.ChangeType(Value, Property.PropertyType); Property.SetValue(Component, Value, null); }
protected override void ApplyResources(Component component, string componentName, CultureInfo culture) { foreach (PropertyDescriptor descriptor in this.GetLocalizableStringProperties(component.GetType())) { string str = this.GetString(string.Format("{0}.{1}", componentName, descriptor.Name), culture); if (str != null) { descriptor.SetValue(component, str); } } ComboBox box = component as ComboBox; if ((box != null) && (box.DataSource == null)) { string item = this.GetString(string.Format("{0}.Items", box.Name), culture); if (item != null) { int selectedIndex = box.SelectedIndex; box.BeginUpdate(); box.Items.Clear(); int num2 = 1; while (item != null) { box.Items.Add(item); item = this.GetString(string.Format("{0}.Items{1}", box.Name, num2++), culture); } if (selectedIndex < box.Items.Count) { box.SelectedIndex = selectedIndex; } box.EndUpdate(); } } }
/// <summary> /// 为指定控件的属性赋值。 /// </summary> /// <param name="ctl">控件。</param> /// <param name="propertyName">属性名称。</param> /// <param name="value">新值。</param> /// <returns>指定属性的值。</returns> public void SetPropertyValue(System.ComponentModel.Component ctl, string propertyName, object value) { if (this.InvokeRequired) { this.Invoke(new SetPropertyHandler(this.SetPropertyValue), ctl, propertyName, value); } else { ctl.GetType().GetProperty(propertyName).SetValue(ctl, value, null); } }
public void Construct_from_component() { Dispose(); using (var component = new Component()) { DisplaySettings = new DisplaySettings(component); Assert.AreEqual(component.GetType().FullName, DisplaySettings.Name); Assert.IsFalse(DisplaySettings.IsDisposed); } Assert.IsTrue(DisplaySettings.IsDisposed); }
public EventSuppressor(Component source) { if (source == null) throw new ArgumentNullException("control", "An instance of a control must be provided."); _source = source; _sourceType = _source.GetType(); _sourceEventsInfo = _sourceType.GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic); _sourceEventHandlerList = (EventHandlerList)_sourceEventsInfo.GetValue(_source, null); _eventHandlerListType = _sourceEventHandlerList.GetType(); _headFI = _eventHandlerListType.GetField("head", BindingFlags.Instance | BindingFlags.NonPublic); }
public CommandAdapter AddCommandBinding(Component component, ICommand command, Func<object> commandParameterCallback) { if (component == null) { throw new ArgumentNullException("component"); } if (command == null) { throw new ArgumentNullException("command"); } if (commandParameterCallback == null) { throw new ArgumentNullException("commandParameterCallback"); } foreach (CommandBindingFactory factory in factories.Reverse()) { if (factory.CanCreate(component)) { bindings.Add(factory.Create(component, command, commandParameterCallback)); return this; } } throw new NotSupportedException("This component type '" + component.GetType().Name + "' is not supported. Please provide an adapter for this component."); }
private void SetPropertyThreadSafe(System.ComponentModel.Component what, object setto, string property) { if (this.InvokeRequired) { SetPropertyThreadSafeCallback sptscb = new SetPropertyThreadSafeCallback(SetPropertyThreadSafe); try { this.Invoke(sptscb, new object[] { what, setto, property }); } catch (Exception) { // FFFFF! } return; } what.GetType().GetProperty(property).SetValue(what, setto, null); //what.Text = setto; }
protected virtual void RemoveHandler(Component extendee) { // verifico se extendee possiede l'evento click EventInfo clickEvent = extendee.GetType().GetEvent("Click"); if (clickEvent != null) { clickEvent.RemoveEventHandler(extendee, clickEventHandler); } // verifico se extendee possiede l'evento CheckStateChanged EventInfo checkStateChangedEvent = extendee.GetType().GetEvent("CheckStateChanged"); if (checkStateChangedEvent != null) { checkStateChangedEvent.RemoveEventHandler(extendee, checkStateChangedEventHandler); } // Casi particolari // verifico se extendee è un ToolbarButton ToolBarButton button = extendee as ToolBarButton; if (button != null) { button.Parent.ButtonClick -= new ToolBarButtonClickEventHandler(toolbar_ButtonClick); } }
private void updateProperty(Component target, string propertyName, object value) { WorkingState = ActionWorkingState.Driving; try { if (ActionList != null) { if (!SpecialUpdateProperty(target, propertyName, value)) ActionList.TypesDescription[target.GetType()].SetValue( propertyName, target, value); } } finally { WorkingState = ActionWorkingState.Listening; } }
public static IRawElementProviderFragment GetProvider (Component component, bool initialize, bool forceInitializeChildren) { if (component == null) //FIXME: we should throw new ArgumentNullException ("component"); return null; // First check if we've seen this component before IRawElementProviderFragment provider = FindProvider (component); if (provider != null) return provider; // Send a WndProc message to see if the control // implements it's own provider. if (component is SWF.Control // Sending WndProc to a form is broken for some reason && !(component is SWF.Form)) { SWF.Control control = component as SWF.Control; IRawElementProviderSimple simpleProvider; IntPtr result; result = SWF.NativeWindow.WndProc (control.Handle, SWF.Msg.WM_GETOBJECT, IntPtr.Zero, new IntPtr (AutomationInteropProvider.RootObjectId)); if (result != IntPtr.Zero) { simpleProvider = AutomationInteropProvider .RetrieveAndDeleteProvider (result); provider = simpleProvider as IRawElementProviderFragment; if (provider == null) provider = new FragmentControlProviderWrapper (component, simpleProvider); } } ComponentProviderMapperHandler handler = null; Type providerType = null; if (provider == null) { Type typeIter = component.GetType (); // Chain up the type hierarchy until we find // either a type or handler for mapping, or we // hit Control or Component. do { // First see if there's a mapping handler if (componentProviderMappers.TryGetValue (typeIter, out handler)) break; // Next, see if we have a type mapping if (providerComponentMap.TryGetValue (typeIter, out providerType)) break; typeIter = typeIter.BaseType; } while (typeIter != null && typeIter != typeof (System.ComponentModel.Component) && typeIter != typeof (SWF.Control)); } if (handler != null) { provider = handler (component); } // Create the provider if we found a mapping type if (provider == null) { // We meet a unknown custom control type, // then we count it as a Pane if (providerType == null) { var dialog = component as SWF.CommonDialog; if (dialog != null) return GetProvider (dialog.form, initialize, forceInitializeChildren); providerType = typeof (PaneProvider); } try { provider = (FragmentControlProvider) Activator.CreateInstance (providerType, new object [] { component }); } catch (MissingMethodException) { Log.Error ( "Provider {0} does not have a valid single parameter constructor to handle {1}.", providerType, component.GetType () ); return null; } } if (provider != null) { // TODO: Abstract this out? if (component is SWF.Form) { formProviders.Add ((IRawElementProviderFragmentRoot) provider); } // TODO: Make tracking in dictionary optional componentProviders [component] = provider; if (provider is FragmentControlProvider) { FragmentControlProvider frag = (FragmentControlProvider) provider; if (initialize) frag.Initialize (); if (forceInitializeChildren) frag.InitializeChildControlStructure (); } } else { //FIXME: let's not throw while we are developing, a big WARNING will suffice //throw new NotImplementedException ("Provider not implemented for control " + component.GetType().Name); Log.Warn ("Provider not implemented for component " + component.GetType ()); return null; } return provider; }
public SelectToolStripMenuItem(Component c, IServiceProvider provider) { this.comp = c; this.serviceProvider = provider; string fullName = null; if (this.comp != null) { ISite site = this.comp.Site; if (site != null) { INestedSite site2 = site as INestedSite; if ((site2 != null) && !string.IsNullOrEmpty(site2.FullName)) { fullName = site2.FullName; } else if (!string.IsNullOrEmpty(site.Name)) { fullName = site.Name; } } } this.Text = System.Design.SR.GetString("ToolStripSelectMenuItem", new object[] { fullName }); this._itemType = c.GetType(); }
private void UpdateText(Component c, string text) { try { if (null != c) { PropertyInfo pi = c.GetType().GetProperty("Text"); if (null != pi) { pi.SetValue(c, text, null); } } } catch (Exception) { } }
// This removes the specified control from this UICommand. internal void Remove(Component component) { // We must be able to handle any object that UICommandProvider.CanExtend returns true for. _components.Remove(component); if (component is Control) ((Control)component).Click -= ClickForwarderDelegate; else if (component is ToolStripItem) ((ToolStripItem)component).Click -= ClickForwarderDelegate; else throw new ApplicationException("Object has unexpected type " + component.GetType()); }
public void SetAction(Component extendee, Action action) { if (!initializing) { if (extendee == null) throw new ArgumentNullException("extendee"); if (action != null && action.ActionList != this) throw new ArgumentException("The Action you selected is owned by another ActionList"); } /* Se extendee appartiene gi?alla collection, rimuovo l'handler * sul suo evento Click e lo rimuovo dai component associati alla * collection */ if (targets.ContainsKey(extendee)) { targets[extendee].InternalRemoveTarget(extendee); targets.Remove(extendee); } /* Aggiungo extendee alla collection */ if (action != null) { // eventualmente aggiungo le informazioni sul tipo if (!typesDescription.ContainsKey(extendee.GetType())) { typesDescription.Add(extendee.GetType(), new ActionTargetDescriptionInfo(extendee.GetType())); } targets.Add(extendee, action); action.InternalAddTarget(extendee); } }
/// <summary> /// コマンドのバインディングを追加します。 /// </summary> public static CommandBindingBase AddCommandBinding(Component component, ICommand command, Func<object> commandParameterCallback) { if (component == null) { throw new ArgumentNullException("component"); } if (command == null) { throw new ArgumentNullException("command"); } if (commandParameterCallback == null) { throw new ArgumentNullException("commandParameterCallback"); } foreach (var factory in factories) { if (factory.CanCreate(component)) { var binding = factory.Create(component, command, commandParameterCallback); bindings.Add(binding); return binding; } } throw new NotSupportedException( string.Format( "コンポ―ネント'{0}'はコマンドバインディングに対応していません。", component.GetType().Name)); }
private static PropertyInfo FindTemplateProperty(Component Template, string Name) { Name = Name.ToUpper(); foreach (PropertyInfo i in Template.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) { // Check all the parameter aliases for this parameter. foreach (ParameterAlias j in i.CustomAttributes<ParameterAlias>()) if (Name == j.Alias) return i; // Check the name itself. if (Name == i.Name.ToUpper()) return i; } return null; }
private static string GetNameFromComponent(Component component) { Verify.ArgumentNotNull(component, "component"); return component.GetType().FullName; }
/// <summary> /// Serializes a component to a source code in the language specified in the <see cref="LiteDevelop.Essentials.FormsDesigner.DesignerCodeWriter.Language"/> property. /// </summary> /// <param name="namespace">The namespace to create the code in.</param> /// <param name="instance">The object to be serialized.</param> /// <param name="container">The container object.</param> /// <param name="includeBaseType">Include the base type of the instance in the to be generated source.</param> /// <returns></returns> public string SerializeCode(string @namespace, Component instance, IContainer container, bool includeBaseType) { // Create new namespace CodeNamespace codeNamespace = new CodeNamespace(@namespace); // Create new class. CodeTypeDeclaration controlType = new CodeTypeDeclaration(instance.Site.Name) { Attributes = MemberAttributes.Public, IsClass = true, IsPartial = true, }; if (includeBaseType) controlType.BaseTypes.Add(new CodeTypeReference(instance.GetType())); // generate fields for members. controlType.Members.AddRange(GenerateMembers(container)); // generate initializecomponent(). controlType.Members.Add(GenerateInitializeComponentMethod(instance, container)); // add class to namespace. codeNamespace.Types.Add(controlType); string code = string.Empty; using (MemoryStream stream = new MemoryStream()) { using (StreamWriter writer = new StreamWriter(stream)) { using (IndentedTextWriter codeWriter = new IndentedTextWriter(writer, " ")) { CodeDomProvider provider = Language.CodeProvider; using (provider) { // generate source code. provider.GenerateCodeFromNamespace(codeNamespace, codeWriter, new CodeGeneratorOptions() { BlankLinesBetweenMembers = true, BracingStyle = "C", // use new lines on brackets. }); } } // write data to stream. writer.Flush(); // read stream contents to get code. stream.Position = 0; using (StreamReader reader = new StreamReader(stream)) { code = reader.ReadToEnd(); } } } propertySerializer.TemporaryVariables.Clear(); return code; }
static void ReflectComponent( Component co ) { Type t = co.GetType(); //FieldInfo [] fields = t.GetFields(BindingFlags.GetField | BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static ); FieldInfo [] fields = t.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static); foreach( FieldInfo fld in fields ) { object o = fld.GetValue(co); if( null != o ) { Type tt = o.GetType(); if( Component.CheckType(tt) ) { Console.WriteLine( "Field {0} [{1}] value {2}", fld.Name, tt, o ); } } } }
public void SetAction(Component extendee, UIAction action) { if (!initializing) { if (extendee == null) throw new ArgumentNullException("extendee"); if (action != null && action.ActionList != this) throw new ArgumentException("The Action you selected is owned by another ActionList"); } if (targets.ContainsKey(extendee)) { targets[extendee].InternalRemoveTarget(extendee); targets.Remove(extendee); } if (action != null) { if (!typesDescription.ContainsKey(extendee.GetType())) typesDescription.Add( extendee.GetType(), new UIActionTargetDescriptor(extendee.GetType())); targets.Add(extendee, action); action.InternalAddTarget(extendee); } }
protected virtual void RemoveHandler(Component extendee) { EventInfo clickEvent = extendee.GetType().GetEvent("Click"); if (clickEvent != null) clickEvent.RemoveEventHandler(extendee, clickEventHandler); EventInfo checkStateChangedEvent = extendee.GetType().GetEvent("CheckStateChanged"); if (checkStateChangedEvent != null) checkStateChangedEvent.RemoveEventHandler(extendee, checkStateChangedEventHandler); // Cas particulier : bouton de barre d'outils ToolBarButton button = extendee as ToolBarButton; if (button != null) button.Parent.ButtonClick -= new ToolBarButtonClickEventHandler(toolbar_ButtonClick); }
// This attaches the specified control to this UICommand. internal void Add(Component component) { // We must be able to handle any object that UICommandProvider.CanExtend returns true for. if (component is Control) { ((Control)component).Click += ClickForwarderDelegate; ((Control)component).Enabled = _enabled; } else if (component is ToolStripItem) { ((ToolStripItem)component).Click += ClickForwarderDelegate; ((ToolStripItem)component).Enabled = _enabled; } else throw new ApplicationException("Object has unexpected type " + component.GetType()); _components.Add(component); }
internal void Attach(Action a, Component o, bool designMode) { Debug.Assert(o != null && a != null); component = o; action = a; _designMode = designMode; Debug.Assert(action.Parent != null); // Text textWrapper.Attach(component, "Text"); Text = action.Text; // Enabled enabledWrapper.Attach(component, "Enabled"); Enabled = action.Enabled; // Checked // special case of a toolbarButton if (component is ToolBarButton) { checkedWrapper.Attach(component, "Pushed"); } else { checkedWrapper.Attach(component, "Checked"); } Checked = action.Checked; // Visible visibleWrapper.Attach(component, "Visible"); Visible = action.Visible; // Shortcut _shortcut = o.GetType().GetProperty("Shortcut"); if (_shortcut != null && (!_shortcut.CanRead || !_shortcut.CanWrite) && (_shortcut.PropertyType == typeof(Keys))) { // we must be able to read and write a shortcut property _shortcut = null; } Shortcut = action.Shortcut; _shortcutkeys = o.GetType().GetProperty("ShortcutKeys"); if (_shortcutkeys != null && (!_shortcutkeys.CanRead || !_shortcutkeys.CanWrite) && (_shortcutkeys.PropertyType == typeof(Keys))) { // we must be able to read and write a shortcut property _shortcutkeys = null; } ShortcutKeys = action.Shortcut; _shortcuts = o.GetType().GetProperty("Shortcuts"); if (_shortcuts != null && (!_shortcuts.CanRead || !_shortcuts.CanWrite) && (_shortcuts.PropertyType == typeof(ShortcutKeysCollection))) { // we must be able to read and write a shortcut property _shortcuts = null; } Shortcuts = action.Shortcuts; _shortcutkeydisplaystring = o.GetType().GetProperty("ShortcutKeyDisplayString"); if (_shortcutkeydisplaystring != null && (!_shortcutkeydisplaystring.CanRead || !_shortcutkeydisplaystring.CanWrite) && (_shortcutkeydisplaystring.PropertyType == typeof(string))) { // we must be able to read and write a shortcut property _shortcutkeydisplaystring = null; } UpdateShortcutKeyDisplayString(); // ImageList // don't handle toolbarButtons here if (!(component is ToolBarButton)) { _imageList = o.GetType().GetProperty("ImageList"); if (_imageList != null && (!_imageList.CanRead || !_imageList.CanWrite) && (_imageList.PropertyType == typeof(ImageList))) { // we must be able to read and write an ImageList property _imageList = null; } } ImageList = action.Parent.ImageList; // ImageIndex _imageIndex = o.GetType().GetProperty("ImageIndex"); if (_imageIndex != null && (!_imageIndex.CanRead || !_imageIndex.CanWrite) && (_imageIndex.PropertyType == typeof(int))) { // we must be able to read and write an integer property _imageIndex = null; } ImageIndex = action.ImageIndex; //image if (_imageIndex == null || o is ToolStripItem) { _image = o.GetType().GetProperty("Image"); _imageTransparentColor = o.GetType().GetProperty("ImageTransparentColor"); if (_image != null && (!_image.CanRead || !_image.CanWrite) && (_image.PropertyType == typeof(Image)) && _imageTransparentColor != null && (!_imageTransparentColor.CanRead || !_imageTransparentColor.CanWrite) && (_imageTransparentColor.PropertyType == typeof(Color)) ) { _image = null; _imageTransparentColor = null; } UpdateImage(); } // Hint Hint = action.Hint; // click if (!designMode) { // special case of a toolbarButton if (component is ToolBarButton) { ToolBar tb = ((ToolBarButton)component).Parent; if (tb != null) { tb.ButtonClick += new ToolBarButtonClickEventHandler(OnToolbarClick); _click = true; } } else { EventInfo e = o.GetType().GetEvent("Click"); if (e != null && e.EventHandlerType == typeof(EventHandler)) { e.AddEventHandler(component, new EventHandler(action.OnExecute)); _click = true; } if(component is System.Windows.Forms.MenuItem) { OwnerDrawMenus = action.Parent.OwnerDrawMenus; } } } // Dispose Debug.Assert(action.Parent != null); component.Disposed += new EventHandler(action.Parent.OnComponentDisposed); }