Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
LiteralExpression.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 
7 namespace SiliconStudio.Shaders.Ast
8 {
9  /// <summary>
10  /// A literal expression.
11  /// </summary>
13  {
14  #region Constructors and Destructors
15 
16  /// <summary>
17  /// Initializes a new instance of the <see cref = "LiteralExpression" /> class.
18  /// </summary>
20  {
21  }
22 
23  /// <summary>
24  /// Initializes a new instance of the <see cref="LiteralExpression"/> class.
25  /// </summary>
26  /// <param name="literal">
27  /// The literal.
28  /// </param>
29  public LiteralExpression(Literal literal)
30  {
31  Literal = literal;
32  }
33 
34  /// <summary>
35  /// Initializes a new instance of the <see cref="LiteralExpression"/> class.
36  /// </summary>
37  /// <param name="value">
38  /// The value.
39  /// </param>
40  public LiteralExpression(object value)
41  {
42  Literal = new Literal(value);
43  }
44 
45  #endregion
46 
47  #region Public Properties
48 
49  /// <summary>
50  /// Gets or sets the literal.
51  /// </summary>
52  /// <value>
53  /// The literal.
54  /// </value>
55  public Literal Literal { get; set; }
56 
57  /// <summary>
58  /// Gets or sets the text.
59  /// </summary>
60  /// <value>
61  /// The text.
62  /// </value>
63  public string Text
64  {
65  get { return Literal != null ? Literal.Text : null; }
66  set
67  {
68  if (Literal != null)
69  {
70  Literal.Text = value;
71  }
72  else
73  {
74  Literal = value == null ? null : new Literal() {Text = value};
75  }
76  }
77  }
78 
79  /// <summary>
80  /// Gets or sets the value.
81  /// </summary>
82  /// <value>
83  /// The value.
84  /// </value>
85  public object Value
86  {
87  get { return Literal != null ? Literal.Value : null; }
88  set
89  {
90  if (Literal != null)
91  {
92  Literal.Value = value;
93  }
94  else
95  {
96  Literal = value == null ? null : new Literal(value);
97  }
98  }
99  }
100 
101  #endregion
102 
103  #region Public Methods
104 
105  public bool Equals(LiteralExpression other)
106  {
107  if (ReferenceEquals(null, other)) return false;
108  if (ReferenceEquals(this, other)) return true;
109  return Equals(other.Literal, Literal);
110  }
111 
112  public override bool Equals(object obj)
113  {
114  if (ReferenceEquals(null, obj)) return false;
115  if (ReferenceEquals(this, obj)) return true;
116  if (obj.GetType() != typeof(LiteralExpression)) return false;
117  return Equals((LiteralExpression)obj);
118  }
119 
120  public override int GetHashCode()
121  {
122  return (Literal != null ? Literal.GetHashCode() : 0);
123  }
124 
125  public static bool operator ==(LiteralExpression left, LiteralExpression right)
126  {
127  return Equals(left, right);
128  }
129 
130  public static bool operator !=(LiteralExpression left, LiteralExpression right)
131  {
132  return !Equals(left, right);
133  }
134 
135  /// <inheritdoc />
136  public override IEnumerable<Node> Childrens()
137  {
138  ChildrenList.Clear();
139  ChildrenList.Add(Literal);
140  return ChildrenList;
141  }
142 
143  /// <inheritdoc />
144  public override string ToString()
145  {
146  return string.Format("{0}", Literal);
147  }
148 
149  #endregion
150  }
151 }
LiteralExpression(Literal literal)
Initializes a new instance of the LiteralExpression class.
LiteralExpression(object value)
Initializes a new instance of the LiteralExpression class.
override IEnumerable< Node > Childrens()
Gets the child nodes. An enumeration of child nodes
Literal Literal
Gets or sets the literal.
A field of a struct.
Definition: Literal.cs:13
LiteralExpression()
Initializes a new instance of the LiteralExpression class.