Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ParamFilter.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 using System.Collections;
5 using System.Collections.Generic;
6 using System.IO;
7 using System.Linq;
8 using System.Text;
9 using System.Threading.Tasks;
10 
11 namespace SiliconStudio.BuildEngine
12 {
13  public interface IParamFilter
14  {
15  Action<Command, object> Assigner { get; }
16  Type CommandType { get; }
17  IEnumerable Filter(object param);
18  }
19 
20  public abstract class ParamFilter<TIn, TOut, TCommand> : IParamFilter where TCommand : Command
21  {
22  public Action<Command, object> Assigner { get; protected set; }
23 
24  public Type CommandType { get; protected set; }
25 
26  protected ParamFilter(Action<TCommand, TOut> assigner)
27  {
28  CommandType = typeof(TCommand);
29  SetAssigner(assigner);
30  }
31 
32  public IEnumerable Filter(object param)
33  {
34  return Filter((TIn)param);
35  }
36 
37  protected void SetAssigner(Action<TCommand, TOut> assigner)
38  {
39  Assigner = (x, y) => assigner((TCommand)x, (TOut)y);
40  }
41 
42  public abstract IEnumerable<TOut> Filter(TIn input);
43  }
44 
45  public class FilePatternFilter<TCommand> : ParamFilter<string, string, TCommand> where TCommand : Command
46  {
47  public FilePatternFilter(Action<TCommand, string> assigner)
48  : base(assigner)
49  {
50 
51  }
52 
53  public override IEnumerable<string> Filter(string pattern)
54  {
55  if (pattern.Contains("/") || pattern.Contains("\\"))
56  {
57  string path = pattern.Substring(0, Math.Max(pattern.LastIndexOf('/'), pattern.LastIndexOf('\\')));
58  string filePattern = path.Length < pattern.Length ? pattern.Substring(path.Length + 1) : "";
59  return Directory.EnumerateFiles(path, filePattern);
60  }
61  return Directory.EnumerateFiles(pattern);
62  }
63  }
64 }
override IEnumerable< string > Filter(string pattern)
Definition: ParamFilter.cs:53
_In_ size_t _In_ DXGI_FORMAT _In_ size_t _In_ float size_t y
Definition: DirectXTexP.h:191
FilePatternFilter(Action< TCommand, string > assigner)
Definition: ParamFilter.cs:47
void SetAssigner(Action< TCommand, TOut > assigner)
Definition: ParamFilter.cs:37