public static string Alter(object o, ETrim trim, ECase cas) { if (o == null) { return(null); } string cad = o.ToString(); switch (trim) { case ETrim.All: cad = cad.Trim(new char[] { '\0', ' ', '\n', '\r' }); break; case ETrim.End: cad = cad.TrimEnd(new char[] { '\0', ' ', '\n', '\r' }); break; case ETrim.Start: cad = cad.TrimStart(new char[] { '\0', ' ', '\n', '\r' }); break; } switch (cas) { case ECase.ToUpperInvariant: cad = cad.ToUpperInvariant(); break; case ECase.ToUpper: cad = cad.ToUpper(); break; case ECase.ToLowerInvariant: cad = cad.ToLowerInvariant(); break; case ECase.ToLower: cad = cad.ToLower(); break; } return(cad); }
// Strategy pattern /// <summary> /// Case Constructor /// </summary> /// <param name="factoryCase"> use ECase enum to select case </param> public Control_Case(ECase factoryCase) { t.Add(ECase.ViewInCreationLangNotAuth, ConcreteCase_ViewInCreationLangNotAuth.Instance); t.Add(ECase.ViewInAltLang, ConcreteCase_ViewInAltLang.Instance); t.Add(ECase.ViewInCreationLangAuth, ConcreteCase_ViewInCreationLangAuth.Instance); t.Add(ECase.Translate, ConcreteCase_Translate.Instance); t.Add(ECase.Edit, ConcreteCase_Edit.Instance); t.Add(ECase.SubEdit1, ConcreteCase_SubEdit1.Instance); t.Add(ECase.SubEdit2, ConcreteCase_SubEdit2.Instance); temp.Add(EComponentType.Label, t[factoryCase].CreateLabel()); temp.Add(EComponentType.Latex, t[factoryCase].CreateLatex()); temp.Add(EComponentType.RichText, t[factoryCase].CreateRich()); temp.Add(EComponentType.RichRichText, t[factoryCase].CreateRichRich()); temp.Add(EComponentType.YouTube, t[factoryCase].CreateYouTube()); }
private void checkWhoWins() { if (gameOver) { return; } gameOver = true; ECase winner = checkFor(); switch (winner) { case ECase.X: scoreBen++; ben_score.Text = scoreBen.ToString(); Log("Ben kazandım..."); break; case ECase.O: scoreSen++; sen_score.Text = scoreSen.ToString(); if (babymode.Checked) { bebeScore++; } Log("Sen kazandın, tebrikler."); break; case ECase.NULL: if (checkIfOver()) { Log("Oyun berabere bitti"); } else { gameOver = false; } break; } }
public StrObjectDict ToDict(bool nullValueAsKey, ECase keyCaseSensitive) { return(StrObjectDict.FromVariable(this, nullValueAsKey, keyCaseSensitive)); }
public static StrObjectDict FromVariable(object o, bool nullValueAsKey, ECase keyCaseSensitive) { return(new StrObjectDict().Merger(o, nullValueAsKey, keyCaseSensitive) as StrObjectDict); }
public static object GetObject(this IDictionary <string, object> dictionary, string key, ECase keyECase) { if (keyECase == ECase.LOWER) { key = key.ToLower(); } else if (keyECase == ECase.UPPER) { key = key.ToUpper(); } object result; if (dictionary.ContainsKey(key)) { result = dictionary[key]; } else { result = null; } return(result); }
public static System.Collections.Generic.IDictionary <string, string> Merger(this System.Collections.Generic.IDictionary <string, string> dictionary, object o, bool nullValueAsKey, ECase keyECase, bool includeInheritedProperty) { if (o != null) { if (o is System.Collections.Generic.IDictionary <string, string> ) { System.Collections.Generic.IDictionary <string, string> dictionary2 = o as System.Collections.Generic.IDictionary <string, string>; foreach (string text in dictionary2.Keys) { if (dictionary.ContainsKey(text.ToUpper())) { dictionary[text.ToUpper()] = dictionary2[text]; } else { dictionary.Add(text.ToUpper(), dictionary2[text]); } } } else { System.Reflection.PropertyInfo[] array = includeInheritedProperty ? o.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public) : o.GetType().GetProperties(System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); System.Reflection.PropertyInfo[] array2 = array; for (int i = 0; i < array2.Length; i++) { System.Reflection.PropertyInfo propertyInfo = array2[i]; string text = propertyInfo.Name; if (keyECase == ECase.UPPER) { text = text.ToUpper(); } else { if (keyECase == ECase.LOWER) { text = text.ToLower(); } } object value = propertyInfo.GetValue(o, null); if (value != null) { if (!dictionary.ContainsKey(text)) { dictionary.Add(text, value.ToString()); } else { dictionary[text] = value.ToString(); } } else { if (nullValueAsKey) { if (!dictionary.ContainsKey(text)) { dictionary.Add(text, null); } else { dictionary[text] = null; } } } } } } return(dictionary); }
public static IDictionary <string, string> Merger(this IDictionary <string, string> dictionary, object o, bool nullValueAsKey, ECase keyECase) { return(dictionary.Merger(o, nullValueAsKey, keyECase, false)); }
public static IDictionary <string, object> Merger(this IDictionary <string, object> dictionary, object o, bool nullValueAsKey, ECase keyECase, bool includeInheritedProperty) { if (o != null) { if (o is IDictionary <string, object> ) { IDictionary <string, object> dictionary2 = o as IDictionary <string, object>; string key = null; foreach (string text in dictionary2.Keys) { key = text; if (keyECase == ECase.UPPER) { key = text.ToUpper(); } else { if (keyECase == ECase.LOWER) { key = text.ToLower(); } } object value = dictionary2[key]; if (value != null && !string.IsNullOrEmpty(value.ToString())) { if (dictionary.ContainsKey(key)) { dictionary[key] = value; } else { dictionary.Add(key, value); } } else { if (nullValueAsKey) { if (dictionary.ContainsKey(key)) { dictionary[key] = value; } else { dictionary.Add(key, value); } } } } } else if (o is NameValueCollection) { NameValueCollection nvc = o as NameValueCollection; foreach (var key in nvc.AllKeys) { //dict.Add(k, col[k]); string[] values = nvc.GetValues(key); if (values.Length == 1) { dictionary.Add(key, values[0]); } else { dictionary.Add(key, values); } } } else { PropertyInfo[] array = includeInheritedProperty ? o.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public) : o.GetType().GetProperties(System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); PropertyInfo[] array2 = array; for (int i = 0; i < array2.Length; i++) { System.Reflection.PropertyInfo propertyInfo = array2[i]; string text = propertyInfo.Name; if (keyECase == ECase.UPPER) { text = text.ToUpper(); } else { if (keyECase == ECase.LOWER) { text = text.ToLower(); } } object value = propertyInfo.GetValue(o, null); if (value != null && !string.IsNullOrEmpty(value.ToString())) { if (!dictionary.ContainsKey(text)) { dictionary.Add(text, value); } else { dictionary[text] = value; } } else { if (nullValueAsKey) { if (!dictionary.ContainsKey(text)) { dictionary.Add(text, null); } else { dictionary[text] = null; } } } } } } return(dictionary); }
public static IDictionary <string, string> MergerJson(this IDictionary <string, string> dictionary, string jsonstr, bool nullValueAsKey, ECase keyECase) { return(dictionary.Merger(JsonAdapter.FromJsonAsDictionary(jsonstr), nullValueAsKey, keyECase)); }
public static System.Collections.Generic.IDictionary <string, object> MergerJson(this IDictionary <string, object> dictionary, string jsonstr, bool nullValueAsKey, ECase keyECase) { return(dictionary.Merger(JsonAdapter.FromJsonAsDictionary(jsonstr), nullValueAsKey, keyECase)); }