init
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user