5
// Lluis Sanchez <lluis@xamarin.com>
7
// Copyright (c) 2012 Xamarin Inc
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using System.Collections.Generic;
31
using System.Runtime.Serialization.Formatters.Binary;
39
/// Data type to be used in drag & drop and copy & paste operations
41
public class TransferDataType
46
/// The URI data type. This is used for file and url copy and drag operations
48
public static readonly TransferDataType Uri = FromId ("uri");
51
/// The text data type
53
public static readonly TransferDataType Text = FromId ("text");
58
public static readonly TransferDataType Rtf = FromId ("rtf");
61
/// The image data type
63
public static readonly TransferDataType Image = FromId ("image");
65
private TransferDataType (string id)
71
/// Gets the identifier of the data type
81
/// Creates a data type using a custom identifier
86
/// <param name='name'>
89
public static TransferDataType FromId (string id)
91
return new TransferDataType (id);
95
/// Creates a transfer data type from a CLR type
100
/// <param name='type'>
104
/// This is the data type to be used when transferring
105
/// whole objects through drag & drop or copy & paste
107
public static TransferDataType FromType (Type type)
109
if (type == typeof(string))
110
return TransferDataType.Text;
111
else if (type == typeof(Xwt.Drawing.Image))
112
return TransferDataType.Image;
114
return FromId (type.AssemblyQualifiedName);
117
public override bool Equals (object obj)
119
TransferDataType t = obj as TransferDataType;
120
return t != null && t.id == id;
123
public override int GetHashCode ()
125
return id.GetHashCode ();
128
public static bool operator == (TransferDataType c1, TransferDataType c2)
130
if (object.ReferenceEquals (c1, c2))
133
if ((object)c1 == null || (object)c2 == null)
136
return c1.id == c2.id;
139
public static bool operator != (TransferDataType c1, TransferDataType c2)