71 lines
2.4 KiB
Plaintext
71 lines
2.4 KiB
Plaintext
using System;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
|
|
namespace DTS.Common.Classes.DSP
|
|
{
|
|
/// <summary>
|
|
/// this converter is used for displaying StreamingFilterCollection/array in property grids
|
|
/// </summary>
|
|
public class StreamingFilterConverter : ArrayConverter
|
|
{
|
|
private StreamingFilterProfileCollection _collection = null;
|
|
private static readonly object MyLock = new object();
|
|
private StreamingFilterProfile[] _values = null;
|
|
private StreamingFilterProfileCollection GetCollection()
|
|
{
|
|
lock (MyLock)
|
|
{
|
|
if (null == _collection)
|
|
{
|
|
_collection = StreamingFilterProfileCollection.GetCollection();
|
|
}
|
|
return _collection;
|
|
}
|
|
}
|
|
public StreamingFilterProfile[] Values
|
|
{
|
|
get
|
|
{
|
|
lock (MyLock)
|
|
{
|
|
if (null == _values)
|
|
{
|
|
var collection = GetCollection();
|
|
|
|
var array = new StreamingFilterProfile[collection.Count];
|
|
collection.CopyTo(array, 0);
|
|
_values = array;
|
|
}
|
|
}
|
|
return _values;
|
|
}
|
|
}
|
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
|
|
{
|
|
if (sourceType == typeof(string)) { return true; }
|
|
return base.CanConvertFrom(context, sourceType);
|
|
}
|
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
|
|
{
|
|
var result = Array.Find(Values, x => x.DisplayString == (string)value);
|
|
if (result != null) { return result; }
|
|
return base.ConvertFrom(context, culture, value);
|
|
}
|
|
|
|
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
|
|
{
|
|
return true;
|
|
}
|
|
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
|
|
{
|
|
return true;
|
|
}
|
|
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
|
|
{
|
|
var collection = GetCollection();
|
|
return new StandardValuesCollection(collection);
|
|
}
|
|
}
|
|
}
|