using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SharpGL.Version
{
///
/// Allows a version to be specified as metadata on a field.
///
[AttributeUsage(AttributeTargets.Field)]
public class VersionAttribute : Attribute
{
private readonly int major;
private readonly int minor;
///
/// Initializes a new instance of the class.
///
/// The major version number.
/// The minor version number.
public VersionAttribute(int major, int minor)
{
this.major = major;
this.minor = minor;
}
///
/// Determines whether this version is at least as high as the version specified in the parameters.
///
/// The major version.
/// The minor version.
/// True if this version object is at least as high as the version specified by and .
public bool IsAtLeastVersion(int major, int minor)
{
// If major versions match, we care about minor. Otherwise, we only care about major.
if (this.major == major)
return this.major >= major && this.minor >= minor;
return this.major >= major;
}
///
/// Gets the version attribute of an enumeration value .
///
/// The enumeration.
/// The defined on , or null of none exists.
public static VersionAttribute GetVersionAttribute(Enum enumeration)
{
// Get the attribute from the enumeration value (if it exists).
return enumeration
.GetType()
.GetMember(enumeration.ToString())
.Single()
.GetCustomAttributes(typeof(VersionAttribute), false)
.OfType()
.FirstOrDefault();
}
///
/// Gets the major version number.
///
public int Major
{
get { return major; }
}
///
/// Gets the minor version number.
///
public int Minor
{
get { return minor; }
}
}
}