Repository navigation
Expand file tree
/
Copy pathScriptVariable.cs
More file actions
79 lines (72 loc) · 2.1 KB
/
Copy pathScriptVariable.cs
File metadata and controls
79 lines (72 loc) · 2.1 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
77
78
79
// 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.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading;
using Microsoft.CodeAnalysis;
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
{
if (_member.MemberType == MemberTypes.Field)
{
return ((FieldInfo)_member).FieldType;
}
else
{
return ((PropertyInfo)_member).PropertyType;
}
}
}
/// <summary>
/// The value of the variable after running the script.
/// </summary>
public object Value
{
get
{
if (_member.MemberType == MemberTypes.Field)
{
return ((FieldInfo)_member).GetValue(_instance);
}
else
{
return ((PropertyInfo)_member).GetValue(_instance);
}
}
}
private string GetDebuggerDisplay()
{
return string.Format("{0}: {1}", this.Name, (this.Value != null) ? this.Value : "<null>");
}
}
}