using System;
using System.Reflection;
namespace Elsa.Testing.Shared.AutoFixture.SpecimenBuilders
{
///
/// Convenience methods for specimen builders. You're only likey to want to use these extensions
/// within a specimen builder class.
///
public static class AutofixtureRequestExtensions
{
///
/// Gets a value which indicates if the specified qualifies as an Autofixture
/// request for an instance of the specified generic type.
///
/// The request object
/// The desired specimen type
/// true if the is a request for an instance of ; false otherwise.
public static bool IsAnAutofixtureRequestForType(this object request) => request.IsAnAutofixtureRequestForType(typeof(T));
///
/// Gets a value which indicates if the specified qualifies as an Autofixture
/// request for an instance of the specified generic type.
///
/// The request object
/// The desired specimen type
/// true if the is a request for an instance of ; false otherwise.
public static bool IsAnAutofixtureRequestForType(this object request, Type type)
{
if(Equals(request, type))
return true;
if(request is ParameterInfo paramInfo && paramInfo.ParameterType == type)
return true;
return false;
}
}
}