示例#1
0
        static SystemTypes()
        {
            const BindingFlags bf = BindingFlags.Static | BindingFlags.Public | BindingFlags.GetField;
            var fields            = typeof(SystemTypeCode).GetFields(bf);

            Types = new SystemType[fields.Length];
            foreach (var field in fields)
            {
                var code       = (SystemTypeCode)field.GetValue(null);
                int index      = (int)code;
                var attr       = field.GetAttribute <SystemTypeNameAttribute>(false);
                var systemType = new SystemType(code, attr != null ? attr.Name : code.ToString());
                var cs_attr    = field.GetAttribute <CSharpAttribute>(false);
                if (cs_attr != null)
                {
                    systemType.CSharpKeyword = cs_attr.Value;
                }
                Types[index] = systemType;
            }
            Lookup           = Types.ToDictionary(x => x.Name, x => x);
            LookupByFullName = Types.ToDictionary(x => x.FullName, x => x);
        }
示例#2
0
        private static void LoadConversions(string text, bool[,] table)
        {
            using (var reader = new StringReader(text))
            {
                char[] sep = { ' ', '\t', ',' };
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    line = line.Trim();
                    if (line.Length == 0)
                    {
                        continue;
                    }

                    //comment?
                    if (line.StartsWith("#"))
                    {
                        continue;
                    }

                    var arr  = line.Split(sep, StringSplitOptions.RemoveEmptyEntries);
                    int n    = arr.Length;
                    var from = SystemType.ParseCode(arr[0]);
                    if (from == SystemTypeCode.None)
                    {
                        throw new InvalidOperationException();
                    }
                    for (int i = 1; i < n; ++i)
                    {
                        var to = SystemType.ParseCode(arr[i]);
                        if (to != SystemTypeCode.None)
                        {
                            table[(int)from, (int)to] = true;
                        }
                    }
                }
            }
        }