public FormatEnumerator(IDataObject parent, FORMATETC[] formats) { Debug.WriteLineIf(CompModSwitches.DataObject.TraceVerbose, "FormatEnumerator: Constructed: " + parent.ToString() + ", FORMATETC[]" + formats.Length.ToString(CultureInfo.InvariantCulture)); this.formats.Clear(); this.parent = parent; current = 0; if (formats != null) { if (parent is DataObject dataObject && dataObject.RestrictedFormats) { if (!Clipboard.IsFormatValid(formats)) { throw new Security.SecurityException(SR.ClipboardSecurityException); } } for (int i = 0; i < formats.Length; i++) { FORMATETC currentFormat = formats[i]; FORMATETC temp = new FORMATETC { cfFormat = currentFormat.cfFormat, dwAspect = currentFormat.dwAspect, ptd = currentFormat.ptd, lindex = currentFormat.lindex, tymed = currentFormat.tymed }; this.formats.Add(temp); } } }
public FormatEnumerator(IDataObject parent, string[] formats) { Debug.WriteLineIf(CompModSwitches.DataObject.TraceVerbose, "FormatEnumerator: Constructed: " + parent.ToString() + ", string[]" + formats.Length.ToString(CultureInfo.InvariantCulture)); this.parent = parent; this.formats.Clear(); if (formats != null) { if (parent is DataObject dataObject && dataObject.RestrictedFormats) { if (!Clipboard.IsFormatValid(formats)) { throw new Security.SecurityException(SR.ClipboardSecurityException); } } for (int i = 0; i < formats.Length; i++) { string format = formats[i]; FORMATETC temp = new FORMATETC { cfFormat = unchecked ((short)(ushort)(DataFormats.GetFormat(format).Id)), dwAspect = DVASPECT.DVASPECT_CONTENT, ptd = IntPtr.Zero, lindex = -1 }; if (format.Equals(DataFormats.Bitmap)) { temp.tymed = TYMED.TYMED_GDI; } else if (format.Equals(DataFormats.EnhancedMetafile)) { temp.tymed = TYMED.TYMED_ENHMF; } else if (format.Equals(DataFormats.Text) || format.Equals(DataFormats.UnicodeText) || format.Equals(DataFormats.StringFormat) || format.Equals(DataFormats.Rtf) || format.Equals(DataFormats.CommaSeparatedValue) || format.Equals(DataFormats.FileDrop) || format.Equals(CF_DEPRECATED_FILENAME) || format.Equals(CF_DEPRECATED_FILENAMEW)) { temp.tymed = TYMED.TYMED_HGLOBAL; } else { temp.tymed = TYMED.TYMED_HGLOBAL; } if (temp.tymed != 0) { this.formats.Add(temp); } } } }