当前位置: 首页>>代码示例>>C#>>正文


C# SafeDictionary.TryGetValue方法代码示例

本文整理汇总了C#中SafeDictionary.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# SafeDictionary.TryGetValue方法的具体用法?C# SafeDictionary.TryGetValue怎么用?C# SafeDictionary.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SafeDictionary的用法示例。


在下文中一共展示了SafeDictionary.TryGetValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

        public static void Load()
        {
            BaseInformations = new SafeDictionary<uint, ConquerItemBaseInformation>(10000);
            PlusInformations = new SafeDictionary<uint, SafeDictionary<byte, ConquerItemPlusInformation>>(10000);
            GradeInformations = new SafeDictionary<string, SafeDictionary<int, ConquerItemBaseInformation>>(10000);
            GradeInformations2 = new SafeDictionary<string, SafeDictionary<uint, int>>(10000);
            string[] baseText = File.ReadAllLines(ServerBase.Constants.ItemBaseInfosPath);
            string text = "►◄►◄►◄►◄►◄►◄►◄►◄►◄►◄►◄►◄►◄►◄►◄►◄►◄►◄►◄►◄";
            int for1prg = baseText.Length / (System.Console.WindowWidth - text.Length);
            int count = 0;
            System.Console.Write(text);
            var old1 = System.Console.BackgroundColor;
            var old2 = System.Console.ForegroundColor;
            System.Console.BackgroundColor = ConsoleColor.Gray;
            System.Console.ForegroundColor = ConsoleColor.Gray;
            int gkey = 0;
            int lastlevel = 0;
            string lastgr = "";
            foreach (string line in baseText)
            {
                count++;
                if (count == for1prg)
                {
                    count = 0;
                    System.Console.Write("▼◘");
                }
                string _item_ = line.Trim();
                if (_item_.Length > 11)
                {
                    if (_item_.IndexOf("//", 0, 2) != 0)
                    {
                        ConquerItemBaseInformation CIBI = new ConquerItemBaseInformation();
                        CIBI.Parse(_item_);

                        var Grades = GradeInformations[CIBI.Description];
                        BaseInformations.Add(CIBI.ID, CIBI);
                        if (GradeInformations.ContainsKey(CIBI.Description) == false)
                        {
                            GradeInformations2.Add(CIBI.Description, new SafeDictionary<uint, int>(1000));
                            GradeInformations2[CIBI.Description].Add((uint)(CIBI.ID / 10), 0);
                            lastlevel = CIBI.Level;
                            GradeInformations.Add(CIBI.Description, new SafeDictionary<int, ConquerItemBaseInformation>(1000));
                            gkey = 0;
                        }
                        else
                        {
                            if (lastgr != CIBI.Description)
                                gkey = GradeInformations2[CIBI.Description].Count - 1;

                            if (GradeInformations2[CIBI.Description].ContainsKey(CIBI.ID / 10) && CIBI.Level == lastlevel)
                            {
                                CIBI.GradeKey = gkey;
                                continue;
                            }
                            else
                            {
                                GradeInformations2[CIBI.Description].Add((uint)(CIBI.ID / 10), 0);
                                lastlevel = CIBI.Level;
                                gkey = gkey + 1;
                            }
                        }
                        lastgr = CIBI.Description;
                        CIBI.GradeKey = gkey;
                        GradeInformations[CIBI.Description].Add(gkey, CIBI);
                    }
                }
            }
            GradeInformations2.Base.Clear();
            System.Console.BackgroundColor = old1;
            System.Console.ForegroundColor = old2;
            baseText = File.ReadAllLines(ServerBase.Constants.ItemPlusInfosPath);

            foreach (string line in baseText)
            {
                try
                {
                    string _item_ = line.Trim();
                    ConquerItemPlusInformation CIPI = new ConquerItemPlusInformation();
                    CIPI.Parse(_item_);
                    SafeDictionary<byte, ConquerItemPlusInformation> info = null;
                    if (PlusInformations.TryGetValue(CIPI.ID, out info))
                    {
                        info.Add(CIPI.Plus, CIPI);
                    }
                    else
                    {
                        PlusInformations.Add(CIPI.ID, new SafeDictionary<byte, ConquerItemPlusInformation>(1000));
                        if (PlusInformations.TryGetValue(CIPI.ID, out info))
                        {
                            info.Add(CIPI.Plus, CIPI);
                        }
                    }
                }
                catch
                {
                    Console.WriteLine(line);
                    Console.ReadLine();
                }
            }
            Console.WriteLine("Item Base and Plus information loaded.");
//.........这里部分代码省略.........
开发者ID:faresali,项目名称:co-pserver,代码行数:101,代码来源:ConquerItemInformation.cs

示例2: AddFieldToMethodEffects

        public static TypeEx AddFieldToMethodEffects(IPexComponent host, TypeEx declaringType, SafeSet<string> res, 
            SafeSet<string> directSetFields, SafeDictionary<string, FieldModificationType> modificationTypeDic,
            OpCode prevOpcode, Field field, TypeEx fieldType)
        {
            SafeDebug.AssumeNotNull(field, "field");
            SafeDebug.Assume(!field.IsStatic, "!field.IsStatic");

            TypeEx fieldDeclaringType;

            //The following check ensures that the field belongs to this class
            //or its base classes
            if (field.TryGetDeclaringType(out fieldDeclaringType) &&
                declaringType.IsAssignableTo(fieldDeclaringType))
            {
                res.Add(field.ShortName);

                FieldModificationType fmt = FieldModificationType.UNKNOWN;
                if (fieldType == SystemTypes.Int32 || fieldType == SystemTypes.Int64 || fieldType == SystemTypes.Int16)
                {
                    if (prevOpcode == OpCodes.Add)
                        fmt = FieldModificationType.INCREMENT;
                    else if (prevOpcode == OpCodes.Sub)
                        fmt = FieldModificationType.DECREMENT;
                    else if (prevOpcode == OpCodes.Call || prevOpcode == OpCodes.Calli || prevOpcode == OpCodes.Callvirt)
                        fmt = FieldModificationType.METHOD_CALL;
                    else
                        host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fieldmodificationtype",
                                "Encountered unknown modification type for integer type " + prevOpcode);
                }
                else
                {
                    if (field.Type.IsReferenceType)
                    {
                        if (prevOpcode == OpCodes.Ldnull)
                            fmt = FieldModificationType.NULL_SET;
                        else if (prevOpcode == OpCodes.Newarr || prevOpcode == OpCodes.Newobj)
                            fmt = FieldModificationType.NON_NULL_SET;
                        else if (LdArgOpCodes.Contains(prevOpcode))
                            fmt = FieldModificationType.NON_NULL_SET;
                        else
                        {
                            fmt = FieldModificationType.METHOD_CALL;    //A method call is invoked on this field, which updates this field
                        }
                    }
                    else if (fieldType == SystemTypes.Bool)
                    {
                        if (prevOpcode == OpCodes.Ldc_I4_0)
                            fmt = FieldModificationType.FALSE_SET;
                        else if (prevOpcode == OpCodes.Ldc_I4_1)
                            fmt = FieldModificationType.TRUE_SET;
                        else
                            host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fieldmodificationtype",
                                    "Encountered unknown modification type for boolean type " + prevOpcode);
                    }
                }

                //Store the value of fmt. Sometimes, the same field
                //can be modified in different ways within the method, for example
                //setting a boolean field to both true or false. In that case, the modification
                //type is left as unknown
                FieldModificationType prevFMT;
                if (modificationTypeDic.TryGetValue(field.ShortName, out prevFMT))
                {
                    //There is some entry for this field
                    if (prevFMT != FieldModificationType.UNKNOWN && prevFMT != fmt)
                    {
                        modificationTypeDic[field.ShortName] = FieldModificationType.UNKNOWN;
                    }
                }
                else
                {
                    modificationTypeDic[field.ShortName] = fmt;
                }

                //A heuristic based approach for aliasing analysis for checking whether the field is directly
                //assigned any parameters
                if (LdArgOpCodes.Contains(prevOpcode))
                    directSetFields.Add(field.ShortName);
            }
            return fieldDeclaringType;
        }
开发者ID:spati2,项目名称:ICSE-2011-Covana,代码行数:81,代码来源:FieldAnalyzer.cs

示例3: handleAConstantInTerm

        /// <summary>
        /// OBSOLETE: Handles a scenario where there is a term in the condition
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <param name="binOp"></param>
        /// <param name="fmt"></param>
        private void handleAConstantInTerm(TermManager termManager, Term left, Term right,
            BinaryOperator binOp, bool bNegated, SafeDictionary<Field, FieldValueHolder> fieldValues, Field culpritField,
            out FieldModificationType fmt, out int fitnessval)
        {
            fitnessval = Int32.MaxValue;
            fmt = FieldModificationType.UNKNOWN;
            Term non_constant_term = null;
            Term constant_term = null;

            bool bleftRightMaintainted = true;
            if (termManager.IsValue(left))
            {
                non_constant_term = right;
                constant_term = left;
                bleftRightMaintainted = true;
            }
            else if (termManager.IsValue(right))
            {
                non_constant_term = left;
                constant_term = right;
                bleftRightMaintainted = false;
            }

            int value;
            if (termManager.TryGetI4Constant(constant_term, out value))
            {
                fmt = FieldModificationType.INCREMENT;

                FieldValueHolder fvh;
                if (fieldValues.TryGetValue(culpritField, out fvh))
                {
                    int non_constant_field_value = fvh.intValue;    //TODO: Assuming that the fieldType is Int32
                    if (bleftRightMaintainted)
                        fitnessval = FitnessMeasure.ComputeFitnessValue(this.host, binOp, value, non_constant_field_value, bNegated);
                    else
                        fitnessval = FitnessMeasure.ComputeFitnessValue(this.host, binOp, non_constant_field_value, value, bNegated);
                }
                else
                    this.host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fitness measure",
                        "Failed to retrieve value for field " + culpritField.ToString());
            }
            else if (termManager.IsDefaultValue(constant_term))
            {
                if (binOp == BinaryOperator.Ceq)
                {
                    if (culpritField.Type.ToString() == "System.Boolean")
                    {
                        fmt = bNegated ? FieldModificationType.TRUE_SET : FieldModificationType.FALSE_SET;
                    }
                    else
                        fmt = bNegated ? FieldModificationType.NON_NULL_SET : FieldModificationType.NULL_SET;
                }
            }

            Term objectValue;
            ObjectProperty objectProperty;
            if (termManager.TryGetObjectProperty(constant_term, out objectValue, out objectProperty))
            {
                //TODO??? How to handle this scenario?
            }
        }
开发者ID:spati2,项目名称:ICSE-2011-Covana,代码行数:68,代码来源:TargetBranchAnalyzer.cs


注:本文中的SafeDictionary.TryGetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。