Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ShaderArraySource.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.Linq;
7 
8 using SiliconStudio.Core;
9 
10 namespace SiliconStudio.Paradox.Shaders
11 {
12  /// <summary>
13  /// An array of <see cref="ShaderSource"/> used only in shader mixin compositions.
14  /// </summary>
15  public sealed class ShaderArraySource : ShaderSource, IEnumerable<ShaderSource>, IEquatable<ShaderArraySource>
16  {
17  /// <summary>
18  /// Initializes a new instance of the <see cref="ShaderArraySource"/> class.
19  /// </summary>
21  {
22  Values = new List<ShaderSource>();
23  }
24 
25  /// <summary>
26  /// Gets or sets the values.
27  /// </summary>
28  /// <value>The values.</value>
29  public List<ShaderSource> Values { get; set; }
30 
31  /// <summary>
32  /// Adds the specified composition.
33  /// </summary>
34  /// <param name="composition">The composition.</param>
35  public void Add(ShaderSource composition)
36  {
37  Values.Add(composition);
38  }
39 
40  public override object Clone()
41  {
42  return new ShaderArraySource { Values = Values.Select(x => (ShaderSource)x.Clone()).ToList() };
43  }
44 
45  public override bool Equals(object obj)
46  {
47  if (ReferenceEquals(null, obj)) return false;
48  if (ReferenceEquals(this, obj)) return true;
49  if (obj.GetType() != this.GetType()) return false;
50  return Equals((ShaderArraySource)obj);
51  }
52 
53  public bool Equals(ShaderArraySource other)
54  {
55  if (ReferenceEquals(null, other)) return false;
56  if (ReferenceEquals(this, other)) return true;
57 
58  if (ReferenceEquals(Values, other.Values))
59  return true;
60 
61  if (ReferenceEquals(Values, null))
62  return false;
63 
64  if (Values.Count != other.Values.Count)
65  return false;
66 
67  return !Values.Where((t, i) => !t.Equals(other.Values[i])).Any();
68  }
69 
70  public override int GetHashCode()
71  {
72  return Utilities.GetHashCode(Values);
73  }
74 
75  public IEnumerator<ShaderSource> GetEnumerator()
76  {
77  return Values.GetEnumerator();
78  }
79 
80  IEnumerator IEnumerable.GetEnumerator()
81  {
82  return GetEnumerator();
83  }
84 
85  public override string ToString()
86  {
87  return string.Format("[{0}]", Values != null ? string.Join(", ", Values) : string.Empty);
88  }
89  }
90 }
override bool Equals(object obj)
Determines whether the specified System.Object is equal to this instance.
Let the emitter choose the style.
ShaderArraySource()
Initializes a new instance of the ShaderArraySource class.
List< ShaderSource > Values
Gets or sets the values.
An array of ShaderSource used only in shader mixin compositions.
void Add(ShaderSource composition)
Adds the specified composition.
override object Clone()
Deep clones this instance.