System.Windows.Forms.IDataObject.ContainsString()

Here are the examples of the csharp api class System.Windows.Forms.IDataObject.ContainsString() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

1. Example

Project: duality
Source File: ExtMethodsDataObject.cs
View license
public static bool ContainsIColorData(this IDataObject data)
		{
			if (data.GetWrappedDataPresent(typeof(IColorData[])))
				return true;

			if (data.ContainsString())
			{
				string valString = data.GetString();
				string[] token = valString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
				byte[] valToken = new byte[4];
				valToken[3] = 255;

				bool success = true;
				for (int i = 0; i < token.Length; i++)
				{
					token[i] = token[i].Trim();
					if (!byte.TryParse(token[i], out valToken[i]))
					{
						success = false;
						break;
					}
				}

				if (success) return true;
			}

			return false;
		}

2. Example

Project: duality
Source File: ExtMethodsDataObject.cs
View license
public static T[] GetIColorData<T>(this IDataObject data) where T : IColorData
		{
			IColorData[] clrArray = null;
			if (data.GetWrappedDataPresent(typeof(IColorData[])))
			{
				clrArray = data.GetWrappedData(typeof(IColorData[])) as IColorData[];
			}
			else if (data.ContainsString())
			{
				string valString = data.GetString();
				string[] token = valString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
				byte[] valToken = new byte[4];
				valToken[3] = 255;

				bool success = true;
				for (int i = 0; i < token.Length; i++)
				{
					token[i] = token[i].Trim();
					if (!byte.TryParse(token[i], out valToken[i]))
					{
						success = false;
						break;
					}
				}

				if (success) clrArray = new IColorData[] { new ColorRgba(valToken[0], valToken[1], valToken[2], valToken[3]) };
			}

			if (clrArray != null)
			{
				// Don't care which format? Great, just return the array as is
				if (typeof(T) == typeof(IColorData)) return (T[])(object)clrArray;
				// Convert to specific format
				return clrArray.Select<IColorData,T>(ic => ic is T ? (T)ic : ic.ConvertTo<T>()).ToArray();
			}
			else
				return null;
		}