Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
QuantumConsistencyException.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.Quantum
6 {
7  /// <summary>
8  /// An exception that occurs during consistency checks of Quantum objects, indicating that a <see cref="IModelNode"/> is un an unexpected state.
9  /// </summary>
11  {
12  /// <summary>
13  /// Initializes a new instance of the QuantumConsistencyException class.
14  /// </summary>
15  /// <param name="expected">A string representing the expected result.</param>
16  /// <param name="observed">A string representing the observed result.</param>
17  /// <param name="node">The node that is related to this error.</param>
18  public QuantumConsistencyException(string expected, string observed, IModelNode node)
19  : base(GetMessage(expected, observed))
20  {
21  Expected = expected ?? "(NullMessage)";
22  Observed = observed ?? "(NullMessage)";
23  Node = node;
24  }
25 
26  /// <summary>
27  /// Initializes a new instance of the QuantumConsistencyException class, with advanced string formatting.
28  /// </summary>
29  /// <param name="expected">A string representing the expected result. This string must contains a </param>
30  /// <param name="expectedArg"></param>
31  /// <param name="observed">A string representing the observed result.</param>
32  /// <param name="observedArg"></param>
33  /// <param name="node">The node that is related to this error.</param>
34  public QuantumConsistencyException(string expected, string expectedArg, string observed, string observedArg, IModelNode node)
35  : base(GetMessage(expected, expectedArg, observed, observedArg))
36  {
37  try
38  {
39  Expected = string.Format(expected ?? "(NullMessage) [{0}]", expectedArg ?? "(NullArgument)");
40  }
41  catch (Exception)
42  {
43  Expected = expected ?? "(NullMessage) [{0}]";
44  }
45  try
46  {
47  Observed = string.Format(observed ?? "(NullMessage) [{0}]", observedArg ?? "(NullArgument)");
48  }
49  catch (Exception)
50  {
51  Observed = observed ?? "(NullMessage) [{0}]";
52  }
53 
54  Node = node;
55  }
56 
57  /// <summary>
58  /// Gets a string representing the expected result.
59  /// </summary>
60  public string Expected { get; private set; }
61 
62  /// <summary>
63  /// Gets a string representing the observed result.
64  /// </summary>
65  public string Observed { get; private set; }
66 
67  /// <summary>
68  /// Gets the <see cref="IModelNode"/> that triggered this exception.
69  /// </summary>
70  public IModelNode Node { get; private set; }
71 
72  ///// <inheritdoc/>
73  //public override string ToString()
74  //{
75  // return GetMessage(Expected, Observed);
76  //}
77 
78  private static string Format(string message, string argument)
79  {
80  try
81  {
82  return string.Format(message ?? "(NullMessage) [{0}]", argument ?? "(NullArgument)");
83  }
84  catch (Exception)
85  {
86  return message ?? "(NullMessage) [(NullArgument)]";
87  }
88 
89  }
90 
91  private static string Format(string message)
92  {
93  return message ?? "(NullMessage)";
94 
95  }
96 
97  private static string GetMessage(string expected, string observed)
98  {
99  return string.Format("Quantum consistency exception. Expected: {0} - Observed: {1}", Format(expected), Format(observed));
100  }
101 
102  private static string GetMessage(string expected, string expectedArg, string observed, string observedArg)
103  {
104  return string.Format("Quantum consistency exception. Expected: {0} - Observed: {1}", Format(expected, expectedArg), Format(observed, observedArg));
105  }
106  }
107 }
QuantumConsistencyException(string expected, string observed, IModelNode node)
Initializes a new instance of the QuantumConsistencyException class.
An exception that occurs during consistency checks of Quantum objects, indicating that a IModelNode i...
QuantumConsistencyException(string expected, string expectedArg, string observed, string observedArg, IModelNode node)
Initializes a new instance of the QuantumConsistencyException class, with advanced string formatting...
The IModelNode interface represents a node in a model object. A model object is represented by a grap...
Definition: IModelNode.cs:16