-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeOf.cs
More file actions
76 lines (59 loc) · 1.87 KB
/
TypeOf.cs
File metadata and controls
76 lines (59 loc) · 1.87 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
70
71
72
73
74
75
76
using NodeDev.Core.NodeDecorations;
using NodeDev.Core.Types;
using System.Linq.Expressions;
namespace NodeDev.Core.Nodes;
/// <summary>
/// Returns the selected type. Represent C# '<see langword="typeof"/>' keyword.
/// </summary>
public class TypeOf : NoFlowNode
{
private class CurrentUndefinedType : INodeDecoration
{
public TypeBase Type { get; }
public CurrentUndefinedType(TypeBase undefinedType)
{
Type = undefinedType;
}
public string Serialize()
{
return Type.SerializeWithFullTypeNameString();
}
public static INodeDecoration Deserialize(TypeFactory typeFactory, string json)
{
return new CurrentUndefinedType(TypeBase.DeserializeFullTypeNameString(typeFactory, json));
}
}
public TypeOf(Graph graph, string? id = null) : base(graph, id)
{
Outputs.Add(new("Type", this, TypeFactory.Get<Type>()));
Type = new UndefinedGenericType("T");
Decorations.Add(typeof(CurrentUndefinedType), new CurrentUndefinedType(Type));
}
private TypeBase Type;
public override string Name => "TypeOf";
public override IEnumerable<string> GetUndefinedGenericTypes()
{
if (Type is UndefinedGenericType undefined)
return [undefined.Name];
return [];
}
public override void OnBeforeGenericTypeDefined(IReadOnlyDictionary<string, TypeBase> changedGenerics)
{
if (Type is not UndefinedGenericType undefined)
return;
if (changedGenerics.TryGetValue(undefined.Name, out var newType))
{
Type = newType;
Decorations[typeof(CurrentUndefinedType)] = new CurrentUndefinedType(Type);
}
}
protected override void Deserialize(SerializedNode serializedNodeObj)
{
base.Deserialize(serializedNodeObj);
Type = ((CurrentUndefinedType)(Decorations[typeof(CurrentUndefinedType)])).Type;
}
internal override void BuildInlineExpression(BuildExpressionInfo info)
{
info.LocalVariables[Outputs[0]] = Expression.Constant(Type.MakeRealType());
}
}