Files
DP44/Common/DTS.Common/.svn/pristine/c6/c6c76a8c1a45fa2ed8f0c1119b23068a462b7662.svn-base

71 lines
2.5 KiB
Plaintext
Raw Normal View History

2026-04-17 14:55:32 -04:00
using System;
using System.ComponentModel;
using System.Globalization;
namespace DTS.Common.Classes.DSP
{
/// <summary>
/// this converter is used to display DSPFilterCollection in a property grid
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S101:Types should be named in PascalCase", Justification = "Acronym")]
public class DSPFilterConverter : ArrayConverter
{
private DSPFilterCollection _collection = null;
private static readonly object MyLock = new object();
private DSPFilterType[] _values = null;
private DSPFilterCollection GetCollection()
{
lock (MyLock)
{
if (null == _collection)
{
_collection = DSPFilterCollection.GetDSPFilterCollection();
}
return _collection;
}
}
public DSPFilterType [] Values
{
get
{
lock (MyLock)
{
if (null == _values)
{
var collection = GetCollection();
var array = new DSPFilterType[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);
}
}
}