Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ShaderClassSource.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.Generic;
5 using System.Linq;
6 using System.Text;
7 
8 using SiliconStudio.Core;
9 using SiliconStudio.Core.Serialization;
10 
11 namespace SiliconStudio.Paradox.Shaders
12 {
13  /// <summary>
14  /// A shader class used for mixin.
15  /// </summary>
16  [DataContract]
17  public sealed class ShaderClassSource : ShaderSource, IEquatable<ShaderClassSource>
18  {
19  /// <summary>
20  /// Gets the name of the class.
21  /// </summary>
22  /// <value>The name of the class.</value>
23  public string ClassName { get; set; }
24 
25  /// <summary>
26  /// Gets the generic parameters.
27  /// </summary>
28  /// <value>The generic parameters.</value>
29  public string[] GenericArguments { get; set; }
30 
31  public Dictionary<string, string> GenericParametersArguments { get; set; }
32 
33  /// <summary>
34  /// Initializes a new instance of the <see cref="ShaderClassSource"/> class.
35  /// </summary>
37  {
38  }
39 
40  /// <summary>
41  /// Initializes a new instance of the <see cref="ShaderClassSource"/> class.
42  /// </summary>
43  /// <param name="className">Name of the class.</param>
44  public ShaderClassSource(string className)
45  : this(className, null)
46  {
47  }
48 
49  /// <summary>
50  /// Initializes a new instance of the <see cref="ShaderClassSource"/> class.
51  /// </summary>
52  /// <param name="className">Name of the class.</param>
53  /// <param name="genericArguments">The generic parameters.</param>
54  public ShaderClassSource(string className, params string[] genericArguments)
55  {
56  ClassName = className;
57  GenericArguments = genericArguments;
58  }
59 
60  /// <summary>
61  /// Initializes a new instance of the <see cref="ShaderClassSource"/> class.
62  /// </summary>
63  /// <param name="className">Name of the class.</param>
64  /// <param name="genericArguments">The generic parameters.</param>
65  public ShaderClassSource(string className, params object[] genericArguments)
66  {
67  ClassName = className;
68  if (genericArguments != null)
69  {
70  GenericArguments = new string[genericArguments.Length];
71  for (int i = 0; i < genericArguments.Length; ++i)
72  {
73  var genArg = genericArguments[i];
74  if (genArg is bool)
75  GenericArguments[i] = ((bool)genArg).ToString().ToLower();
76  else
77  GenericArguments[i] = genArg == null ? "null": genArg.ToString();
78  }
79  }
80  }
81 
82  /// <summary>
83  /// Returns a class name as a <see cref="System.String" /> that represents this instance.
84  /// </summary>
85  /// <returns>A class name as a <see cref="System.String" /> that represents this instance.</returns>
86  public string ToClassName()
87  {
88  if (GenericArguments == null)
89  return ClassName;
90 
91  var result = new StringBuilder();
92  result.Append(ClassName);
93  if (GenericArguments != null && GenericArguments.Length > 0)
94  {
95  result.Append('<');
96  result.Append(string.Join(",", GenericArguments));
97  result.Append('>');
98  }
99 
100  return result.ToString();
101  }
102 
103  public bool Equals(ShaderClassSource shaderClassSource)
104  {
105  if (ReferenceEquals(null, shaderClassSource)) return false;
106  if (ReferenceEquals(this, shaderClassSource)) return true;
107  return string.Equals(ClassName, shaderClassSource.ClassName) && Utilities.Compare(GenericArguments, shaderClassSource.GenericArguments);
108  }
109 
110  public override bool Equals(object obj)
111  {
112  if (ReferenceEquals(null, obj)) return false;
113  if (ReferenceEquals(this, obj)) return true;
114  if (obj.GetType() != GetType()) return false;
115  return Equals((ShaderClassSource)obj);
116  }
117 
118  public override int GetHashCode()
119  {
120  unchecked
121  {
122  return ((ClassName != null ? ClassName.GetHashCode() : 0) * 397) ^ Utilities.GetHashCode(GenericArguments);
123  }
124  }
125 
126  public override object Clone()
127  {
128  return new ShaderClassSource(ClassName, GenericArguments = GenericArguments != null ? GenericArguments.ToArray() : null);
129  }
130 
131  public override string ToString()
132  {
133  return ToClassName();
134  }
135 
136  /// <summary>
137  /// Performs an implicit conversion from <see cref="System.String"/> to <see cref="ShaderClassSource"/>.
138  /// </summary>
139  /// <param name="className">Name of the class.</param>
140  /// <returns>The result of the conversion.</returns>
141  public static implicit operator ShaderClassSource(string className)
142  {
143  return new ShaderClassSource(className);
144  }
145  }
146 }
override bool Equals(object obj)
Determines whether the specified System.Object is equal to this instance.
static bool Compare(IEnumerable left, IEnumerable right)
Compares two collection, element by elements.
Definition: Utilities.cs:584
override object Clone()
Deep clones this instance.
ShaderClassSource(string className, params object[] genericArguments)
Initializes a new instance of the ShaderClassSource class.
bool Equals(ShaderClassSource shaderClassSource)
string[] GenericArguments
Gets the generic parameters.
ShaderClassSource(string className)
Initializes a new instance of the ShaderClassSource class.
ShaderClassSource()
Initializes a new instance of the ShaderClassSource class.
ShaderClassSource(string className, params string[] genericArguments)
Initializes a new instance of the ShaderClassSource class.
string ToClassName()
Returns a class name as a System.String that represents this instance.