// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.MixedReality.Toolkit.Utilities;
#if WINDOWS_UWP && !ENABLE_IL2CPP
using Microsoft.MixedReality.Toolkit;
#endif // WINDOWS_UWP && !ENABLE_IL2CPP
using System;
namespace Microsoft.MixedReality.Toolkit
{
///
/// Constraint that allows selection of classes that implement a specific interface
/// when selecting a with the Unity inspector.
///
public sealed class ImplementsAttribute : SystemTypeAttribute
{
///
/// Gets the type of interface that selectable classes must implement.
///
public Type InterfaceType { get; private set; }
///
/// Initializes a new instance of the class.
///
/// Type of interface that selectable classes must implement.
/// Gets or sets grouping of selectable classes. Defaults to unless explicitly specified.
public ImplementsAttribute(Type interfaceType, TypeGrouping grouping) : base(interfaceType, grouping)
{
InterfaceType = interfaceType;
}
///
public override bool IsConstraintSatisfied(Type type)
{
if (base.IsConstraintSatisfied(type))
{
var interfaces = type.GetInterfaces();
for (var i = 0; i < interfaces.Length; i++)
{
if (interfaces[i] == InterfaceType)
{
return true;
}
}
}
return false;
}
}
}