protected virtual string[] GetExtensions() { ArrayList list = new ArrayList(); foreach (Type extender in GetImageExtenders()) { // Skip invalid extenders. if (extender == null || !typeof(ImageEditor).IsAssignableFrom(extender)) { continue; } ImageEditor e = (ImageEditor)Activator.CreateInstance(extender, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, null, null); if (e.GetType() != typeof(ImageEditor)) { string[] extensions = e.GetExtensions(); if (extensions != null) { list.AddRange(extensions); } } } return((string[])list.ToArray(typeof(string))); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (!provider.TryGetService(out IWindowsFormsEditorService editorService)) { return(value); } if (_fileDialog is null) { _fileDialog = new OpenFileDialog(); string filter = CreateFilterEntry(this); foreach (Type extender in GetImageExtenders()) { // Skip invalid extenders. if (extender is null || !typeof(ImageEditor).IsAssignableFrom(extender)) { continue; } ImageEditor e = (ImageEditor)Activator.CreateInstance( extender, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, null, null); Type myClass = GetType(); if (!myClass.Equals(e.GetType()) && e != null && myClass.IsInstanceOfType(e)) { filter += $"|{CreateFilterEntry(e)}"; } } _fileDialog.Filter = filter; } IntPtr hwndFocus = User32.GetFocus(); try { if (_fileDialog.ShowDialog() == DialogResult.OK) { using FileStream stream = new(_fileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read); value = LoadFromStream(stream); } } finally { if (hwndFocus != IntPtr.Zero) { User32.SetFocus(hwndFocus); } } return(value); }
/// <summary> /// Edits the given object value using the editor style provided by /// GetEditorStyle. A service provider is provided so that any /// required editing services can be obtained. /// </summary> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { if (provider.GetService(typeof(IWindowsFormsEditorService)) is IWindowsFormsEditorService edSvc) { if (_fileDialog == null) { _fileDialog = new OpenFileDialog(); string filter = CreateFilterEntry(this); foreach (Type extender in GetImageExtenders()) { // Skip invalid extenders. if (extender == null || !typeof(ImageEditor).IsAssignableFrom(extender)) { continue; } ImageEditor e = (ImageEditor)Activator.CreateInstance(extender, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, null, null); Type myClass = GetType(); if (!myClass.Equals(e.GetType()) && e != null && myClass.IsInstanceOfType(e)) { filter += "|" + CreateFilterEntry(e); } } _fileDialog.Filter = filter; } IntPtr hwndFocus = UnsafeNativeMethods.GetFocus(); try { if (_fileDialog.ShowDialog() == DialogResult.OK) { using (var file = new FileStream(_fileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { value = LoadFromStream(file); } } } finally { if (hwndFocus != IntPtr.Zero) { UnsafeNativeMethods.SetFocus(new HandleRef(null, hwndFocus)); } } } } return(value); }
protected virtual string[] GetExtensions() { ArrayList list = new ArrayList(); for (int i = 0; i < this.GetImageExtenders().Length; i++) { ImageEditor editor = (ImageEditor)Activator.CreateInstance(this.GetImageExtenders()[i], BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, null, null); if (!editor.GetType().Equals(typeof(ImageEditor))) { list.AddRange(new ArrayList(editor.GetExtensions())); } } return((string[])list.ToArray(typeof(string))); }
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] // everything in this assembly is full trust. protected virtual string[] GetExtensions() { // We should probably smash them together... ArrayList list = new ArrayList(); for (int i = 0; i < GetImageExtenders().Length; i++) { ImageEditor e = (ImageEditor)Activator.CreateInstance(GetImageExtenders()[i], BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, null, null); //.CreateInstance(); if (e.GetType() != typeof(ImageEditor)) { list.AddRange(new ArrayList(e.GetExtensions())); } } return((string[])list.ToArray(typeof(string))); }
[SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")] // everything in this assembly is full trust. public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc != null) { if (fileDialog == null) { fileDialog = new OpenFileDialog(); string filter = CreateFilterEntry(this); for (int i = 0; i < GetImageExtenders().Length; i++) { ImageEditor e = (ImageEditor)Activator.CreateInstance(GetImageExtenders()[i], BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance, null, null, null); //.CreateInstance(); Type myClass = this.GetType(); Type editorClass = e.GetType(); if (!myClass.Equals(editorClass) && e != null && myClass.IsInstanceOfType(e)) { filter += "|" + CreateFilterEntry(e); } } fileDialog.Filter = filter; } IntPtr hwndFocus = UnsafeNativeMethods.GetFocus(); try { if (fileDialog.ShowDialog() == DialogResult.OK) { FileStream file = new FileStream(fileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read); value = LoadFromStream(file); } } finally { if (hwndFocus != IntPtr.Zero) { UnsafeNativeMethods.SetFocus(new HandleRef(null, hwndFocus)); } } } } return(value); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if ((provider != null) && (((IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService))) != null)) { if (this.fileDialog == null) { this.fileDialog = new OpenFileDialog(); string str = CreateFilterEntry(this); for (int i = 0; i < this.GetImageExtenders().Length; i++) { ImageEditor o = (ImageEditor)Activator.CreateInstance(this.GetImageExtenders()[i], BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, null, null); System.Type type = base.GetType(); System.Type type2 = o.GetType(); if ((!type.Equals(type2) && (o != null)) && type.IsInstanceOfType(o)) { str = str + "|" + CreateFilterEntry(o); } } this.fileDialog.Filter = str; } IntPtr focus = System.Drawing.Design.UnsafeNativeMethods.GetFocus(); try { if (this.fileDialog.ShowDialog() == DialogResult.OK) { FileStream stream = new FileStream(this.fileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read); value = this.LoadFromStream(stream); } } finally { if (focus != IntPtr.Zero) { System.Drawing.Design.UnsafeNativeMethods.SetFocus(new HandleRef(null, focus)); } } } return(value); }