//evaluate a filter attribute against a list, and check whther permitted
private bool FilterPermitted(ToolboxItemFilterAttribute desFa, ICollection filterAgainst, object rootDesigner)
{
switch (desFa.FilterType) {
case ToolboxItemFilterType.Allow:
//this is really for matching some other filter string against
return true;
case ToolboxItemFilterType.Custom:
IToolboxUser tbUser = rootDesigner as IToolboxUser;
if (tbUser == null)
throw new ArgumentException ("Host's root designer does not support IToolboxUser interface.");
return EvaluateCustomFilter (tbUser);
case ToolboxItemFilterType.Prevent:
//if host and toolboxitem have same filterstring, then not permitted
foreach (ToolboxItemFilterAttribute itemFa in filterAgainst)
if (desFa.Match (itemFa))
return false;
return true;
case ToolboxItemFilterType.Require:
//if host and toolboxitem have same filterstring, then permitted, unless one is prevented
foreach (ToolboxItemFilterAttribute itemFa in filterAgainst)
if (desFa.Match (itemFa) && (desFa.FilterType != ToolboxItemFilterType.Prevent))
return true;
return false;
}
throw new InvalidOperationException ("Unexpected ToolboxItemFilterType value.");
}