public static bool Deserialize(string s, IDictionary <string, double> dict, Deep deep) { KeyValuePair <string, string>[] keyValues; if (preDeserializeDict(s, out keyValues, deep)) { foreach (var keyValue in keyValues) { double value; if (double.TryParse(keyValue.Value, out value)) { dict.Add(keyValue.Key, value); } else { throw new ArgumentException(string.Format("String '{0}' constaint illegal values for dict<{1},{2}>.", keyValue, dict.GetType().GetGenericArguments()[0].Name, dict.GetType().GetGenericArguments()[1].Name)); } } return(true); } else { dict = null; return(false); } }
private static string serialize(object o, Deep deep) { if (o is String s) { return(s); } else if (o is bool b) { return(b ? "1" : "0"); } else if (o is InnerSerializerV1_0 innerSerializable) { return(innerSerializable.Serialize(deep.NEXT)); } else if (o is IDictionary dictionary) { return(Serialize(dictionary, deep.NEXT)); } else if (o is IEnumerable enumerable) { return(Serialize(enumerable, deep.NEXT)); } else if (o is double @double) { return(((ProtocolDouble)@double).ToString()); } else if (o == null) { return(string.Empty); } else { return(o.ToString()); } }
public static bool Deserialize(string orig, Deep deep, out MineGunV1_0 deserialized) { string[] rest; if (ProtocolV1_0Utils.GetParams(orig, NAME, deep, out rest)) { if (rest.Length == 4) { int[] paramsInt; string[] zonesString; if (Parser.TryParse(new int[] { 0, 1, 2 }, rest, out paramsInt) && ProtocolV1_0Utils.Deserialize(rest[3], out zonesString, deep.NEXT)) { ZoneV1_0[] zones = new ZoneV1_0[zonesString.Length]; for (int i = 0; i < zones.Length; i++) { if (!ZoneV1_0.Deserialize(zonesString[i], deep.NEXT.NEXT, out zones[i])) { deserialized = null; return(false); } } deserialized = new MineGunV1_0(paramsInt[0], paramsInt[1], paramsInt[2], zones); return(true); } } } deserialized = null; return(false); }
public static string ConvertToDeeper(string serializedString, Deep toDeep) { StringBuilder sb = new StringBuilder(); char[] serializedCharacter = serializedString.ToCharArray(); for (int i = 0; i < serializedCharacter.Length; i++) { Deep replaceDeep = toDeep; Deep replacedDeep = DEFAULT; while (replaceDeep != null) { if (serializedCharacter[i] == replacedDeep.SEPARATOR) { sb.Append(replaceDeep.SEPARATOR); goto nextCharacter; } replaceDeep = replaceDeep.NEXT; replacedDeep = replacedDeep.NEXT; } sb.Append(serializedCharacter[i]); nextCharacter: ; } return(sb.ToString()); }
public static string ConvertToShallowly(string serializedString, int howManyTimes) { if (howManyTimes <= 0) { throw new ArgumentException(nameof(howManyTimes) + "have to be positive."); } StringBuilder sb = new StringBuilder(); char[] serializedCharacter = serializedString.ToCharArray(); for (int i = 0; i < serializedCharacter.Length; i++) { Deep replacedDeep = LAST; while (replacedDeep != DEFAULT) { if (serializedCharacter[i] == replacedDeep.SEPARATOR) { Deep addedDeep = replacedDeep; for (int j = 0; j < howManyTimes && addedDeep != DEFAULT; j++) { addedDeep = addedDeep.PREV; } sb.Append(addedDeep.SEPARATOR); goto nextCharacter; } replacedDeep = replacedDeep.PREV; } sb.Append(serializedCharacter[i]); nextCharacter: ; } return(sb.ToString()); }
/// <summary> /// Creates a <see cref="ParameterDefinition"/> list that represents this filter. /// </summary> public ParameterDefinition[] ToParameterDefinition() { var result = new List <ParameterDefinition>(); if (Deep) { result.Add(ParameterDefinition.Create(DeepParamName, Deep.ToString())); } if (LimitResult >= 0) { result.Add(ParameterDefinition.Create(LimitResultParamName, LimitResult.ToString())); } if (MeasurementUuids != null && MeasurementUuids.Length > 0) { result.Add(ParameterDefinition.Create(MeasurementUuidsParamName, RestClientHelper.ConvertGuidListToString(MeasurementUuids))); } if (RequestedMeasurementAttributes != null && RequestedMeasurementAttributes.AllAttributes != AllAttributeSelection.True && RequestedMeasurementAttributes.Attributes != null) { result.Add(ParameterDefinition.Create(RequestedMeasurementAttributesParamName, RestClientHelper.ConvertUInt16ListToString(RequestedMeasurementAttributes.Attributes))); } if (OrderBy != null && OrderBy.Length > 0) { result.Add(ParameterDefinition.Create(OrderByParamName, OrderByToString(OrderBy))); } if (SearchCondition != null) { result.Add(ParameterDefinition.Create(SearchConditionParamName, SearchConditionParser.GenericConditionToString(SearchCondition))); } if (Statistics != MeasurementStatistics.None) { result.Add(ParameterDefinition.Create(StatisticsParamName, Statistics.ToString())); } if (AggregationMeasurements != AggregationMeasurementSelection.Default) { result.Add(ParameterDefinition.Create(AggregationParamName, AggregationMeasurements.ToString())); } if (FromModificationDate.HasValue) { result.Add(ParameterDefinition.Create(FromModificationDateParamName, XmlConvert.ToString(FromModificationDate.Value, XmlDateTimeSerializationMode.RoundtripKind))); } if (ToModificationDate.HasValue) { result.Add(ParameterDefinition.Create(ToModificationDateParamName, XmlConvert.ToString(ToModificationDate.Value, XmlDateTimeSerializationMode.RoundtripKind))); } return(result.ToArray()); }
// =========== DICTIONARY ======== public static string Serialize(IDictionary dict, Deep deep) { List <string> serializeList = new List <string>(); foreach (var key in dict.Keys) { serializeList.Add(serialize(key, deep) + DICTIONARY_KEY_VALUE_SEPARATOR + serialize(dict[key], deep)); } return(SerializeArray(serializeList, deep)); }
private Deep(char separator, Deep next) { SEPARATOR = separator; SEPARATOR_STRING = "" + separator; NEXT = next; if (next != null) { next.PREV = this; } }
public void PlayerFire(Player player) { var shell = new Shell { Id = _shellCounter++, LaunchTime = _time }; shell.Origin = Deep.Clone(player.Tank.ToDto()); // make the shell appear to come from the correct side of the tank shell.Origin.Point.X += Convert.ToInt32(player.Tank.Turret.Angle * Tank.Width / 180); player.Shells.Add(shell); player.Tank.IsFiring = true; }
public static bool Deserialize(string orig, Deep deep, out ZoneV1_0 deserialized) { string[] rest; int[] param; if (ProtocolV1_0Utils.GetParams(orig, NAME, deep, out rest)) { if (rest.Length == 2 && Parser.TryParse(rest, out param)) { deserialized = new ZoneV1_0(param[0], param[1]); return(true); } } deserialized = null; return(false); }
static void Main(string[] args) { var s1 = new Shallow(new Thing(23)); var s2 = (Shallow)s1.Clone(); Console.WriteLine(s2.T.I); // 23 s1.T.I = 9; Console.WriteLine(s2.T.I); // 9 var d1 = new Deep(new Thing(23)); var d2 = (Deep)d1.Clone(); Console.WriteLine(d2.T.I); // 23 d1.T.I = 9; Console.WriteLine(d2.T.I); // 23 }
private void FormStrain_VisibleChanged(object sender, EventArgs e) { if (this.Visible) { skipCrystalChangedEvent = true; CrystalControl.GenerateFromInterface(); originalCrystal = Deep.Copy(CrystalControl.Crystal); SetStrainedCrystal(); skipCrystalChangedEvent = false; } else { resetOriginalCrystal(); } }
public static string Serialize(IEnumerable enumerable, Deep deep) { StringBuilder s = new StringBuilder(); s.Append("["); foreach (var item in enumerable) { s.Append(serialize(item, deep)); s.Append(deep.SEPARATOR); } if (s.Length > 1) { s.Remove(s.Length - 1, 1); // remove last separator } return(s.Append("]").ToString()); }
public static string SerializeParams(string commandName, Deep deep, params object[] param) { StringBuilder s = new StringBuilder(); s.Append(commandName); s.Append("("); for (int i = 0; i < param.Length; i++) { if (i > 0) { s.Append(deep.SEPARATOR); } object o = param[i]; s.Append(serialize(o, deep)); } return(s.Append(")").ToString()); }
public static bool Deserialize(string s, IDictionary <string, string> dict, Deep deep) { KeyValuePair <string, string>[] keyValues; if (preDeserializeDict(s, out keyValues, deep)) { foreach (var keyValue in keyValues) { dict.Add(keyValue); } return(true); } else { dict = null; return(false); } }
public static bool Deserialize(String orig, Deep deep, out ArmorV1_0 deserialized) { string[] rest; if (ProtocolV1_0Utils.GetParams(orig, NAME, deep, out rest)) { if (rest.Length == 3) { int[] paramsInt; if (Parser.TryParse(rest, out paramsInt)) { deserialized = new ArmorV1_0(paramsInt[0], paramsInt[1], paramsInt[2]); return(true); } } } deserialized = null; return(false); }
private void crystalControl_CrystalChanged(object sender, EventArgs e) { if (skipCrystalChangedEvent || !this.Visible) { return; } //ここが呼ばれるのは、crystalControl側が操作されて結晶が変更される場合のみ。 //このformStrainがcrystalControlを変更する時は、その時だけこのイベントを無視する skipCrystalChangedEvent = true; CrystalControl.GenerateFromInterface(); originalCrystal = Deep.Copy(CrystalControl.Crystal); SetStrainedCrystal(); skipCrystalChangedEvent = false; numericBoxStrain_ValueChanged(new object(), new EventArgs()); }
public static bool Deserialize(string orig, Deep deep, out EndLapCommandV1_0 deserialized) { string[] rest; if (ProtocolV1_0Utils.GetParams(orig, COMMAND_NAME, deep, out rest)) { if (rest.Length == 3) { int gold, score; LapState lapState; if (Enum.TryParse(rest[0], true, out lapState) && int.TryParse(rest[1], out gold) && int.TryParse(rest[2], out score)) { deserialized = new EndLapCommandV1_0(lapState, gold, score); return(true); } } } deserialized = null; return(false); }
public static bool Deserialize(String orig, Deep deep, out MotorV1_0 deserialized) { string[] rest; if (ProtocolV1_0Utils.GetParams(orig, NAME, deep, out rest)) { if (rest.Length == 7) { ProtocolDouble[] paramsDouble; int[] paramsInt; if (Parser.TryParse(new int[] { 0, 1, 2, 3, 4 }, rest, out paramsDouble) && Parser.TryParse(new int[] { 5, 6 }, rest, out paramsInt)) { deserialized = new MotorV1_0(paramsDouble[0], paramsDouble[1], paramsDouble[2], paramsDouble[3], paramsDouble[4], paramsInt[0], paramsInt[1]); return(true); } } } deserialized = null; return(false); }
public static bool Deserialize(string s, out int[] array, Deep deep) { string[] rest; if (StringUtils.GetRestOfStringSplit(s, "[", "]", out rest, deep.SEPARATOR)) { array = new int[rest.Length]; for (int i = 0; i < rest.Length; i++) { if (!int.TryParse(rest[i], out array[i])) { return(false); } } return(true); } else { array = null; return(false); } }
public void SetCrystal() { CrystalControl.GenerateFromInterface(); OriginalCrystal = Deep.Copy(CrystalControl.Crystal); OriginalCrystal.SetAxis(); CrystalControl.SymmetrySeriesNumber = 1; CrystalControl.Crystal.Atoms = new Atoms[0]; for (int i = 0; i < OriginalCrystal.Atoms.Length; i++) { for (int j = 0; j < OriginalCrystal.Atoms[i].Atom.Count; j++) { var atom = Deep.Copy(OriginalCrystal.Atoms[i]); atom.X = OriginalCrystal.Atoms[i].Atom[j].X; atom.Y = OriginalCrystal.Atoms[i].Atom[j].Y; atom.Z = OriginalCrystal.Atoms[i].Atom[j].Z; CrystalControl.Crystal.AddAtoms(atom); } } CrystalControl.SetToInterface(); }
private void SetStrainedCrystal() { skipCrystalChangedEvent = true; CrystalControl.SymmetrySeriesNumber = 1; CrystalControl.Crystal.Atoms = new Atoms[0]; for (int i = 0; i < originalCrystal.Atoms.Length; i++) { for (int j = 0; j < originalCrystal.Atoms[i].Atom.Count; j++) { var atom = Deep.Copy(originalCrystal.Atoms[i]); atom.X = originalCrystal.Atoms[i].Atom[j].X; atom.Y = originalCrystal.Atoms[i].Atom[j].Y; atom.Z = originalCrystal.Atoms[i].Atom[j].Z; CrystalControl.Crystal.AddAtoms(atom); } } CrystalControl.SetToInterface(); numericBoxStrain_ValueChanged(new object(), new EventArgs()); skipCrystalChangedEvent = false; }
// =========== ARRAY ======== public static string SerializeArray(IEnumerable enumerable, Deep deep) { StringBuilder s = new StringBuilder(); s.Append("["); foreach (var item in enumerable) { InnerSerializerV1_0 innerSerializable = item as InnerSerializerV1_0; if (innerSerializable != null) { s.Append(innerSerializable.Serialize(deep.NEXT)); } else { s.Append(item); } s.Append(deep.SEPARATOR); } if (s.Length > 1) { s.Remove(s.Length - 1, 1); // remove last separator } return(s.Append("]").ToString()); }
public DmConsole SetBackgroundColor(Deep.Magic.Color background) { this.BackgroundColor = background; return this.console; }
public string Serialize(Deep deep) { return(ProtocolV1_0Utils.SerializeParams(NAME, deep, MAX_HP, COST, ID)); }
private static bool preDeserializeDict(string s, out KeyValuePair <string, string>[] dict, Deep deep) { string[] rest; if (Deserialize(s, out rest, deep)) { dict = new KeyValuePair <string, string> [rest.Length]; string[] keyValue; for (int i = 0; i < dict.Length; i++) { if (StringUtils.GetRestOfStringSplit(rest[i], string.Empty, string.Empty, out keyValue, DICTIONARY_KEY_VALUE_SEPARATOR)) { if (keyValue.Length == 2) { dict[i] = new KeyValuePair <string, string>(keyValue[0], keyValue[1]); } else { throw new ArgumentException(string.Format("S containt illegal dictionary pair '{0}'", rest[i])); } } } return(true); } else { dict = null; return(false); } }
public DmConsole SetColor(Deep.Magic.Color foreground, Deep.Magic.Color background) { this.ForegroundColor = foreground; this.BackgroundColor = background; return this.console; }
public static bool GetParams(string orig, string commandName, Deep deep, out string[] rest) { return(StringUtils.GetRestOfStringSplit(orig, commandName + "(", ")", out rest, deep.SEPARATOR)); }
private void GenerateTree_Load(object sender, EventArgs e) { InputDeep.Text = Deep.ToString(); InputNodes.Text = NodesCount.ToString(); }
// Just wrappers, for the sake of chaining. public DmConsole SetForegroundColor(Deep.Magic.Color foreground) { this.ForegroundColor = foreground; return this.console; }
public string Serialize(Deep deep) { return(ProtocolV1_0Utils.SerializeParams(COMMAND_NAME, deep, X, Y)); }
public static bool Deserialize(string s, out string[] array, Deep deep) { return(StringUtils.GetRestOfStringSplit(s, "[", "]", out array, deep.SEPARATOR)); }
public string Serialize(Deep deep) { return(ProtocolV1_0Utils.SerializeParams(NAME, deep, ID, COST, MAX_MINES, ZONES)); }