public Dictionary<string, object> Insert(string tableName, Dictionary<string, object> row, ITransaction transaction = null) { if (!DataStore.ContainsKey(tableName)) DataStore.Add(tableName, new FakeDBTable()); var table = DataStore[tableName]; var dictToUse = row.Copy(); //var id = DataStore[tableName].Count + 1; var primaryKeys = Analyzer.GetPrimaryKeys(tableName); var autoKey = Analyzer.GetAutoNumberKey(tableName); if (autoKey != null) { if (!dictToUse.ContainsKey(autoKey)) dictToUse.Add(autoKey, table.NextAutoKey++); else dictToUse[autoKey] = table.NextAutoKey++; } var invalid = primaryKeys.Where(key => dictToUse[key] == null); if (invalid.Any()) throw new KeyNotSetException(tableName, invalid); table.Add(dictToUse); return dictToUse.WhereKeys(key => primaryKeys.Contains(key)); }
public void Copy() { Dictionary<string, string> dict = new Dictionary<string, string>(); dict.Add("Key 1", "Value 1"); dict.Add("Key 2", "Value 2"); dict.Add("Key 3", "Value 3"); var dictCopy = dict.Copy(); Assert.AreEqual(dictCopy, dict); }
public void DictionaryIsCopied() { var dict = new Dictionary<int, Exception>(); dict.Add(0, new Exception("Test")); var copy = (Dictionary<int, Exception>) dict.Copy(); Assert.AreNotSame(copy[0], dict[0]); Assert.AreEqual(copy[0].Message, dict[0].Message); }
public static Dictionary <TKey, TValue> Remove <TKey, TValue>(this Dictionary <TKey, TValue> current, Func <KeyValuePair <TKey, TValue>, bool> method) { foreach (var item in current.Copy()) { if (method(item)) { current.Remove(item.Key); } } return(current); }
public void DictionaryIsCopied() { var dict = new Dictionary <int, Exception>(); dict.Add(0, new Exception("Test")); var copy = (Dictionary <int, Exception>)dict.Copy(); Assert.AreNotSame(copy[0], dict[0]); Assert.AreEqual(copy[0].Message, dict[0].Message); }
/// <summary> /// Combines the dictionary with another one. Duplicate keys /// are overwritten. /// </summary> public static Dictionary <Tk, Tv> Combine <Tk, Tv>( this Dictionary <Tk, Tv> self, Dictionary <Tk, Tv> second) { var result = self.Copy(); foreach (var kvp in second) { result[kvp.Key] = kvp.Value; } return(result); }
public InputManager(InputType inputType) { // Default input type CurrentInputType = inputType; // PressedThisFrame & HeldLastFrame & HeldThisFrame EmptyInput = new Dictionary <Input, bool>() { { Input.Up, false }, { Input.Down, false }, { Input.Left, false }, { Input.Right, false }, { Input.Action1, false }, { Input.Action2, false }, { Input.L1, false }, { Input.L2, false }, { Input.Special1, false }, { Input.Special2, false } }; PressedThisFrame = EmptyInput.Copy(); HeldThisFrame = PressedThisFrame.Copy(); // Keyboard input KeyboardInput = new Dictionary <Keys, Input>() { { Keys.Up, Input.Up }, { Keys.Down, Input.Down }, { Keys.Left, Input.Left }, { Keys.Right, Input.Right }, { Keys.Z, Input.Action1 }, { Keys.X, Input.Action2 }, { Keys.A, Input.L1 }, { Keys.S, Input.L2 }, { Keys.OemComma, Input.Special1 }, { Keys.OemPeriod, Input.Special2 } }; // Controller input ControllerInput = new Dictionary <Buttons, Input>() { { Buttons.DPadUp, Input.Up }, { Buttons.DPadDown, Input.Down }, { Buttons.DPadLeft, Input.Left }, { Buttons.DPadRight, Input.Right }, { Buttons.A, Input.Action1 }, { Buttons.B, Input.Action2 }, { Buttons.LeftShoulder, Input.L1 }, { Buttons.RightShoulder, Input.L2 }, { Buttons.LeftTrigger, Input.Special1 }, { Buttons.RightTrigger, Input.Special2 }, }; }
public void DictionaryIsCopied() { Dictionary <int, FooBar> dict = new Dictionary <int, FooBar>(); dict.Add(0, new FooBar(3)); Dictionary <int, FooBar> copy = dict.Copy(); Assert.NotSame(copy, dict); Assert.NotSame(copy[0], dict[0]); Assert.NotEqual(copy[0], dict[0]); Assert.Equal(copy[0].Foo, dict[0].Foo); }
public void DictionaryIsCopied() { Dictionary <int, Exception> dict = new Dictionary <int, Exception> { { 0, new Exception("Test") } }; Dictionary <int, Exception> copy = (Dictionary <int, Exception>)dict.Copy(); Assert.AreNotSame(copy[0], dict[0]); Assert.AreEqual(copy[0].Message, dict[0].Message); }
public void Update() { HeldLastFrame = HeldThisFrame.Copy(); HeldThisFrame = EmptyInput.Copy(); PressedThisFrame = EmptyInput.Copy(); if (CurrentInputType == InputType.Keyboard) { foreach (var key in Keyboard.GetState().GetPressedKeys()) { if (KeyboardInput.ContainsKey(key)) { HeldThisFrame[KeyboardInput[key]] = true; if (HeldThisFrame[KeyboardInput[key]] != HeldLastFrame[KeyboardInput[key]]) { PressedThisFrame[KeyboardInput[key]] = true; } } } } else if (CurrentInputType == InputType.Controller) { GamePadState gps = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One); foreach (var btn in ControllerInput) { if (gps.IsButtonDown(btn.Key)) { HeldThisFrame[ControllerInput[btn.Key]] = true; if (HeldThisFrame[ControllerInput[btn.Key]] != HeldLastFrame[ControllerInput[btn.Key]]) { PressedThisFrame[ControllerInput[btn.Key]] = true; } } } } }
public void Copy_Extension_Test() { short a = 1; int b = 2; long c = 3; float d = 4.0f; double e = 5.0; string f = "foo"; var g = new ClientRetrievalTask { Enabled = false }; var h = new List <string>(new[] { "foo" }); var i = new Dictionary <string, object> { { "foo", new object() } }; object objA = (short)1; object objB = 2; object objC = (long)3; object objD = 4.0f; object objE = 5.0; object objF = "foo"; object objG = new ClientRetrievalTask { Enabled = false }; object objH = new List <string>(new[] { "foo" }); object objI = new Dictionary <string, object> { { "foo", new object() } }; Assert.AreEqual(1, a.Copy()); Assert.AreEqual(2, b.Copy()); Assert.AreEqual(3, c.Copy()); Assert.AreEqual(4.0f, d.Copy()); Assert.AreEqual(5.0, e.Copy()); Assert.AreEqual("foo", f.Copy()); Assert.AreNotSame(g, g.Copy()); Assert.AreNotSame(h, h.Copy()); Assert.AreNotSame(i, i.Copy()); Assert.AreEqual(1, objA.Copy()); Assert.AreEqual(2, objB.Copy()); Assert.AreEqual(3, objC.Copy()); Assert.AreEqual(4.0f, objD.Copy()); Assert.AreEqual(5.0, objE.Copy()); Assert.AreEqual("foo", objF.Copy()); Assert.AreNotSame(g, objG.Copy()); Assert.AreNotSame(h, objH.Copy()); Assert.AreNotSame(i, objI.Copy()); }
/// <summary> /// Handles refreshing the key-values /// </summary> private void DataStoreRefreshHandler() { var currentTime = DateTime.Now; _lifeTimes.Copy().ForEach(x => { if (currentTime - _lastRun >= x.Value) { Delete(x.Key); } }); _lastRun = currentTime; }
public static Dictionary <string, string> LocateAllOnlyPossibles(this Dictionary <string, string> puzzle) { if (puzzle == null) { return(null); } var toReturn = puzzle.Copy(); var units = Parser.Units(); foreach (var u in units) { toReturn = toReturn.LocateOnlyPossible(u); } return(toReturn); }
public static Dictionary <string, string> RunConstraints(this Dictionary <string, string> puzzle) { if (puzzle == null) { return(null); } if (puzzle.IsSolved()) { return(puzzle); } var previousPuzzle = puzzle.Copy(); var newPuzzle = puzzle.Copy(); newPuzzle = newPuzzle.EliminateAllSingletons().EliminateAllTwins(); newPuzzle = newPuzzle.EliminateAllSingletons().LocateAllOnlyPossibles(); //Console.WriteLine($"Found {previousPuzzle.Diff(newPuzzle)} diffs, rerunning."); if (previousPuzzle.Diff(newPuzzle) == 0) { return(newPuzzle); } return(newPuzzle.RunConstraints()); }
public static Dictionary <string, string> EliminateSingleton(this Dictionary <string, string> puzzle, string cell, string value) { if (puzzle == null) { return(null); } var puzz = puzzle.Copy(); var peers = Parser.Peers()[cell]; foreach (var peerCell in peers.Where(x => x != cell)) { puzz[peerCell] = puzz[peerCell].Replace(value, ""); } return(puzz); }
public static Dictionary <string, string> EliminateAllSingletons(this Dictionary <string, string> puzzle) { if (puzzle == null) { return(null); } var toReturn = puzzle.Copy(); foreach (var key in puzzle.Keys) { if (toReturn[key].Length == 1) { toReturn = toReturn.EliminateSingleton(key, toReturn[key]); } } return(toReturn); }
public void Diff() { var a = new Dictionary<string, int>() { { "A", 1 }, { "B", 2 }, {"C", 3}}; var b = a.Assoc("B", -2); var diff = a.Diff(b); Assert.AreEqual("([B,(2, -2)])", diff.Print()); diff = a.Diff(b, "A".And("B")); Assert.AreEqual("([B,(2, -2)])", diff.Print()); diff = a.Diff(b, "A".And("C")); Assert.AreEqual("()", diff.Print()); var copyA = a.Copy(); diff = a.Diff(copyA); Assert.AreEqual("()", diff.Print()); }
public static Dictionary <string, string> EliminateTwin(this Dictionary <string, string> puzzle, List <string> unit, string value) { if (puzzle == null) { return(null); } var toReturn = puzzle.Copy(); var nonPairedCells = unit.Where(x => toReturn[x] != value); foreach (var nonCell in nonPairedCells) { foreach (var v in value.ToCharArray()) { toReturn[nonCell] = toReturn[nonCell].Replace(v.ToString(), ""); } } return(toReturn); }
public override double Evaluate(Dictionary <string, double> values) { if (values != null && values.ContainsKey(iterator)) { throw new Exception("A sum cannot be evaluated if its iterator variable has been assigned."); } double result = 0; var newValues = values == null ? new Dictionary <string, double>() : values.Copy(); var minVal = min.Evaluate(values); var maxVal = max.Evaluate(values); for (double d = minVal; d <= maxVal; d++) { newValues[iterator] = d; Console.WriteLine(result += body.Evaluate(newValues)); } return(result); }
public void Copy_Extension_Test() { short a = 1; int b = 2; long c = 3; float d = 4.0f; double e = 5.0; string f = "foo"; var g = new ClientRetrievalTask { Enabled = false }; var h = new List<string>(new[] { "foo" }); var i = new Dictionary<string, object> { { "foo", new object() } }; object objA = (short)1; object objB = 2; object objC = (long)3; object objD = 4.0f; object objE = 5.0; object objF = "foo"; object objG = new ClientRetrievalTask { Enabled = false }; object objH = new List<string>(new[] { "foo" }); object objI = new Dictionary<string, object> { { "foo", new object() } }; Assert.AreEqual(1, a.Copy()); Assert.AreEqual(2, b.Copy()); Assert.AreEqual(3, c.Copy()); Assert.AreEqual(4.0f, d.Copy()); Assert.AreEqual(5.0, e.Copy()); Assert.AreEqual("foo", f.Copy()); Assert.AreNotSame(g, g.Copy()); Assert.AreNotSame(h, h.Copy()); Assert.AreNotSame(i, i.Copy()); Assert.AreEqual(1, objA.Copy()); Assert.AreEqual(2, objB.Copy()); Assert.AreEqual(3, objC.Copy()); Assert.AreEqual(4.0f, objD.Copy()); Assert.AreEqual(5.0, objE.Copy()); Assert.AreEqual("foo", objF.Copy()); Assert.AreNotSame(g, objG.Copy()); Assert.AreNotSame(h, objH.Copy()); Assert.AreNotSame(i, objI.Copy()); }
private void OnEnable() { Faces.Copy(ActorModel.Model.GetFaceDictionary()); actor.UpdateFace(Faces); SetType(0); if (ActorModel.Model.GetMoney() >= need_money) { no_money_tip.SetActive(false); sure_button.interactable = true; sure_button.GetComponentInChildren <Text>().color = Color.white; } else { no_money_tip.SetActive(true); sure_button.interactable = false; sure_button.GetComponentInChildren <Text>().color = Color.gray; } }
private static Dictionary <string, string> Search(Dictionary <string, string> values) { if (values == null) { return(null); // failed earlier } if (squares.All(s => values[s].Length == 1)) { return(values); // solved } var min = squares .Select(s => new { s, len = values[s].Length }) .Where(sl => sl.len > 1) .OrderBy(sl => sl.len) .First() .s; var seq = values[min] .Select(d => Search(Assign(values.Copy(), min, d))); return(seq.Where(it => it != null).FirstOrDefault()); }
public void ReferenceTypeDictionaryIsCopied() { Dictionary <int, FooBar> dict = new Dictionary <int, FooBar>(); dict.Add(0, new FooBar(3)); var stuffb1 = dict[0]; Dictionary <int, FooBar> copy = dict.Copy(); var stuff = copy[0]; var stuff1 = dict[0]; Assert.NotSame(copy, dict); Assert.NotEqual(copy.Single(), dict.Single()); Assert.NotEqual(copy.Single(), dict.Single()); // these should be equal because it's a copy (and the key is a value type) Assert.Equal(copy.Single().Key, dict.Single().Key); Assert.Equal(copy.Single().Key, dict.Single().Key); Assert.NotSame(copy.Single().Value, dict.Single().Value); Assert.NotEqual(copy.Single().Value, dict.Single().Value); Assert.Equal(copy.Single().Value.Foo, dict.Single().Value.Foo); }
public void WriteEntries(IEnumerable <KeyValuePair <string, object> > entries) { if (entries.Any()) { using (GetNewMutexScope()) { bool changesMade = false; Dictionary <string, JRaw> originalSettings = LoadFile(); Dictionary <string, JRaw> newSettings = new Dictionary <string, JRaw>(PathComparer); if (originalSettings.Any()) { originalSettings.Copy(newSettings); } foreach (KeyValuePair <string, object> kvp in entries) { string path = NormalizePath(kvp.Key); if (kvp.Value != null) { JRaw jRawValue = new JRaw(JsonConvert.SerializeObject(kvp.Value)); if (!newSettings.ContainsKey(path) || !newSettings[path].Equals(jRawValue)) { newSettings[path] = jRawValue; changesMade = true; } } else { if (newSettings.Remove(path)) { changesMade = true; } } } if (changesMade) { SaveFile(originalSettings, newSettings); } } } }
/// <summary> /// 获取枚举字典列表 /// </summary> /// <param name="en">枚举类型</param> /// <param name="isIntValue">返回枚举值是否是int类型</param> /// <returns></returns> public static Dictionary <string, string> GetDescriptionList(this Enum en, bool isIntValue = true) { var enType = en.GetType(); string key = string.Concat(enType.FullName, isIntValue); Dictionary <string, string> enums = enumDirs.GetOrAdd(key, (k) => { var dirs = new Dictionary <string, string>(); var values = Enum.GetValues(enType); foreach (var value in values) { var name = value.ToString(); string resultValue = isIntValue ? ((int)value).ToString() : name; string description; var attr = enType.GetField(name).GetCustomAttributes(typeof(ALDescriptAttribute), false); if (attr.Length > 0) { description = ((ALDescriptAttribute)attr[0]).Description; } else { attr = enType.GetField(name).GetCustomAttributes(typeof(DescriptionAttribute), false); description = attr == null ? name : ((DescriptionAttribute)attr[0]).Description; } dirs.Add(resultValue, description); } return(dirs); }); if (enums != null) { return(enums.Copy()); } else { return(enums); } }
/// <summary> /// 枚举类型的枚举项与描述转为NameValue List(Name为描述 Value为枚举名) /// </summary> /// <param name="enumType"></param> /// <returns></returns> public static Dictionary <int, string> ToDictionary(this Type enumType) { if (DictKeyDescription.ContainsKey(enumType)) { return(DictKeyDescription[enumType].Copy()); } var dict = new Dictionary <int, string>(); foreach (MemberInfo memberInfo in enumType.GetMembers()) { foreach (Attribute attr in Attribute.GetCustomAttributes(memberInfo)) { if (attr.GetType() == typeof(DescriptionAttribute)) { dict.Add(Enum.Parse(enumType, memberInfo.Name).GetHashCode(), ((DescriptionAttribute)attr).Description); break; } } } DictKeyDescription.Add(enumType, dict); return(dict.Copy()); }
public DeleteOp(string table, Dictionary<string, object> keys) : base(table) { Keys = keys.Copy(); }
public static ConditionalData ParseIfBlock(string line, StringReader reader, Dictionary <string, object> variables) { //if (i > 50) { //if (i <= 50) { //if(i > 50) { //if (i > 50){ string mod = line.Remove(0, 2).TrimStart(); //(i > 50) { //(i <= 50) { //(i > 50) { //(i == 50){ mod = mod.Replace("{", "").Trim(); if (line.IndexOf('(') == -1) { throw new ParsingException("If statement invalid syntax!", line); } if (line.IndexOf(')') == -1) { throw new ParsingException("If statement invalid syntax!", line); } mod = mod.Trim('(', ')'); int equalsIndex = mod.IndexOf("="); if (equalsIndex == mod.LastIndexOf("=") && equalsIndex != -1 && mod[equalsIndex - 1] != '!') { throw new ParsingException("If statement invalid syntax (== for comparison)!", line); } mod = mod.Replace("==", "="); mod = mod.Replace("!=", "<>"); ExpressionContext context = FleeHelper.GetExpression(variables); try { IGenericExpression <bool> ifCondition = context.CompileGeneric <bool>(mod); if (!line.EndsWith("{")) { BlockParser.ReadToBlock(reader, line); } List <string> lines = BlockParser.ParseBlock(reader); List <ParsedData> isStatement = new List <ParsedData>(); Queue <ParsedData> data = CommandParser.Parse(string.Join(Environment.NewLine, lines), MainWindow.Instance, variables); isStatement.AddRange(data); return(new ConditionalData(line, ifCondition, data, variables.Copy())); } catch (ParsingException) { throw; } catch (Exception e) { throw new ParsingException("Invalid boolean expression!", line, e); } }
private static ParsedData ParseLine(string line, StringReader reader, Dictionary <string, object> variables) { if (string.IsNullOrWhiteSpace(line) || line.Trim() == "}") { return(null); } string original = line; if (line.Length > 3) { if (line[0] == '{' && char.IsDigit(line[1]) && line[2] == '}') { line = line.Remove(0, 3); } } if (line.StartsWith("//")) { return(null); } if (LineValidators.IsFunctionCall(line, out FunctionCallInfo info)) { if (conditionals.Count > 0) { conditionals.Peek().IsModifiable = false; } switch (info.FunctionName) { case "Rotate": { return(new RotateParseData(ParseGenericExpression <double>(info.GetArg(0, line), line, variables), info, variables.Copy(), original)); } case "Forward": { return(new ForwardParseData(ParseGenericExpression <double>(info.GetArg(0, line), line, variables), variables.Copy(), original)); } case "SetBrushSize": { return(new BrushSizeData(ParseGenericExpression <double>(info.GetArg(0, line), line, variables), variables.Copy(), original)); } case "PenUp": { return(new PenPositionData(false, variables.Copy(), original)); } case "PenDown": { return(new PenPositionData(true, variables.Copy(), original)); } case "SetColor": { return(new ColorData(info.Arguments, variables.Copy(), original)); } case "MoveTo": { return(new MoveData(info.Arguments, variables.Copy(), original)); } case "SetLineCapping": { return(new BrushCappingData(info.Arguments, variables.Copy(), original)); } case "StoreTurtlePosition": { return(new StoredPositionData(info.Arguments, variables.Copy(), original)); } case "RestoreTurtlePosition": { return(new RestorePositionData(info.Arguments, variables.Copy(), original)); } case "CaptureScreenshot": { return(new ScreenCaptureData(info.Arguments, original, variables.Copy())); } default: { throw new ParsingException($"Unknown function!", line); } } } if (LineValidators.IsForLoop(line)) { if (conditionals.Count > 0) { conditionals.Peek().IsModifiable = false; } ForLoopData data = ForLoopParser.ParseForLoop(line, reader, variables); return(data); } if (LineValidators.IsConditional(line)) { if (line.Contains("if")) { ConditionalData data = IfStatementParser.ParseIfBlock(line, reader, variables.Copy()); conditionals.Push(data); return(data); } if (line.Contains("else")) { ConditionalData latest = conditionals.Peek(); latest.AddElse(reader, line); latest.IsModifiable = false; return(null); } } if (LineValidators.IsVariableDeclaration(line, variables, out (string, string, string)variableDef)) { IDynamicExpression valueObj = ParseDynamicExpression(variableDef.Item3, original, variables); object value = valueObj.Evaluate(); variables[variableDef.Item2] = value; return(new VariableData(variableDef.Item2, valueObj, variables, line)); } throw new ParsingException($"Unexpected squence!", line); }
/// <summary> /// uses a dictionary to quickly calculate UI elements for rows, and position them in the view /// </summary> public Dictionary <object, DataSheetRow> RefreshRowUi() { // map list elements to row UI Dictionary <object, DataSheetRow> srcToRowUiMap = new Dictionary <object, DataSheetRow>(); for (int i = 0; i < contentRectangle.childCount; ++i) { DataSheetRow rObj = contentRectangle.GetChild(i).GetComponent <DataSheetRow>(); if (rObj == null) { continue; } if (rObj.obj == null) { throw new Exception("found a row (" + rObj.transform.HierarchyPath() + ") without source object at index " + i); } if (srcToRowUiMap.TryGetValue(rObj.obj, out DataSheetRow uiElement)) { throw new Exception("multiple row elements for row " + i + ": " + rObj.obj); } srcToRowUiMap[rObj.obj] = rObj; } List <DataSheetRow> unused = new List <DataSheetRow>(); // check to see if any of the UI rows are not being used by the datasheet (should be removed or replaced) Dictionary <object, DataSheetRow> unusedMapping = srcToRowUiMap.Copy(); for (int i = 0; i < data.rows.Count; ++i) { RowData rd = data.rows[i]; if (unusedMapping.TryGetValue(rd.obj, out DataSheetRow found)) { unusedMapping.Remove(rd.obj); } } foreach (KeyValuePair <object, DataSheetRow> kvp in unusedMapping) { unused.Add(kvp.Value); srcToRowUiMap.Remove(kvp.Key); } Vector2 cursor = Vector2.zero; // go through all of the row elements and put the row UI elements in the correct spot for (int i = 0; i < data.rows.Count; ++i) { RowData rd = data.rows[i]; // if this row data is missing a UI element if (!srcToRowUiMap.TryGetValue(rd.obj, out DataSheetRow rObj)) { // use one of the unused elements if there is one if (unused.Count > 0) { rObj = unused[unused.Count - 1]; unused.RemoveAt(unused.Count - 1); UpdateRowData(rObj, rd, -cursor.y); } else { // create he UI element, and put it into the content rectangle rObj = CreateRow(data.rows[i], -cursor.y); } rObj.transform.SetParent(contentRectangle); srcToRowUiMap[rObj.obj] = rObj; } rObj.transform.SetSiblingIndex(i); RectTransform rect = rObj.GetComponent <RectTransform>(); //rect.anchoredPosition = cursor; //rect.localPosition = cursor; rObj.LocalPosition = cursor; cursor.y -= rect.rect.height; } if (contentRectangle.childCount > data.rows.Count || unused.Count > 0) { // remove them in reverse order, should be slightly faster for (int i = contentRectangle.childCount - 1; i >= data.rows.Count; --i) { DataSheetRow rObj = contentRectangle.GetChild(i).GetComponent <DataSheetRow>(); srcToRowUiMap.Remove(rObj.obj); unused.Add(rObj); } Show.Log("deleting extra elements: " + unused.JoinToString(", ", go => { DataSheetRow ro = go.GetComponent <DataSheetRow>(); if (ro == null) { return("<null>"); } if (ro.obj == null) { return("<null obj>"); } return(ro.obj.ToString()); })); unused.ForEach(go => { go.transform.SetParent(null); Destroy(go); }); } contentAreaSize.y = -cursor.y; contentRectangle.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, -cursor.y); return(srcToRowUiMap); }
/// <summary> /// Note: row should include any autokeys that the table defines as well, /// since InsertOp cannot determine them internally /// </summary> /// <param name="table"></param> /// <param name="row"></param> public InsertOp(string table, Dictionary<string, object> row) : base(table) { Row = row.Copy(); }
public UpdateOp(string table, Dictionary<string, object> data, Dictionary<string, object> keys) : base(table) { Keys = keys.Copy(); NewValues = data.Copy(); }
public async Task <T> Create(T entity) { var paramsDic = routeParams.Copy(); return(await rest.Post <T>(route, entity, paramsDic)); }
public static Dictionary <string, string> BlindGuess(this Dictionary <string, string> puzzle, IEnumerable <string> alreadyTriedCells) { if (puzzle == null) { return(null); } if (puzzle.IsSolved()) { return(puzzle); } var myPuzz = puzzle.Copy(); var cell = ChooseBestCellToGuess(puzzle, alreadyTriedCells); if (cell == "") { return(puzzle); } var possibleValues = puzzle[cell].ToCharArray().Select(x => x.ToString()); foreach (var guess in possibleValues) { if (myPuzz == null) { return(null); } var testPuzzle = myPuzz.Copy(); Console.WriteLine($"Guessing a value for {cell}, attempted = {guess}, out of possible {myPuzz[cell]}"); testPuzzle = testPuzzle.Assign(cell, guess); if (testPuzzle != null) { testPuzzle = testPuzzle.RunConstraints(); if (testPuzzle.Validate()) { if (testPuzzle.IsSolved()) { Console.WriteLine("SOLVED!"); testPuzzle.Print(); return(testPuzzle); } return(testPuzzle.BlindGuess(new List <string>())); } else { Console.WriteLine(" Invalid after running constraints check. Trying next..."); var unassigned = myPuzz.UnAssign(cell, guess); if (unassigned != null) { myPuzz = unassigned; } } } else { Console.WriteLine(" Invalid, trying next..."); var unassigned = myPuzz.UnAssign(cell, guess); if (unassigned != null) { myPuzz = unassigned; } } } return(puzzle.BlindGuess(alreadyTriedCells.Concat(new List <string> { cell }))); }
public static ForLoopData ParseForLoop(string line, StringReader reader, Dictionary <string, object> inherited) { ExpressionContext context = FleeHelper.GetExpression(inherited); string errorMessage = ""; try { // for(int i = 0; i < 50; i++) { // for (int i=0;i<20;i++){ // for (int i=0;i<20;i++) string mod = line.Remove(0, 3).Trim(); // (int i = 0; i < 50; i++) { // (int i=0;i<20;i++){ // (int i=0;i<20;i++) // (long val=1; val <50; val+=2){ errorMessage = "Invalid for loop syntax!"; mod = mod.Remove(0, 1); // int i = 0; i < 50; i++) { // int i=0;i<20;i++){ // int i=0;i<20;i++) // long val=1; val <50; val+=2){ errorMessage = "Unsupported iteration type!"; mod = mod.Replace("int ", "").Replace("long ", ""); // i = 0; i < 50; i++) { // i=0;i<20;i++){ // i=0;i<20;i++) // val=1; val <50; val+=2){ errorMessage = "Redefinition of variable!"; string variableName = mod.Split('=')[0].Trim(); if (inherited.ContainsKey(variableName)) { throw new ParsingException(errorMessage, line); } mod = mod.Remove(0, mod.IndexOf("=") + 1).Trim(); // 0; i < 50; i++) { // 0 ;i<20;i++){ // 0 ;i<20;i++) // 1; val <50; val+=2){ errorMessage = "Invalid expression for starting value!"; IGenericExpression <int> startValueExp = context.CompileGeneric <int>(mod.Split(';')[0].Trim()); errorMessage = "Invalid for loop syntax!"; mod = mod.Remove(0, mod.IndexOf(";") + 1).Trim(); // i < 50; i++) { // i<20 ;i++){ // i<20 ;i++) // val >=50; val+=2){ mod = mod.Remove(0, variableName.Length).Trim(); // < 50; i++) { // <20 ;i++){ // <20 ;i++) // >=50; val+=2){ string lhs = mod.Split(';')[0].Trim(); ConditionType condition = LogicParsers.ParseCondition(lhs); if (lhs.Contains("=")) { mod = mod.Remove(0, 2).Trim(); } else { mod = mod.Remove(0, 1).Trim(); } string[] endValAndChange = mod.Split(';'); errorMessage = "Invalid expression for end value!"; IGenericExpression <int> endValueExp = context.CompileGeneric <int>(endValAndChange[0].Trim()); errorMessage = "Invalid for loop syntax!"; mod = endValAndChange[1].Trim(); // i++) { // i++){ // i++) // val +=2){ mod = mod.Remove(0, variableName.Length).Trim(); // ++) { // ++){ // ++) // +=2){ OperatorType _operator = LogicParsers.ParseOperator(mod.Split(')')[0]); mod = mod.Remove(0, 2).Trim(); // ) { // ){ // ) // 2){ IGenericExpression <int> changeValueExp = null; if (_operator == OperatorType.PlusEquals || _operator == OperatorType.MinusEquals) { string[] changeSplit = mod.Split(')'); errorMessage = "Invalid expression for change of value!"; changeValueExp = context.CompileGeneric <int>(changeSplit[0]); mod = changeSplit[1].Trim(); } // ) { // ){ // ) // ){ mod = mod.Replace(")", ""); // { //{ if (!mod.Contains("{")) { BlockParser.ReadToBlock(reader, line); } List <string> lines = BlockParser.ParseBlock(reader); return(new ForLoopData(inherited.Copy(), line) { From = startValueExp, To = endValueExp, LoopVariable = variableName, Change = changeValueExp, Condition = condition, Operator = _operator, Lines = lines, }); } catch (ParsingException) { throw; } catch (Exception e) { throw new ParsingException(errorMessage, line, e); } }
/// <summary> /// 获取枚举字典列表 /// </summary> /// <param name="enType">枚举类型</param> /// <param name="isIntValue">返回枚举值是否是int类型</param> /// <returns></returns> public static Dictionary<string, string> ToEnumDirs(this Type enType, bool isIntValue=true) { if (!enType.IsEnum) { throw new ArgumentException("获取枚举字典,参数必须是枚举类型!"); } string key = string.Concat(enType.FullName, isIntValue); Dictionary<string, string> dirs; enumDirs.TryGetValue(key, out dirs); if (dirs != null) return dirs.Copy(); dirs=new Dictionary<string, string>(); var values = Enum.GetValues(enType); foreach (var value in values) { var name = Enum.GetName(enType, value); string resultValue = isIntValue ? ((int)value).ToString() : value.ToString(); var attrList = enType.GetField(name).GetCustomAttributes(typeof(DescriptionAttribute), false) as DescriptionAttribute[]; if (attrList != null && attrList.Length > 0) { dirs.Add(resultValue, attrList[0].Description); continue; } dirs.Add(resultValue, name); } enumDirs.TryAdd(key, dirs); return dirs.Copy(); }