// Copyright (C) Stichting Deltares 2018. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using Deltares.Standard.Extensions;
namespace Deltares.Standard.Specifications
{
///
/// Defines the abstract base class for the specification attributes
/// to derive more specific types from
///
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Property, Inherited = true, AllowMultiple = true)]
public abstract class SpecificationBaseAttribute : Attribute
{
private readonly ISpecification specification;
protected SpecificationBaseAttribute(Type specification, params object[] args)
{
if (args == null && !specification.HasDefaultConstructor())
throw new ArgumentException("The specification type should have a default constructor or supply ");
if (!typeof(ISpecification).IsAssignableFrom(specification))
throw new ArgumentException("The specification type should implement interface ISpecification");
this.specification = Activator.CreateInstance(specification, args) as ISpecification;
}
protected SpecificationBaseAttribute(Type specification) : this(specification, null)
{
}
///
/// Gets or sets the name of the specification.
///
/// If this property is not set, the name of the specification (when available) will be used
///
/// The name.
///
public string Name { get; set; }
///
/// Gets or sets the text in case the specification is not satisfied
///
/// If this property is not set, the description of the specification (when available) will be used
///
/// The not satisfied text.
///
public string NotSatisfiedText { get; set; }
public string GroupName { get; set; }
// This is a positional argument
public ISpecification Specification
{
get { return this.specification; }
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
public sealed class SpecificationAttribute : SpecificationBaseAttribute
{
public SpecificationAttribute(Type specification, params object[] args)
: base(specification, args)
{
}
public SpecificationAttribute(Type specification) : base(specification)
{
}
}
}