コード例 #1
0
ファイル: Map.cs プロジェクト: OrganizationUsername/Towel
        public void GetEnumeratorPairsTest()
        {
            IMap <string, int> map = MapHashLinked.New <string, int>();

            map.Add(1, "Hello");
            map.Add(2, "World");
            (int, string)[] array = new (int, string)[2];
コード例 #2
0
ファイル: Map.cs プロジェクト: OrganizationUsername/Towel
        public void PropertyTest()
        {
            IMap <string, int> map = MapHashLinked.New <string, int>();

            map.Add(1, "Hello");
            map.Add(2, "World");
            Assert.IsTrue(map.Count is 2);
        }
コード例 #3
0
ファイル: Map.cs プロジェクト: OrganizationUsername/Towel
        public void RemoveTest()
        {
            IMap <string, int> map = MapHashLinked.New <string, int>();

            map.Add(1, "Hello");
            map.Add(2, "World");
            map.Remove(1);
            Assert.ThrowsException <ArgumentException>(() => map[1]);
        }
コード例 #4
0
ファイル: Map.cs プロジェクト: OrganizationUsername/Towel
        public void IndexerGetSetTest()
        {
            IMap <string, int> map = MapHashLinked.New <string, int>();

            map.Add(1, "Hello");
            map.Add(2, "World");
            const string s = "Added word";

            map[3] = s;
            Assert.IsTrue(map[3] is s);
        }
コード例 #5
0
 protected override void AttachRequest(PayRequestModel model, IMap <RequestMapField> requestMapper)
 {
     requestMapper.Add(new NameValueCollection
     {
         { "timestamp", Extensions.UnixTimeSpan().ToString() },
         { "orderId", "" },
         { "merchantId", "" },
         { "amount", "" },
         { "type", "" },
         { "notifyUrl", "" },
         { "frontUrl", "" },
         { "merchantKey", Settings.Mkey },
         { "productName", "" }
     })
     .Add(new Dictionary <RequestMapField, string>()
     {
         { RequestMapField.Mid, "merchantId" },
         { RequestMapField.Amount, "amount" },
         { RequestMapField.OrderId, "orderId" },
         { RequestMapField.ProductName, "productName" },
         { RequestMapField.ClientNotifyUrl, "frontUrl" },
         { RequestMapField.ServerNotifyUrl, "notifyUrl" },
         { RequestMapField.BankCo, "type" }
     });
 }
コード例 #6
0
    private void CreateCell(int x, int z, int i)
    {
        Vector3 position;

        position.x = (x + z * 0.5f - z / 2) * (HexMetrices.InnerRadius * 2f);
        position.y = z * (HexMetrices.OuterRadius * 1.5f);
        position.z = 0f;

        ICell cell = _hexCellPresenterFactory.Create();

        cell.Initialize(_hexCellViewFactory.Create());
        cell.UiPosition  = position;
        cell.Coordinates = HexCoordinates.FromOffsetCoordinates(x, z);
        cell.UpdateLabel(cell.Distance.ToString());
        cell.IsWalkable = Random.value > 0.2f ? true : false;
        if (!cell.IsWalkable)
        {
            cell.CellColor = _settings.BlockedCellColor;
        }
        else
        {
            cell.CellColor = _settings.DefaultCellColor;
        }

        bool makeRoad = Random.value > 0.7f && cell.IsWalkable ? true : false;

        if (makeRoad)
        {
            cell.CellColor = _settings.RoadCellColor;
            var directions = System.Enum.GetValues(typeof(HexDirection)) as HexDirection[];
            foreach (var item in directions)
            {
                cell.AddRoad(item);
            }
        }
        if (x > 0)
        {
            cell.SetNeighbor(HexDirection.W, _map.Cells[i - 1]);
        }
        if (z > 0)
        {
            if ((z & 1) == 0)
            {
                cell.SetNeighbor(HexDirection.SE, _map.Cells[i - _settings.CellCountX]);
                if (x > 0)
                {
                    cell.SetNeighbor(HexDirection.SW, _map.Cells[i - _settings.CellCountX - 1]);
                }
            }
            else
            {
                cell.SetNeighbor(HexDirection.SW, _map.Cells[i - _settings.CellCountX]);
                if (x < _settings.CellCountX - 1)
                {
                    cell.SetNeighbor(HexDirection.SE, _map.Cells[i - _settings.CellCountX + 1]);
                }
            }
        }
        _map.Add(cell);
    }
コード例 #7
0
 private void BindMap <T>
     (ISeq <JST.Statement> statements,
     IMap <T, int> usageMap,
     IMap <T, JST.Expression> boundMap,
     Func <T, string> mkName,
     Func <T, JST.Expression> mkExpression)
 {
     foreach (var kv in usageMap)
     {
         if (!boundMap.ContainsKey(kv.Key))
         {
             if (kv.Value > 1)
             {
                 var e = mkExpression(kv.Key);
                 if (e != null)
                 {
                     if (env.DebugMode)
                     {
                         statements.Add(new JST.CommentStatement(mkName(kv.Key)));
                     }
                     var id = NameSupply.GenSym();
                     statements.Add(JST.Statement.Var(id, e));
                     boundMap.Add(kv.Key, id.ToE());
                 }
             }
             // else: inline expression as need it
         }
         // else: use outer binding
     }
 }
コード例 #8
0
        public static double testMap(IMap <string, int> map, string filename)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            Console.WriteLine(filename);

            List <string> words = new List <string>();

            FileOperation.ReadFile(filename, words);

            Console.WriteLine("Total words: " + words.Count);

            foreach (var word in words)
            {
                if (map.Contains(word))
                {
                    map.Set(word, map.Get(word) + 1);
                }
                else
                {
                    map.Add(word, 1);
                }
            }
            Console.WriteLine("Total different words: " + map.GetSize());

            stopWatch.Stop();
            return((double)stopWatch.ElapsedMilliseconds / 1000.000);
        }
コード例 #9
0
        public void MapDelegates()
        {
            IMap <int, int> map = MapHashLinked.New <int, int>();

            for (int i = 0; i < N; i++)
            {
                map.Add(i, i);
            }
        }
コード例 #10
0
            public IMap Merge(IMap map)
            {
                for (int i = 0; i < _count; i++)
                {
                    JwtMember item = _keyValues[i];
                    map = map.Add(item);
                }

                return(map);
            }
コード例 #11
0
        public static void ParseMap(this StreamReader sr, IMap <string, dynamic> map, Line line, Line lookAheadLine)
        {
            if (sr is null || map is null || line is null || lookAheadLine is null)
            {
                return;
            }
            var innerMap = new Map <string, dynamic>(map);

            map.Add(line.Key, innerMap);
            lookAheadLine.ParseLine(sr, innerMap);
        }
コード例 #12
0
 public void IterationSetup()
 {
     mapHashLinked        = MapHashLinked.New <int, int>();
     mapHashLinkedStructs = new MapHashLinked <int, int, IntEquate, IntHash>();
     dictionary           = new System.Collections.Generic.Dictionary <int, int>();
     for (int i = 0; i < N; i++)
     {
         mapHashLinked.Add(i, i);
         mapHashLinkedStructs.Add(i, i);
         dictionary.Add(i, i);
     }
 }
コード例 #13
0
        /// <summary>
        /// Parses the value from a line of GIMIC text
        /// </summary>
        /// <param name="line"></param>
        /// <param name="sr"></param>
        /// <param name="map"></param>
        public static void ParseValue(this Line line, StreamReader sr, IMap <string, dynamic> map)
        {
            if (line is null || sr is null || map is null)
            {
                return;
            }
            var     tokenState = new TokenState();
            dynamic value      = sr.CaptureAndEscapeTokens((string)line.Value, ref tokenState);

            value = value.Contains(',')
                    ? tokenState.CreateListOfValues((string)value)
                    : tokenState.ReInsertCapturedTokens((string)value);

            map.Add(line.Key, value);
        }
コード例 #14
0
ファイル: Map.cs プロジェクト: OrganizationUsername/Towel
        public void Remove_Testing()
        {
            {             // string, int
                const int          count = 100000;
                IMap <string, int> map   = MapHashLinked.New <string, int>();
                Iterate(count, i => map.Add(i, i.ToString()));
                for (int i = 0; i < count; i += 3)
                {
                    map.Remove(i);
                }
                for (int i = 0; i < count; i++)
                {
                    if (i % 3 == 0)
                    {
                        Assert.IsFalse(map.Contains(i));
                    }
                    else
                    {
                        Assert.IsTrue(map.Contains(i));
                    }
                }
                Assert.IsFalse(map.Contains(-1));
                Assert.IsFalse(map.Contains(count));
            }

            {             // int, string
                const int          count = 100000;
                IMap <int, string> map   = MapHashLinked.New <int, string>();
                Iterate(count, i => map.Add(i.ToString(), i));
                for (int i = 0; i < count; i += 3)
                {
                    map.Remove(i.ToString());
                }
                for (int i = 0; i < count; i++)
                {
                    if (i % 3 == 0)
                    {
                        Assert.IsFalse(map.Contains(i.ToString()));
                    }
                    else
                    {
                        Assert.IsTrue(map.Contains(i.ToString()));
                    }
                }
                Assert.IsFalse(map.Contains((-1).ToString()));
                Assert.IsFalse(map.Contains(count.ToString()));
            }
        }
コード例 #15
0
ファイル: ResourceManager.cs プロジェクト: gixslayer/darktech
        public bool LinkPackage(string path)
        {
            // Prevent linking the same package twice.
            if (linkedPackages.Contains(path))
            {
                Engine.Log.WriteLine("warning/system/resourcemanager", "Package {0} is already loaded", path);

                return(true);
            }

            try
            {
                // Begin loading the package file.
                File    file    = Engine.FileSystem.OpenFile(path, FileMode.Open, FileAccess.Read);
                PakFile pakFile = new PakFile(file);

                // Package file successfully loaded at this point. Add it to the map of linked packages.
                linkedPackages.Add(path, pakFile);

                // Map all entries in the package.
                foreach (PakEntry entry in pakFile.Entries)
                {
                    // If no previous mapping exist for the entry create a new mapping.
                    if (!packageMapping.Contains(entry.Name))
                    {
                        packageMapping.Add(entry.Name, new ArrayStack <PakFile>(4));
                    }

                    // Push the entry on top of the current mapping stack.
                    packageMapping[entry.Name].Push(pakFile);
                }

                return(true);
            }
            catch (FileSystemException e)
            {
                Engine.Log.WriteLine("error/system/resourcemanager", "Could not open file {0} ({1})", path, e.Message);

                return(false);
            }
            catch (PakException e)
            {
                Engine.Log.WriteLine("error/system/resourcemanager", "Could not open package file {0} ({1})", path, e.Message);

                return(false);
            }
        }
コード例 #16
0
        public PrgState Execute(PrgState state)
        {
            HashSet <string> fileNames = GetFileNames(state);

            if (fileNames.Contains(fileName))
            {
                throw new FileAlreadyOpenedException();
            }
            StreamReader sr = new StreamReader(fileName);
            IMap <ITuple <string, StreamReader> > fileTable = state.FileTable;
            ITuple <string, StreamReader>         tuple     = new MyTuple <string, StreamReader>(fileName, sr);

            fileTable.Add(tuple);
            Adt.IDictionary <string, int> symTable = state.SymTable;
            symTable.Add(varFileId, fileTable.Key);
            return(state);
        }
コード例 #17
0
ファイル: Map.cs プロジェクト: OrganizationUsername/Towel
        public void Add_Testing()
        {
            {             // string, int
                const int          count = 100000;
                IMap <string, int> map   = MapHashLinked.New <string, int>();
                Iterate(count, i => map.Add(i, i.ToString()));
                map.Add(int.MinValue, int.MinValue.ToString());
                map.Add(int.MaxValue, int.MaxValue.ToString());

                // contains
                Iterate(count, i => Assert.IsTrue(map.Contains(i)));
                Assert.IsTrue(map.Contains(int.MinValue));
                Assert.IsTrue(map.Contains(int.MaxValue));
                Assert.IsFalse(map.Contains(-1));
                Assert.IsFalse(map.Contains(count));

                // get
                Iterate(count, i => Assert.IsTrue(map[i] == i.ToString()));
                Assert.IsTrue(map[int.MinValue] == int.MinValue.ToString());
                Assert.IsTrue(map[int.MaxValue] == int.MaxValue.ToString());

                Assert.ThrowsException <ArgumentException>(() => map.Add(0, 0.ToString()));
                Assert.ThrowsException <ArgumentException>(() => map.Add(int.MinValue, int.MinValue.ToString()));
                Assert.ThrowsException <ArgumentException>(() => map.Add(int.MaxValue, int.MaxValue.ToString()));
            }

            {             // int, string
                const int          count = 100000;
                IMap <int, string> map   = MapHashLinked.New <int, string>();
                Iterate(count, i => map.Add(i.ToString(), i));
                map.Add(int.MinValue.ToString(), int.MinValue);
                map.Add(int.MaxValue.ToString(), int.MaxValue);

                // contains
                Iterate(count, i => Assert.IsTrue(map.Contains(i.ToString())));
                Assert.IsTrue(map.Contains(int.MinValue.ToString()));
                Assert.IsTrue(map.Contains(int.MaxValue.ToString()));
                Assert.IsFalse(map.Contains((-1).ToString()));
                Assert.IsFalse(map.Contains(count.ToString()));

                // get
                Iterate(count, i => Assert.IsTrue(map[i.ToString()] == i));
                Assert.IsTrue(map[int.MinValue.ToString()] == int.MinValue);
                Assert.IsTrue(map[int.MaxValue.ToString()] == int.MaxValue);

                Assert.ThrowsException <ArgumentException>(() => map.Add(0.ToString(), 0));
                Assert.ThrowsException <ArgumentException>(() => map.Add(int.MinValue.ToString(), int.MinValue));
                Assert.ThrowsException <ArgumentException>(() => map.Add(int.MaxValue.ToString(), int.MaxValue));
            }
        }
コード例 #18
0
ファイル: ResourceManager.cs プロジェクト: gixslayer/darktech
        public void RegisterResourceLoader <T>(ResourceLoader <T> loader) where T : Resource
        {
            if (loader == null)
            {
                throw new ArgumentNullException("loader");
            }

            if (HasResourceLoader <T>(loader.Name))
            {
                Engine.Log.WriteLine("warning/system/resourcemanager", "Tried to register already registered resource loader {0}", loader.Name);

                return;
            }

            Type type = typeof(T);

            if (!resourceLoaders.Contains(type))
            {
                resourceLoaders.Add(type, new ArrayList <IResourceLoader>());
            }

            resourceLoaders[type].Add(loader);
        }
コード例 #19
0
        private static void MapTest(IMap <int, int> map)
        {
            for (var i = -50; i < 50; i++)
            {
                map.Add(i, i);
            }
            Console.WriteLine(map.Count);

            for (var i = -50; i < 50; i++)
            {
                map.AddIfAbsent(i, i);
            }

            Console.WriteLine(map.Count);

            for (var i = -50; i < 50; i++)
            {
                if (map.Get(i) != i)
                {
                    Console.WriteLine("Error on key: " + i);
                }
            }

            foreach (var kvPair in map)
            {
                if (kvPair.Key != kvPair.Value)
                {
                    Console.WriteLine("Error on key: " + kvPair.Key);
                }
            }

            for (var i = -50; i < 50; i++)
            {
                map.Remove(i);
            }
            Console.WriteLine(map.Count);
        }
コード例 #20
0
ファイル: ResourceManager.cs プロジェクト: gixslayer/darktech
        public T LoadResource <T>(string name) where T : Resource
        {
            // Prevent loading the resource again if it already exists as the same type.
            if (HasResource <T>(name))
            {
                Engine.Log.WriteLine("warning/system/resourcemanager", "Tried to load already loaded resource {0}", name);

                return(GetResource <T>(name));
            }

            // Prevent loading the resource if it already exists as another type.
            if (HasResource(name))
            {
                Engine.Log.WriteLine("error/system/resourcemanager", "Resource {0} is already loaded as another type", name);

                throw new DuplicateResourceException(name);
            }

            T resource = LoadResourceInternal <T>(name);

            resourceCache.Add(name, resource);

            return(resource);
        }
コード例 #21
0
ファイル: Usage.cs プロジェクト: tralivali1234/IL2JS
        private static void Add <T>(IMap <T, int> map, T t, int d, bool isAlwaysUsed)
        {
            var c = default(int);

            if (map.TryGetValue(t, out c))
            {
                if (d > 0)
                {
                    if (c > 0)
                    {
                        // If already definitely used, count possible use as a definite use
                        map[t] = c + d;
                    }
                    else if (isAlwaysUsed)
                    {
                        map[t] = d;
                    }
                }
            }
            else
            {
                map.Add(t, isAlwaysUsed ? d : -1);
            }
        }
コード例 #22
0
        object BinarySerialize(Table table, Type classtype)
        {
            int nrows      = table.nrows;
            int ncols      = table.ncols;
            var xlss       = classtype.GetAttribute <XLSSAttribute>();
            var fieldNames = new List <string>();

            for (int i = 0; i < ncols; i++)
            {
                if (string.IsNullOrEmpty(table[0, i]))
                {
                    continue;
                }
                fieldNames.Add(table[0, i]);
            }

            var objProxy = new ObjProxy(classtype, fieldNames);

            if (xlss.type == XLSSType.List)
            {
                var fullname = string.Format("System.Collections.Generic.List`1[[{0}]]", classtype.AssemblyQualifiedName);
                var listtype = Type.GetType(fullname);
                var list     = Activator.CreateInstance(listtype) as IList;

                for (int row = 1; row < nrows; row++)
                {
                    var key = table[row, 0];
                    if (!string.IsNullOrEmpty(key))
                    {
                        list.Add(objProxy.New());
                        objProxy.SetContext(table, row);
                        ReadItem(table, row, objProxy);
                    }
                }
                return(list);
            }
            else if (xlss.type == XLSSType.Map)
            {
                Type   keyCls         = null;
                Type   rootCls        = classtype;
                var    primaryKeyAttr = rootCls.GetAttribute <PrimaryKeyAttribute>();
                string keyName        = null;

                if (primaryKeyAttr != null)
                {
                    var keyField = rootCls.GetFields().ToList().Find(x => x.Name == primaryKeyAttr.Value);
                    if (keyField != null)
                    {
                        keyCls  = keyField.FieldType;
                        keyName = keyField.Name;
                    }
                }
                else
                {
                    var keyField = rootCls.GetFields().ToList().Find(x => x.IsPublic);
                    if (keyField != null)
                    {
                        keyCls  = keyField.FieldType;
                        keyName = keyField.Name;
                    }
                }

                int keyCol = 0;
                for (var c = 0; c < ncols; c++)
                {
                    if (table[0, c] == keyName)
                    {
                        keyCol = c;
                    }
                }

                if (keyCls == null)
                {
                    throw new Exception(string.Format("Key of map is not found. table:{0}", table.name));
                }

                var  fullname = string.Format("System.Collections.Generic.Map`2[[{0}],[{1}]]", keyCls.AssemblyQualifiedName, classtype.AssemblyQualifiedName);
                var  maptype  = Type.GetType(fullname);
                IMap map      = Activator.CreateInstance(maptype) as IMap;

                for (int row = 1; row < nrows; row++)
                {
                    var headColValue = table[row, 0];
                    if (!string.IsNullOrEmpty(headColValue))
                    {
                        if (string.IsNullOrEmpty(table[row, keyCol]))
                        {
                            throw new Exception(string.Format("Null string can not be used as a dictionary key. table:{0} row:{1} col:{2}", table.name, row, keyCol));
                        }

                        map.Add(keyCls.Parse(table[row, keyCol]), objProxy.New());
                        objProxy.SetContext(table, row);
                        ReadItem(table, row, objProxy);
                    }
                }
                return(map);
            }
            else if (xlss.type == XLSSType.Obj)
            {
                objProxy.New();
                for (int r = 1; r < nrows; r++)
                {
                    for (int c = 0; c < 2; c++)
                    {
                        var key   = table[r, 0];
                        var value = table[r, 1];
                        objProxy.SetField(key, value, r);
                    }
                }
                return(objProxy.obj);
            }
            return(null);
        }
コード例 #23
0
 /// <summary>
 /// Adds the <paramref name="value"/>.
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public void Add(JwtMember value)
 => _map = _map.Add(value);
コード例 #24
0
 public IMap Merge(IMap map)
 => map.Add(_value1)
 .Add(_value2)
 .Add(_value3)
 .Add(_value4);
コード例 #25
0
 public IMap Merge(IMap map)
 => map.Add(_value1);
コード例 #26
0
ファイル: Fase1.cs プロジェクト: clewerton/projetoracexna
        public override void Reset()
        {
            base.Reset();

            map = new Map(this);
            hud = new HUD(this, map);
            enemies = new EnemiesManager(this);

            //Atribui as pistas da estrada para o gestor de inimigos conhecer
            enemies.CurrentRoad = ((IRoad)map.Road).Lanes;

            hero = new Heroi(Game, map);
            hero.SpriteBatch = this.SpriteBatch;
            hero.Velocity = Vector2.Zero;
            hero.Scrollable = true;
            map.Add(hero);
            map.ChangeLaneRegister((IChangeLanelistener)hero);
            map.Velocity = Vector2.Zero;

            base.LoadContent();

            map.ColisionsOccours += OnColisionsOccours;
            map.ChangeRoadType += OnChangeRoad;

            //inicia a geração de inimigos na estrada
            enemies.startGeneration(map);
            gameIsOver = false;
            timer = 3000;
        }
コード例 #27
0
        public void SetField(string fieldName, string fieldValue, int offsetIndex)
        {
            if (!_clsFieldTree.ContainsKey(fieldName))
            {
                return;
            }
            var fieldTree = _clsFieldTree[fieldName];

            foreach (var fieldList in fieldTree)
            {
                var last   = fieldList.Count - 1;
                var target = obj;
                for (int i = 0; i <= last; i++)
                {
                    var field = fieldList[i];
                    var cls   = field.FieldType;
                    var name  = field.Name;

                    if (field.FieldType.IsBasicType())
                    {
                        field.SetValue(target, cls.Parse(fieldValue));
                    }
                    else if (field.FieldType.IsListType())
                    {
                        IList list = field.GetValue(target) as IList;
                        if (list == null)
                        {
                            list = Activator.CreateInstance(field.FieldType) as IList;
                            field.SetValue(target, list);
                        }

                        Type valCls;
                        field.FieldType.GetListParamType(out valCls);

                        if (valCls.IsListType() || valCls.IsMapType())
                        {
                            throw new Exception("List 内不能嵌套 list or dict");
                        }
                        else if (valCls.IsBasicType())
                        {
                            var val = valCls.Parse(fieldValue);
                            if (list.Count <= offsetIndex)
                            {
                                list.Add(val);
                            }
                            else
                            {
                                list[offsetIndex] = val;
                            }
                        }
                        else
                        {
                            if (list.Count <= offsetIndex)
                            {
                                var val = Activator.CreateInstance(valCls);
                                list.Add(val);
                                target = val;
                            }
                            else
                            {
                                target = list[offsetIndex];
                            }
                        }
                    }
                    else if (field.FieldType.IsMapType())
                    {
                        IMap map = field.GetValue(target) as IMap;
                        if (map == null)
                        {
                            map = Activator.CreateInstance(field.FieldType) as IMap;
                            field.SetValue(target, map);
                        }

                        Type keyCls;
                        Type valCls;
                        field.FieldType.GetMapParamType(out keyCls, out valCls);

                        if (valCls.IsListType() || valCls.IsMapType())
                        {
                            throw new Exception("dict 内不能嵌套 list or dict");
                        }
                        else if (valCls.IsBasicType())
                        {
                            var key = keyCls.Parse(fieldValue);
                            var val = valCls.Parse(fieldValue);
                            if (map.Contains(key))
                            {
                                map[key] = val;
                            }
                            else
                            {
                                map.Add(key, val);
                            }
                            break;
                        }
                        else
                        {
                            var    primaryKey = field.GetCustomAttributes(false).ToList().Find(x => x is PrimaryKeyAttribute) as PrimaryKeyAttribute;
                            string keyName    = null;
                            if (primaryKey != null)
                            {
                                keyName = primaryKey.Value;
                            }

                            if (string.IsNullOrEmpty(keyName))
                            {
                                UnityEngine.Debug.LogWarning("Not PrimaryKeyAttribute. Use first field instead.");
                                var firstField = valCls.GetFields().ToList().Find(x => x.IsPublic);
                                if (firstField == null)
                                {
                                    throw new Exception("No Public Field");
                                }
                                keyName = firstField.Name;
                            }

                            object key   = null;
                            int    ncols = _table.ncols;
                            for (int c = 0; c < ncols; c++)
                            {
                                if (_table[0, c] == keyName)
                                {
                                    if (string.IsNullOrEmpty(_table[_row + offsetIndex, c]))
                                    {
                                        //不能使用空字符串作为字典的可以
                                        throw new Exception(string.Format("Null string can not be used as a dictionary key. table:{0} row:{1} col:{2}", _table.name, _row + offsetIndex, c));
                                    }
                                    key = keyCls.Parse(_table[_row + offsetIndex, c]);
                                    break;
                                }
                            }

                            if (key == null)
                            {
                                throw new Exception("Map primary key is not found.");
                            }

                            object valObj;
                            if (map.Contains(key))
                            {
                                valObj = map[key];
                            }
                            else
                            {
                                valObj = Activator.CreateInstance(valCls);
                                map.Add(key, valObj);
                            }
                            target = valObj;
                        }
                    }
                    else
                    {
                        var obj = field.GetValue(target);
                        if (obj == null)
                        {
                            obj = Activator.CreateInstance(field.FieldType);
                            field.SetValue(target, obj);
                        }

                        target = obj;
                    }
                }
            }
        }
コード例 #28
0
ファイル: TwoKeyHashMap.cs プロジェクト: tvn-cosine/aima.net
 public bool Add(KeyValuePair <Pair <K1, K2>, V> item)
 {
     return(backingMap.Add(item));
 }
コード例 #29
0
 public static void Add(KRTransform t)
 {
     _Map.Add(t);
 }
コード例 #30
0
ファイル: DDFMap.cs プロジェクト: gixslayer/darktech
 public void Add(string name, DDFBase value)
 {
     // Must be a unique name.
     entries.Add(name, value);
 }