xronos /Microsoft.Scripting/Actions/TypeTracker.cs

Language C# Lines 81
MD5 Hash ef597881983e149eb53500bdfdc9402e Estimated Cost $1,187 (why?)
Repository https://bitbucket.org/stefanrusek/xronos View Raw File
 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
80
/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 *
 * ***************************************************************************/

#if CODEPLEX_40
using System;
#else
using System; using Microsoft;
#endif
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Scripting.Runtime;

namespace Microsoft.Scripting.Actions {
    public abstract class TypeTracker : MemberTracker, IMembersList {
        internal TypeTracker() {
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")]
        public abstract Type Type {
            get;
        }

        public abstract bool IsGenericType {
            get;
        }

        public abstract bool IsPublic {
            get;
        }

        #region IMembersList Members

        public IList<object> GetMemberNames(CodeContext context) {
            Dictionary<string, string> members = new Dictionary<string, string>();
            foreach (MemberInfo mi in Type.GetMembers()) {
                if (mi.MemberType != MemberTypes.Constructor) {
                    members[mi.Name] = mi.Name;
                }
            }

            List<object> res = new List<object>();
            foreach (string key in members.Keys) {
                res.Add(key);
            }
            return res;
        }

        #endregion

        /// <summary>
        /// Enables implicit Type to TypeTracker conversions accross dynamic languages.
        /// 
        /// TODO: Should be explicit, but that breaks a JS test
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates")]
        public static implicit operator Type(TypeTracker tracker) {
            TypeGroup tg = tracker as TypeGroup;
            if (tg != null) {
                Type res;
                if (!tg.TryGetNonGenericType(out res)) {
                    throw ScriptingRuntimeHelpers.SimpleTypeError("expected non-generic type, got generic-only type");
                }
                return res;
            }
            return tracker.Type;
        }
    }
}
Back to Top