System.Collections.Generic.Dictionary.TryGetValue(string, out object)

Here are the examples of the csharp api System.Collections.Generic.Dictionary.TryGetValue(string, out object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

784 Examples 7

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask ListRightPushAsync(string key, string item)
        {
            using (Lock())
            {
                if (!_data.TryGetValue(key, out var listObj))
                    _data[key] = listObj = new List<string>();

                var list = (List<string>) listObj;
                list.Add(item);

                return new ValueTask();
            }
        }

19 View Source File : AnkiItem.cs
License : MIT License
Project Creator : AnkiTools

public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            string name = binder.Name.ToLower();
            
            return _dictionary.TryGetValue(name, out result);
        }

19 View Source File : JSON.cs
License : MIT License
Project Creator : AlenToma

internal object ParseDictionary(Dictionary<string, object> d, Dictionary<string, object> globaltypes, Type type, object input)
        {
            object tn = "";
            if (type == typeof(NameValueCollection))
                return JsonHelper.CreateNV(d);
            if (type == typeof(StringDictionary))
                return JsonHelper.CreateSD(d);

            if (d.TryGetValue("$i", out tn))
            {
                object v = null;
                _cirrev.TryGetValue((int)(long)tn, out v);
                return v;
            }

            if (d.TryGetValue("$types", out tn))
            {
                _usingglobals = true;
                if (globaltypes == null)
                    globaltypes = new Dictionary<string, object>();
                foreach (var kv in (Dictionary<string, object>)tn)
                {
                    globaltypes.Add((string)kv.Value, kv.Key);
                }
            }
            if (globaltypes != null)
                _usingglobals = true;

            bool found = d.TryGetValue("$type", out tn);
#if !SILVERLIGHT
            if (found == false && type == typeof(System.Object))
            {
                return d;   // CreateDataset(d, globaltypes);
            }
#endif
            if (found)
            {
                if (_usingglobals)
                {
                    object tname = "";
                    if (globaltypes != null && globaltypes.TryGetValue((string)tn, out tname))
                        tn = tname;
                }
                type = Reflection.Instance.GetTypeFromCache((string)tn);
            }

            if (type == null)
                throw new Exception("Cannot determine type");

            string typename = type.FullName;
            object o = input;
            if (o == null)
            {
                if (_params.ParametricConstructorOverride)
                    o = System.Runtime.Serialization.FormatterServices.GetUninitializedObject(type);
                else
                    o = FastDeepCloner.DeepCloner.CreateInstance(type);
            }
            int circount = 0;
            if (_circobj.TryGetValue(o, out circount) == false)
            {
                circount = _circobj.Count + 1;
                _circobj.Add(o, circount);
                _cirrev.Add(circount, o);
            }

            var props = Reflection.Instance.Getproperties(type, typename);
            foreach (var kv in d)
            {
                var n = kv.Key;
                var v = kv.Value;

                string name = n;//.ToLower();
                if (name == "$map")
                {
                    ProcessMap(o, props, (Dictionary<string, object>)d[name]);
                    continue;
                }
                myPropInfo pi;
                if (props.TryGetValue(name, out pi) == false)
                    if (props.TryGetValue(name.ToLowerInvariant(), out pi) == false)
                        continue;

                if (pi.CanWrite)
                {
                    if (v != null)
                    {
                        object oset = null;

                        switch (pi.Type)
                        {
                            case myPropInfoType.Int: oset = (int)JsonHelper.AutoConv(v); break;
                            case myPropInfoType.Long: oset = JsonHelper.AutoConv(v); break;
                            case myPropInfoType.String: oset = v.ToString(); break;
                            case myPropInfoType.Bool: oset = JsonHelper.BoolConv(v); break;
                            case myPropInfoType.DateTime: oset = JsonHelper.CreateDateTime((string)v, _params.UseUTCDateTime); break;
                            case myPropInfoType.Enum: oset = JsonHelper.CreateEnum(pi.pt, v); break;
                            case myPropInfoType.Guid: oset = JsonHelper.CreateGuid((string)v); break;

                            case myPropInfoType.Array:
                                if (!pi.IsValueType)
                                    oset = CreateArray((List<object>)v, pi.pt, pi.bt, globaltypes);
                                // what about 'else'?
                                break;
                            case myPropInfoType.ByteArray: oset = Convert.FromBase64String((string)v); break;
#if !SILVERLIGHT
                            case myPropInfoType.DataSet: oset = CreateDataset((Dictionary<string, object>)v, globaltypes); break;
                            case myPropInfoType.DataTable: oset = CreateDataTable((Dictionary<string, object>)v, globaltypes); break;
                            case myPropInfoType.Hashtable: // same case as Dictionary
#endif
                            case myPropInfoType.Dictionary: oset = CreateDictionary((List<object>)v, pi.pt, pi.GenericTypes, globaltypes); break;
                            case myPropInfoType.StringKeyDictionary: oset = CreateStringKeyDictionary((Dictionary<string, object>)v, pi.pt, pi.GenericTypes, globaltypes); break;
                            case myPropInfoType.NameValue: oset = JsonHelper.CreateNV((Dictionary<string, object>)v); break;
                            case myPropInfoType.StringDictionary: oset = JsonHelper.CreateSD((Dictionary<string, object>)v); break;
                            case myPropInfoType.Custom: oset = Reflection.Instance.CreateCustom((string)v, pi.pt); break;
                            default:
                                {
                                    if (pi.IsGenericType && pi.IsValueType == false && v is List<object>)
                                        oset = CreateGenericList((List<object>)v, pi.pt, pi.bt, globaltypes);

                                    else if ((pi.IsClreplaced || pi.IsStruct || pi.IsInterface) && v is Dictionary<string, object>)
                                        oset = ParseDictionary((Dictionary<string, object>)v, globaltypes, pi.pt, null);// pi.getter(o));

                                    else if (v is List<object>)
                                        oset = CreateArray((List<object>)v, pi.pt, typeof(object), globaltypes);

                                    else if (pi.IsValueType)
                                        oset = ChangeType(v, pi.changeType);

                                    else
                                        oset = v;
                                }
                                break;
                        }

                        pi.Property.SetValue(o, oset);
                    }
                }
            }
            return o;
        }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask<IReadOnlyList<string>> ListRangeAsync(string key, int start, int end)
        {
            using (LockRead())
            {
                if (!_data.TryGetValue(key, out var listObj))
                    return new ValueTask<IReadOnlyList<string>>(ImmutableList<string>.Empty);

                var list = (List<string>) listObj;
                if (!list.Any())
                    return new ValueTask<IReadOnlyList<string>>(ImmutableList<string>.Empty);

                (start, end) = IndexUtils.TranslateStartEndIndex(start, end, list.Count);
                if (start > list.Count) return new ValueTask<IReadOnlyList<string>>(ImmutableList<string>.Empty);

                var rangeLength = end - start + 1;
                var range = list.Skip(start).Take(rangeLength).ToList();
                return new ValueTask<IReadOnlyList<string>>(range);
            }
        }

19 View Source File : ExcelManipulator.cs
License : MIT License
Project Creator : alkampfergit

public void FillWorkItems(IEnumerable<LinkedWorkItem> workItems)
        {
            var sheet = _excelPackage.Workbook.Worksheets[1];
            Dictionary<Int32, String> fieldMapping = new Dictionary<int, string>();
            Int32 col = 1;
            while (sheet.Cells[2, col].Value != null)
            {
                string trimmedValue = sheet.Cells[2, col].Value.ToString().Trim('{', '}');
                fieldMapping[col] = trimmedValue;
                col++;
            }

            sheet.InsertRow(3, workItems.Count());
            Int32 row = 3;
            foreach (var workItem in workItems)
            {
                Log.Logger.Debug("Filling work item {id} in row {rownum}", workItem.WorkItem.Id, row);
                Dictionary<String, Object> propertyDictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
                LinkedWorkItem current = workItem;
                while (current != null)
                {
                    current.WorkItem.FillPropertyDictionary(
                        propertyDictionary, 
                        current.WorkItem.Type.Name.ToLower() + '.',
                        true);
                    current = current.Parent;
                }

                sheet.Cells[2, 1, 2, col].Copy(sheet.Cells[row, 1]);
                //now for each mapping for current row we need to subsreplacedute the real value
                foreach (var colInfo in fieldMapping)
                {
                    sheet.Cells[row, colInfo.Key].Value = "";
                    if (propertyDictionary.TryGetValue(colInfo.Value, out var value))
                    {
                        sheet.Cells[row, colInfo.Key].Value = value?.ToString() ?? "";
                    }
                }
                row++;
            }

            sheet.DeleteRow(2);
        }

19 View Source File : SettingsManager.cs
License : GNU General Public License v3.0
Project Creator : aglab2

public T GetConfig<T>(string configureName, T def)
        {
            T ret = def;
            try
            {
                if (configs.TryGetValue(configureName, out object value))
                {
                    ret = (T)value;
                }
                else
                {
                    configs[configureName] = ret;
                }
            }
            catch (Exception)
            {
                configs[configureName] = ret;
            }

            return ret;
        }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask<bool> SetAddAsync(string key, string value)
        {
            using (Lock())
            {
                if (!_data.TryGetValue(key, out var setObj))
                    _data[key] = setObj = new HashSet<string>();

                var set = (HashSet<string>) setObj;
                var added = set.Add(value);
                return new ValueTask<bool>(added);
            }
        }

19 View Source File : RxContext.cs
License : MIT License
Project Creator : adospace

public static T Get<T>(this RxContext context, string key, T defaultValue = default)
        {
            if (context.TryGetValue(key, out var value))
                return (T)value;

            return defaultValue;
        }

19 View Source File : Utility.cs
License : MIT License
Project Creator : aprilyush

private static object GetRenderInstance(string renderInstance)
        {
            if (string.IsNullOrEmpty(renderInstance)) return null;

            string[] k = renderInstance.Split(new char[] { ',' }, 2);
            if (k.Length != 2) return null;

            string replacedemblyKey = k[1].Trim();
            string typeKey = k[0].Trim();
            string cacheKey = string.Concat(typeKey, ",", replacedemblyKey);

            //从缓存读取
            object render;
            bool flag = false;
            lock (RenderInstanceCache)
            {
                flag = RenderInstanceCache.TryGetValue(cacheKey, out render);
            }
            if (!flag || render == null)
            {
                //重新生成实例
                render = null;
                //生成实例
                replacedembly replacedembly;
                if (replacedemblyKey.IndexOf(":") != -1)
                {
                    replacedembly = replacedembly.LoadFrom(replacedemblyKey);
                }
                else
                {
                    replacedembly = replacedembly.Load(replacedemblyKey);
                }
                if (replacedembly != null)
                {
                    render = replacedembly.CreateInstance(typeKey, false);
                }
                if (render != null)
                {
                    //缓存
                    lock (RenderInstanceCache)
                    {
                        if (RenderInstanceCache.ContainsKey(cacheKey))
                        {
                            RenderInstanceCache[cacheKey] = render;
                        }
                        else
                        {
                            RenderInstanceCache.Add(cacheKey, render);
                        }
                    }
                }
            }
            return render;
        }

19 View Source File : VisualNode.cs
License : MIT License
Project Creator : adospace

public T GetMetadata<T>(string key, T defaultValue = default)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentException("can'be null or empty", nameof(key));
            }

            if (_metadata.TryGetValue(key, out var value))
                return (T)value;

            return defaultValue;
        }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask<bool> HashExistsAsync(string key, string field)
        {
            using (LockRead())
            {
                if (!_data.TryGetValue(key, out var hashSetObj))
                    return new ValueTask<bool>(false);

                var hashSet = (Dictionary<string, string>) hashSetObj;
                return new ValueTask<bool>(hashSet.ContainsKey(field));
            }
        }

19 View Source File : SolanaRpcClient.cs
License : MIT License
Project Creator : allartprotocol

private async Task<RequestResult<T>> SendRequestAsync<T>(
            string method, IList<object> parameters, Dictionary<string, object> configurationObject
            )
        {
            var newList = parameters.ToList();

            if (configurationObject == null)
            {
                configurationObject = new Dictionary<string, object>
                {
                    {"encoding", "jsonParsed"}
                };
            }

            foreach (var key in configurationObject.Keys)
            {
                var ok = configurationObject.TryGetValue(key, out var value);
                if (!ok) continue;

                newList.Add(new Dictionary<string, object>
                {
                    { key, value}
                });
            }

            var req = BuildRequest<T>(method, newList);
            return await SendRequest<T>(req);
        }

19 View Source File : FunctionDictionaryBase.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

public TAction GetDelegate<TAction>(string name = null)where TAction : clreplaced
        {
            object value;
            if (string.IsNullOrEmpty(name))
            {
                var type = typeof(TAction);
                if (!_dependencyDictionary.TryGetValue(type, out value))
                {
                    return null;
                }
            }
            else
            {
                if (!_nameDictionary.TryGetValue(name, out value))
                {
                    return null;
                }
            }
            if (!(value is TAction))
            {
                return null;
            }
            return (TAction)value;
        }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask<string?> GetAsync(string key)
        {
            using (LockRead())
            {
                if (_data.TryGetValue(key, out var value))
                    return new ValueTask<string?>((string) value);

                return new ValueTask<string?>((string?) null);
            }
        }

19 View Source File : ParamsHelper.cs
License : MIT License
Project Creator : ad313

public static string FillParamValues(string source, List<string> keys, Dictionary<string, object> pars)
        {
            if (keys == null || keys.Count <= 0) 
                return source;

            foreach (var key in keys)
            {
                //参数包含:
                if (key.Contains(Separator))
                {
                    var parts = key.Split(Separator);
                    var firstKey = parts[0];
                    var secondKey = parts[1];

                    if (!pars.TryGetValue(firstKey, out object firstValue) || firstValue == null)
                        continue;

                    var secondValue = "";

                    if (firstValue is JsonElement json)
                    {
                        if (!json.TryGetProperty(secondKey, out JsonElement value))
                            continue;

                        secondValue = value.ToString();
                    }
                    else
                    {
                        if (!Helpers.ToDictionary(firstValue).TryGetValue(secondKey, out object second) || second == null)
                            continue;

                        secondValue = second.ToString();
                    }
                    
                    source = source.Replace("{" + key + "}", secondValue);
                }
                else
                {
                    if (!pars.TryGetValue(key, out object value) || value == null)
                        continue;

                    source = source.Replace("{" + key + "}", value.ToString());
                }
            }

            return source;
        }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask<long> ListRemoveAsync(string key, string item)
        {
            using (Lock())
            {
                if (_data.TryGetValue(key, out var listObj))
                {
                    var list = (List<string>) listObj;
                    var removedCount = list.RemoveAll(x => x == item);

                    return new ValueTask<long>(removedCount);
                }

                return new ValueTask<long>(0L);
            }
        }

19 View Source File : PipelineTool.cs
License : MIT License
Project Creator : Alan-FGR

public virtual void LoadData()
         {
            if (GlobalData.TryGetValue(id_, out object obj))
               SetPath(obj as string);
         }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask<IReadOnlyList<string>> SetMembersAsync(string key)
        {
            using (LockRead())
            {
                if (!_data.TryGetValue(key, out var setObj))
                    return new ValueTask<IReadOnlyList<string>>(ImmutableList<string>.Empty);

                var set = (HashSet<string>) setObj;
                return new ValueTask<IReadOnlyList<string>>(set.ToList());
            }
        }

19 View Source File : JsonWebToken.cs
License : MIT License
Project Creator : actions

protected T TryGetValueOrDefault<T>(string key)
            {
                object ret;
                if(TryGetValue(key, out ret))
                {
                    //we have to special case DateTime
                    if (typeof(T) == typeof(DateTime))
                    {
                        return (T)(object)ConvertDateTime(ret);
                    }
                    if (typeof(T).GetTypeInfo().IsEnum && ret is string)
                    {
                        return (T)Enum.Parse(typeof(T), (string)ret);
                    }
                    return (T)Convert.ChangeType(ret, typeof(T));
                }

                return default(T);
            }

19 View Source File : AtlassRequest.cs
License : MIT License
Project Creator : aprilyush

private object GetPostObject(string name)
        {
            if (string.IsNullOrEmpty(name)) return null;

            return PostData.TryGetValue(name, out var value) ? value : null;
        }

19 View Source File : EnhancedExpandoObeject.cs
License : MIT License
Project Creator : AliFlux

public bool TryGetValue(string key, out object value)
        {
            return Properties.TryGetValue(key, out value);
        }

19 View Source File : QuerySection.cs
License : MIT License
Project Creator : alkampfergit

private List<String> PrepareQueries(Dictionary<string, object> parameters)
        {
            var retValue = new List<String>();
            if (QueryParameters.Count == 0)
            {
                if (!RepeatForEachIteration)
                {
                    retValue.Add(SubsreplaceduteParametersInQuery(Query, parameters));
                }
                else
                {
                    //TODO: THis is a logic that should propably be completely changed with the concept of array parameters.
                    if (parameters.TryGetValue("iterations", out object iterations)
                        && iterations is List<String> iterationList)
                    {
                        foreach (var iteration in iterationList)
                        {
                            var query = Query.Replace("{iterationPath}", iteration);
                            retValue.Add(SubsreplaceduteParametersInQuery(query, parameters));
                        }
                    }
                    else
                    {
                        //By convention we should have a list of valid iterations names inside parameters dictionary.
                        Log.Error("Error handling iteration for query {name}, we have RepeatForEachIteration to true but no iteration defined", Name);
                    }
                }
            }
            else
            {
                foreach (var parameterSet in QueryParameters)
                {
                    var query = Query;
                    foreach (var parameter in parameterSet)
                    {
                        query = query.Replace('{' + parameter.Key + '}', parameter.Value);
                        parameters[parameter.Key] = parameter.Value;
                    }
                    retValue.Add(SubsreplaceduteParametersInQuery(query, parameters));
                }
            }

            return retValue;
        }

19 View Source File : PropertiesCollection.cs
License : MIT License
Project Creator : actions

public Boolean TryGetValue(String key, out Object value)
        {
            return m_innerDictionary.TryGetValue(key, out value);
        }

19 View Source File : StatePersister.cs
License : MIT License
Project Creator : alkampfergit

public T Load<T>(String key)
        {
            if (_config.TryGetValue(key, out var obj))
            {
                return (T)obj;
            }

            return default(T);
        }

19 View Source File : Material.cs
License : The Unlicense
Project Creator : aeroson

public void SetUniform(string name, object o)
        {
            if (o is Texture)
            {
                texturesData[name] = o as Texture;
                return;
            }

            object oldObj = null;
            if(!uniformsData.TryGetValue(name, out oldObj) || !oldObj.Equals(o))
            {
                uniformsData[name] = o;
                if(!uniformsChanged.Contains(name)) uniformsChanged.Add(name);
            }                      
        }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask HashSetAsync(string key, IEnumerable<KeyValuePair<string, string>> keyValuePairs)
        {
            using (LockRead())
            {
                if (!_data.TryGetValue(key, out var hashSetObj))
                    _data[key] = hashSetObj = new Dictionary<string, string>();

                var hashSet = (Dictionary<string, string>) hashSetObj;
                foreach (var (field, value) in keyValuePairs)
                {
                    hashSet[field] = value;
                }
            }

            return new ValueTask();
        }

19 View Source File : IOEntry.cs
License : Apache License 2.0
Project Creator : aloneguid

public bool TryGetProperty<TValue>(string name, out TValue value, TValue defaultValue = default)
      {
         if(name == null || !Properties.TryGetValue(name, out object objValue))
         {
            value = defaultValue;
            return false;
         }

         if(objValue is TValue)
         {
            value = (TValue)objValue;
            return true;
         }

         value = defaultValue;
         return false;
      }

19 View Source File : AttributeDictionary.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

public bool Set<T>(string name, T value)
        {
            if (Dictionary.TryGetValue(name, out object value1))
            {
                if (Equals(value, default(T)))
                {
                    Dictionary.Remove(name);
                    return true;
                }
                if (Equals(value1, value))
                {
                    return false;
                }
                Dictionary[name] = value;
                return true;
            }
            if (Equals(value, default( T )))
            {
                return false;
            }
            Dictionary.Add(name, value);
            return true;
        }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask<bool> HashDeleteAsync(string key, string field)
        {
            using (Lock())
            {
                if (!_data.TryGetValue(key, out var hashSetObj))
                    return new ValueTask<bool>(false);

                var hashSet = (Dictionary<string, string>) hashSetObj;
                if (hashSet.Remove(field))
                {
                    if (!hashSet.Any()) _data.Remove(key);

                    return new ValueTask<bool>(true);
                }

                return new ValueTask<bool>(false);
            }
        }

19 View Source File : ParamsHelper.cs
License : MIT License
Project Creator : ad313

public static string FillParamValues(string source, Dictionary<string,string> dicMaps, Dictionary<string, object> pars)
        {
            if (dicMaps == null || dicMaps.Count <= 0)
                return source;

            foreach (var key in dicMaps)
            {
                //参数包含:
                if (key.Value.Contains(Separator))
                {
                    var parts = key.Value.Split(Separator);
                    var firstKey = parts[0];
                    var secondKey = parts[1];

                    if (!pars.TryGetValue(firstKey, out object firstValue) || firstValue == null)
                        continue;

                    var secondValue = "";

                    if (firstValue is JsonElement json)
                    {
                        if (!json.TryGetProperty(secondKey, out JsonElement value))
                            continue;

                        secondValue = value.ToString();
                    }
                    else
                    {
                        if (!Helpers.ToDictionary(firstValue).TryGetValue(secondKey, out object second) || second == null)
                            continue;

                        secondValue = second.ToString();
                    }

                    source = source.Replace("{" + key.Key + "}", secondValue);
                }
                else
                {
                    if (!pars.TryGetValue(key.Value, out object value) || value == null)
                        continue;

                    source = source.Replace("{" + key.Key + "}", value.ToString());
                }
            }

            return source;
        }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask<IReadOnlyDictionary<string, string>> HashGetAllAsync(string key)
        {
            using (LockRead())
            {
                if (!_data.TryGetValue(key, out var hashSetObj))
                    return new ValueTask<IReadOnlyDictionary<string, string>>(ImmutableDictionary<string, string>
                        .Empty);

                var hashSet = (Dictionary<string, string>) hashSetObj;
                return new ValueTask<IReadOnlyDictionary<string, string>>(
                    hashSet.ToImmutableDictionary(x => x.Key, x => x.Value));
            }
        }

19 View Source File : AttributeDictionary.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu

public T Get<T>(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return default( T );
            }
            return Dictionary.TryGetValue(name, out object value) ? (T)value : default(T);
        }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask<string?> GetSetAsync(string key, string value)
        {
            using (Lock())
            {
                _data.TryGetValue(key, out var dbValue);
                _data[key] = value;

                return new ValueTask<string?>((string?) dbValue);
            }
        }

19 View Source File : LootSwap.cs
License : GNU Affero General Public License v3.0
Project Creator : ACEmulator

private static void UpdateTables(Dictionary<string, Type> types, Dictionary<string, Dictionary<string, object>> files)
        {
            foreach (var kvp in types)
            {
                var clreplacedName = kvp.Key;
                var type = kvp.Value;

                if (!files.TryGetValue(clreplacedName, out var newTables))
                {
                    //Console.WriteLine($"Couldn't find {clreplacedName} in files");
                    continue;
                }

                var fields = Reflection.GetFields(type);

                Console.WriteLine($"Updated {clreplacedName}");

                foreach (var field in fields)
                {
                    if (!newTables.TryGetValue(field.field.Name, out var newTable))
                    {
                        //Console.WriteLine($"Couldn't find {field.field.Name} in {clreplacedName}.cs");
                        continue;
                    }
                    //Console.WriteLine($" - {field.field.Name}");
                    UpdateTable(field.field, newTable);
                }
            }
        }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask<int> ListLenAsync(string key)
        {
            using (LockRead())
            {
                if (!_data.TryGetValue(key, out var listObj))
                    return new ValueTask<int>(0);

                var list = (List<string>) listObj;
                return new ValueTask<int>(list.Count);
            }
        }

19 View Source File : Scripts.cs
License : MIT License
Project Creator : Alan-FGR

protected T RetrieveScriptData<T>(string key)
    {
        object outval;
        if (scriptData.TryGetValue(key, out outval))
        {
            return (T) outval;
        }
        return default(T);
    }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask<string?> ListLeftPopAsync(string key)
        {
            using (LockRead())
            {
                if (!_data.TryGetValue(key, out var listObj))
                    return new ValueTask<string?>((string?) null);

                var list = (List<string>) listObj;
                if (list.Count == 0)
                    return new ValueTask<string?>((string?) null);

                var lefreplacedem = list[0];
                list.RemoveAt(0);

                return new ValueTask<string?>(lefreplacedem);
            }
        }

19 View Source File : UserInterfaceRegister.cs
License : GNU General Public License v3.0
Project Creator : Adam-Wilkinson

public bool TryGetUserInterface(string userInterfaceName, out object userInterface)
            {
                if (_userInterfacesByName.TryGetValue(userInterfaceName, out object internalUserInterface))
                {
                    userInterface = PrepareForReturning(internalUserInterface);
                    return true;
                }

                userInterface = default;
                return false;
            }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask<bool> SetRemoveAsync(string key, string value)
        {
            using (Lock())
            {
                if (!_data.TryGetValue(key, out var setObj))
                    return new ValueTask<bool>(false);

                var set = (HashSet<string>) setObj;
                var removed = set.Remove(value);

                if (removed && !set.Any())
                    _data.Remove(key);

                return new ValueTask<bool>(removed);
            }
        }

19 View Source File : PipelineTool.cs
License : MIT License
Project Creator : Alan-FGR

public override void LoadData()
         {
            if (GlobalData.TryGetValue(id_, out object obj))
            {
               var data = obj as Tuple<string, bool, string>;
               SetPath(data.Item1);
               switch_.Toggled = data.Item2;
               namerBox_.Text = data.Item3;
               StateChanged();
            }
         }

19 View Source File : BaseOpenTokService.cs
License : MIT License
Project Creator : AndreiMisiukevich

private T GetValue<T>(T defaultValue, [CallerMemberName] string name = null)
        {
            lock (_propertiesLocker)
            {
                return (T)(_properties.TryGetValue(name, out object value) ? value : defaultValue);
            }
        }

19 View Source File : AnyDictionary.cs
License : MIT License
Project Creator : 5minlab

internal bool TryGetValue<T>(string key, out T val, T defaultVal = default(T)) {
            if(dict == null) {
                val = defaultVal;
                return false;
            }

            object obj;
            if (dict.TryGetValue(key, out obj)) {
                if (typeof(T).IsreplacedignableFrom(obj.GetType())) {
                    val = (T)Convert.ChangeType(obj, typeof(T));
                    return (val != null);
                }
            }
            val = defaultVal;
            return false;
        }

19 View Source File : AnkiSharpDynamic.cs
License : MIT License
Project Creator : AnkiTools

public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            string name = binder.Name.ToLower();

            return _dictionary.TryGetValue(name, out result);
        }

19 View Source File : Blackboard.cs
License : MIT License
Project Creator : alexjhetherington

public bool TryGetTypedValue<T>(string key, out T val)
    {
        object temp;
        bool success = TryGetValue(key, out temp);

        if (!success || !(temp is T)) {
            val = default;
            return false;
        }

        val = (T)temp;
        return success;
    }

19 View Source File : SqliteSyncProvider.cs
License : MIT License
Project Creator : adospace

private static ChangeType DetectChangeType(Dictionary<string, object> values)
        {
            if (values.TryGetValue("__OP", out var syncChangeOperation))
            {
                switch (syncChangeOperation.ToString())
                {
                    case "I":
                        return ChangeType.Insert;

                    case "U":
                        return ChangeType.Update;

                    case "D":
                        return ChangeType.Delete;

                    default:
                        throw new NotSupportedException();
                }
            }

            return ChangeType.Insert;
        }

19 View Source File : ContextDataSlots.cs
License : MIT License
Project Creator : 1996v

public bool TryGetNamedDataSlot(string name, out object data)
        {
            if (storeSlots != null && storeSlots.TryGetValue(name, out data))
            {
                return true;
            }

            data = default;
            return false;
        }

19 View Source File : DictionaryCustomFormatter.cs
License : Apache License 2.0
Project Creator : A7ocin

public string Format(string format, object arg, IFormatProvider formatProvider)
		{
			if (arg == null) throw new ArgumentNullException("arg");

			var dict = arg as Dictionary<string, object>;
			if (format != null && dict != null)
			{
				object o;
				if (dict.TryGetValue(format.Trim(), out o))
				{
					if (o == null)
					{
						Debug.LogError("data was null: " + format.Trim());
					}
					var template = o as CodeGenTemplate;
					if (template != null)
					{
						return template.sb.ToString();
					}
					return o.ToString();
				}
			}

			if (arg is IFormattable)
				return ((IFormattable)arg).ToString(format, formatProvider);
			else return arg.ToString();
		}

19 View Source File : VssHttpUriUtility.cs
License : MIT License
Project Creator : actions

[EditorBrowsable(EditorBrowsableState.Never)]
        public static String ReplaceRouteValues(
            String routeTemplate,
            Dictionary<String, Object> routeValues,
            RouteReplacementOptions routeReplacementOptions)
        {
            StringBuilder sbResult = new StringBuilder();
            StringBuilder sbCurrentPathPart = new StringBuilder();
            int paramStart = -1, paramLength = 0;
            bool insideParam = false;
            HashSet<string> unusedValues = new HashSet<string>(routeValues.Keys, StringComparer.OrdinalIgnoreCase);
            Dictionary<string, object> caseIncensitiveRouteValues = new Dictionary<string, object>(routeValues, StringComparer.OrdinalIgnoreCase);

            for (int i = 0; i < routeTemplate.Length; i++)
            {
                char c = routeTemplate[i];

                if (insideParam)
                {
                    if (c == '}')
                    {
                        insideParam = false;
                        String paramName = routeTemplate.Substring(paramStart, paramLength);
                        paramLength = 0;
                        if (paramName.StartsWith("*"))
                        {
                            if (routeReplacementOptions.HasFlag(RouteReplacementOptions.WildcardAsQueryParams))
                            {
                                continue;
                            }
                            // wildcard route
                            paramName = paramName.Substring(1);
                        }

                        Object paramValue;
                        if (caseIncensitiveRouteValues.TryGetValue(paramName, out paramValue))
                        {
                            if (paramValue != null)
                            {
                                sbCurrentPathPart.Append(paramValue.ToString());
                                unusedValues.Remove(paramName);
                            }
                        }
                        else if (routeReplacementOptions.HasFlag(RouteReplacementOptions.RequireExplicitRouteParams))
                        {
                            throw new ArgumentException("Missing route param " + paramName);
                        }
                    }
                    else
                    {
                        paramLength++;
                    }
                }
                else
                {
                    if (c == '/')
                    {
                        if (sbCurrentPathPart.Length > 0)
                        {
                            sbResult.Append('/');
                            sbResult.Append(sbCurrentPathPart.ToString());
                            sbCurrentPathPart.Clear();
                        }
                    }
                    else if (c == '{')
                    {
                        if ((i + 1) < routeTemplate.Length && routeTemplate[i + 1] == '{')
                        {
                            // Escaped '{'
                            sbCurrentPathPart.Append(c);
                            i++;
                        }
                        else
                        {
                            insideParam = true;
                            paramStart = i + 1;
                        }
                    }
                    else if (c == '}')
                    {
                        sbCurrentPathPart.Append(c);
                        if ((i + 1) < routeTemplate.Length && routeTemplate[i + 1] == '}')
                        {
                            // Escaped '}'
                            i++;
                        }
                    }
                    else
                    {
                        sbCurrentPathPart.Append(c);
                    }
                }
            }

            if (sbCurrentPathPart.Length > 0)
            {
                sbResult.Append('/');
                sbResult.Append(sbCurrentPathPart.ToString());
            }

            if (routeReplacementOptions.HasFlag(RouteReplacementOptions.EscapeUri))
            {
                sbResult = new StringBuilder(Uri.EscapeUriString(sbResult.ToString()));
            }

            if (routeReplacementOptions.HasFlag(RouteReplacementOptions.AppendUnusedAsQueryParams) && unusedValues.Count > 0)
            {
                bool isFirst = true;

                foreach (String paramName in unusedValues)
                {
                    Object paramValue;
                    if (caseIncensitiveRouteValues.TryGetValue(paramName, out paramValue) && paramValue != null)
                    {
                        sbResult.Append(isFirst ? '?' : '&');
                        isFirst = false;
                        sbResult.Append(Uri.EscapeDataString(paramName));
                        sbResult.Append('=');
                        sbResult.Append(Uri.EscapeDataString(paramValue.ToString()));
                    }
                }
            }

            return sbResult.ToString();
        }

19 View Source File : AssemblyHelper.cs
License : MIT License
Project Creator : AFei19911012

public static object ResolveByKey(string key)
        {
            if (CacheDic.TryGetValue(key, out var value))
            {
                return value;
            }

            return null;
        }

19 View Source File : InMemoryDatabaseActions.cs
License : Apache License 2.0
Project Creator : Anapher

public virtual ValueTask<string?> HashGetAsync(string key, string field)
        {
            using (LockRead())
            {
                if (_data.TryGetValue(key, out var hashSetObj))
                {
                    var hashSet = (Dictionary<string, string>) hashSetObj;
                    if (hashSet.TryGetValue(field, out var value))
                        return new ValueTask<string?>(value);
                }
            }

            return new ValueTask<string?>((string?) null);
        }

See More Examples