Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
PackageVersionRangeExtensions.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 
5 namespace SiliconStudio.Assets
6 {
7  public static class PackageVersionRangeExtensions
8  {
9  public static Func<Package, bool> ToFilter(this PackageVersionRange versionInfo)
10  {
11  if (versionInfo == null)
12  {
13  throw new ArgumentNullException("versionInfo");
14  }
15  return versionInfo.ToFilter<Package>(p => p.Meta.Version);
16  }
17 
18  public static Func<T, bool> ToFilter<T>(this PackageVersionRange versionInfo, Func<T, PackageVersion> extractor)
19  {
20  if (versionInfo == null)
21  {
22  throw new ArgumentNullException("versionInfo");
23  }
24  if (extractor == null)
25  {
26  throw new ArgumentNullException("extractor");
27  }
28 
29  return p =>
30  {
31  PackageVersion version = extractor(p);
32  bool condition = true;
33  if (versionInfo.MinVersion != null)
34  {
35  if (versionInfo.IsMinInclusive)
36  {
37  condition = version >= versionInfo.MinVersion;
38  }
39  else
40  {
41  condition = version > versionInfo.MinVersion;
42  }
43  }
44 
45  if (versionInfo.MaxVersion != null)
46  {
47  if (versionInfo.IsMaxInclusive)
48  {
49  condition = condition && version <= versionInfo.MaxVersion;
50  }
51  else
52  {
53  condition = condition && version < versionInfo.MaxVersion;
54  }
55  }
56 
57  return condition;
58  };
59  }
60  }
61 }
static Func< Package, bool > ToFilter(this PackageVersionRange versionInfo)
A package managing assets.
Definition: Package.cs:28
A hybrid implementation of SemVer that supports semantic versioning as described at http://semver...
A dependency to a range of version.