Repository navigation
Expand file tree
/
Copy pathScriptVariable.cs
More file actions
71 lines (62 loc) · 1.82 KB
/
Copy pathScriptVariable.cs
File metadata and controls
71 lines (62 loc) · 1.82 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
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Reflection;
namespace Microsoft.CodeAnalysis.Scripting
{
/// <summary>
/// A variable declared by the script.
/// </summary>
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public class ScriptVariable
{
private readonly object _instance;
private readonly MemberInfo _member;
internal ScriptVariable(object instance, MemberInfo member)
{
_instance = instance;
_member = member;
}
/// <summary>
/// The name of the variable.
/// </summary>
public string Name
{
get { return _member.Name; }
}
/// <summary>
/// The type of the variable.
/// </summary>
public Type Type
{
get
{
var field = _member as FieldInfo;
if (field != null)
{
return field.FieldType;
}
return ((PropertyInfo)_member).PropertyType;
}
}
/// <summary>
/// The value of the variable after running the script.
/// </summary>
public object Value
{
get
{
var field = _member as FieldInfo;
if (field != null)
{
return field.GetValue(_instance);
}
return ((PropertyInfo)_member).GetValue(_instance);
}
}
private string GetDebuggerDisplay()
{
return string.Format("{0}: {1}", this.Name, this.Value?.ToString() ?? "<null>");
}
}
}