我熟悉 C# 中的泛型和泛型约束等,至少在我看到这个之前我是这么认为的。我在 Fluent Validation Library 中查看这个接口,它让我很震惊,这行代码是什么意思?
public interface IValidator<in T> : IValidator, IEnumerable<IValidationRule>, IEnumerable
特别是<in T>
代码片段。
这是完整的界面供参考。(http://fluentvalidation.codeplex.com/SourceControl/latest#src/FluentValidation/IValidator.cs)
#region
Assembly FluentValidation.dll, v4.0.30319
#endregion
using FluentValidation.Results;
using System.Collections;
using System.Collections.Generic;
namespace FluentValidation
{
// Summary:
// Defines a validator for a particualr type.
//
// Type parameters:
// T:
public interface IValidator<in T> : IValidator, IEnumerable<IValidationRule>, IEnumerable
{
// Summary:
// Sets the cascade mode for all rules within this validator.
CascadeMode CascadeMode { get; set; }
// Summary:
// Validates the specified instance.
//
// Parameters:
// instance:
// The instance to validate
//
// Returns:
// A ValidationResult object containing any validation failures.
ValidationResult Validate(T instance);
}
}