forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphProcessingResult.cs
More file actions
69 lines (61 loc) · 2.29 KB
/
Copy pathGraphProcessingResult.cs
File metadata and controls
69 lines (61 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Unity.GraphToolsFoundation.Editor
{
/// <summary>
/// A container for graph processing errors and warnings.
/// </summary>
class GraphProcessingResult
{
readonly List<GraphProcessingError> m_Errors = new List<GraphProcessingError>();
/// <summary>
/// The errors.
/// </summary>
public IReadOnlyList<GraphProcessingError> Errors => m_Errors;
/// <summary>
/// The graph processing status.
/// </summary>
public GraphProcessingStatuses Status => Errors.Any(e => e.IsWarning == false) ?
GraphProcessingStatuses.Failed : GraphProcessingStatuses.Succeeded;
/// <summary>
/// Adds an error.
/// </summary>
/// <param name="description">Error description.</param>
/// <param name="node">The node associated with the error.</param>
/// <param name="quickFix">How to fix this error.</param>
public void AddError(string description, AbstractNodeModel node = null, QuickFix quickFix = null)
{
AddError(description, node, false, quickFix);
}
/// <summary>
/// Adds a warning.
/// </summary>
/// <param name="description">Warning description.</param>
/// <param name="node">The node associated with the warning.</param>
/// <param name="quickFix">How to fix this warning.</param>
public void AddWarning(string description, AbstractNodeModel node = null, QuickFix quickFix = null)
{
AddError(description, node, true, quickFix);
}
void AddError(string desc, AbstractNodeModel node, bool isWarning, QuickFix quickFix)
{
var error = new GraphProcessingError
{
Description = desc,
SourceNode = node,
SourceNodeGuid = node?.Guid ?? default,
IsWarning = isWarning,
Fix = quickFix
};
if (!m_Errors.Contains(error))
{
m_Errors.Add(error);
}
}
}
}