1

I stumbled upon this method

Clipboard.GetDataObject()

It returns an IDataObject so I figured there (maybe) was already a Class implementing the IDataObject Interface in the .net framework, but how can I find it?

user1509229
  • 53
  • 1
  • 8
  • Search your solution for `IDataObject`. If it's in a DLL; then you won't be able to find the code unless you get the source. – user1477388 Sep 02 '14 at 13:10
  • http://www.codeproject.com/Articles/896/Using-the-clipboard-to-transfer-data-to-and-from-y – Dhaval Patel Sep 02 '14 at 13:10
  • 1
    Do you mean using reflection or Visual Studio? – Liath Sep 02 '14 at 13:12
  • 2
    There are multiple interfaces named `IDataObject`. Notably, `System.Windows.Forms.IDataObject`, and `System.Windows.IDataObject`. There is a corresponding class in each of those namespaces called `DataObject` implementing the interface. – Mike Zboray Sep 02 '14 at 13:17
  • If you looks at the [source for `GetDataObject`](http://referencesource.microsoft.com/#System.Windows.Forms/ndp/fx/src/winforms/Managed/System/WinForms/Clipboard.cs) you'll find that it returns a [`DataObject`](http://msdn.microsoft.com/en-us/library/System.Windows.Forms.DataObject(v=vs.110).aspx) object. What do you intend to do with it? – D Stanley Sep 02 '14 at 13:17
  • @Liath In visual studio? – user1509229 Sep 02 '14 at 13:19
  • Do you mean you need a way to **find** derived types of "IDataObject" within Visual Studio? – Teknikaali Sep 02 '14 at 13:22
  • I'm not sure why I got downvoted, no one mentionned object browser in the duplicate question. – user1509229 Sep 03 '14 at 21:19

3 Answers3

3

The whole point of an interface is that you do not have to know a specific class. just use

IDataObject myData = Clipboard.GetDataObject();
ths
  • 2,858
  • 1
  • 16
  • 21
1

If you need to find the derived types for IDataObject inside Visual Studio, you can use the Object Browser (View -> Object Browser).

Type "IDataObject" to the search box and select the .NET Framework version you need from the "Browse" dropdown list.

Expand the results and you should see "Derived Types" folder which should give you an answer.

Teknikaali
  • 135
  • 2
  • 11
0

If you want to know the real object behind the interface you can use:

var obj = Clipboard.GetDataObject();
var str = obj.GetType().ToString();
//I tried in a Windows Forms project and the type behind it is "System.Windows.Forms.DataObject"

But it doesn't have much value in this case (i think). See @speising answer :)

Diego
  • 666
  • 1
  • 8
  • 27