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


C# Map.TryGetValue方法代码示例

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


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

示例1: getEventValuesForXiGivenParents

        /**
         * Get the values for the Random Variable Xi's parents and its own value
         * from the provided event.
         * 
         * @param Xi
         *            a Node for the Random Variable Xi whose parent values and
         *            value are to be extracted from the provided event in the
         *            correct order.
         * @param event
         *            an event containing assignments for Xi's parents and its own
         *            value.
         * @return an ordered set of values for the parents of Xi and its value from
         *         the provided event.
         */

        public static Object[] getEventValuesForXiGivenParents(Node Xi,
                                                               Map<RandomVariable, Object> evt)
        {
            object v = null;
            evt.TryGetValue(Xi.getRandomVariable(), out v);
            return getEventValuesForXiGivenParents(Xi,
                                                   v, evt);
        }
开发者ID:PaulMineau,项目名称:AIMA.Net,代码行数:23,代码来源:ProbUtil.cs

示例2: EmitMethods

        // ----------------------------------------------------------------------
        // Methods
        // ----------------------------------------------------------------------

        // Emit bindings for static or instance methods, but not for virtuals or interface methods
        //  - Invoked from TypeDefinitionCompiler for higher-kinded type definitions
        //  - Invoked from TypeCompiler for first-kinded type definitions
        public void EmitMethods(Seq<JST.Statement> body, JST.Expression lhs, JST.NameSupply outerNameSupply, JST.Expression target, bool isStatic)
        {
            switch (Env.CompilationMode)
            {
                case CompilationMode.Plain:
                {
                    // Method definitions are bound directly into target
                    foreach (var methodDef in Methods.Where(m => m.Invalid == null))
                    {
                        if (Env.InteropManager.IsStatic(TyconEnv.Assembly, TyconEnv.Type, methodDef) == isStatic)
                        {
                            var compiler = new MethodCompiler(this, outerNameSupply, methodDef, MethodCompilationMode.DirectBind);
                            compiler.Emit(body, target);
                        }
                    }
                    break;
                }
            case CompilationMode.Collecting:
                {
                    // Method definitions are bound into MethodCache, redirectors are bound into target
                    foreach (var methodDef in Methods.Where(m => m.Invalid == null))
                    {
                        if (Env.InteropManager.IsStatic(TyconEnv.Assembly, TyconEnv.Type, methodDef) == isStatic)
                        {
                            var slot = Env.GlobalMapping.ResolveMethodDefToSlot(TyconEnv.Assembly, TyconEnv.Type, methodDef);
                            var methodName = CST.CSTWriter.WithAppend
                                (Env.Global, CST.WriterStyle.Uniform, methodDef.MethodSignature.Append);
                            body.Add
                                (JST.Statement.DotCall
                                     (RootId.ToE(),
                                      Constants.RootCollectingBindMethodBuilder,
                                      lhs,
                                      new JST.BooleanLiteral(isStatic),
                                      new JST.StringLiteral(slot),
                                      new JST.StringLiteral(methodName)));
                            var compiler = new MethodCompiler(this, outerNameSupply, methodDef, MethodCompilationMode.DirectBind);
                            compiler.Emit(body, JST.Expression.Dot(target, Constants.TypeMethodCache));
                        }
                    }
                    break;
                }
            case CompilationMode.Traced:
                {
                    // Methods in the initial trace or this trace will be bound directly.
                    // Methods in a trace other than above are bound via builder which is given trace name.
                    // Remaining methods are built via builder with null trace name.
                    var traceToArgs = new Map<string, Seq<JST.Expression>>();
                    var remainingArgs = new Seq<JST.Expression>();
                    remainingArgs.Add(TypeDefinitionId.ToE());
                    remainingArgs.Add(new JST.BooleanLiteral(isStatic));
                    remainingArgs.Add(new JST.NullExpression());
                    foreach (var methodDef in Methods.Where(m => m.Invalid == null))
                    {
                        if (Env.InteropManager.IsStatic(TyconEnv.Assembly, TyconEnv.Type, methodDef) == isStatic)
                        {
                            var slot = Env.GlobalMapping.ResolveMethodDefToSlot(TyconEnv.Assembly, TyconEnv.Type, methodDef);
                            var defTrace = Env.Traces.MethodToTrace[methodDef.QualifiedMemberName(Env.Global, TyconEnv.Assembly, TyconEnv.Type)];
                            if (defTrace.Flavor == TraceFlavor.OnDemand && defTrace != TypeTrace.Parent.Parent)
                            {
                                // Method definition in in another trace, bind redirector for it.
                                var args = default(Seq<JST.Expression>);
                                if (!traceToArgs.TryGetValue(defTrace.Name, out args))
                                {
                                    args = new Seq<JST.Expression>();
                                    args.Add(lhs);
                                    args.Add(new JST.BooleanLiteral(isStatic));
                                    args.Add(new JST.StringLiteral(defTrace.Name));
                                    traceToArgs.Add(defTrace.Name, args);
                                }
                                args.Add(new JST.StringLiteral(slot));
                            }
                            else if (defTrace.Flavor == TraceFlavor.Remainder)
                                // Method definition is in a stand-alone loader, bind redirector for it.
                                remainingArgs.Add(new JST.StringLiteral(slot));
                            else
                            {
                                // Method definition is bound directly
                                var compiler = new MethodCompiler(this, outerNameSupply, methodDef, MethodCompilationMode.DirectBind);
                                compiler.Emit(body, target);
                            }
                        }
                    }
                    foreach (var kv in traceToArgs)
                        body.Add(JST.Statement.DotCall(RootId.ToE(), Constants.RootBindMethodBuilders, kv.Value));
                    if (remainingArgs.Count > 3)
                        body.Add(JST.Statement.DotCall(RootId.ToE(), Constants.RootBindMethodBuilders, remainingArgs));
                    break;
                }
            default:
                throw new ArgumentOutOfRangeException();
            }
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:99,代码来源:TypeDefinitionCompiler.cs

示例3: getEventValuesForParents

        /**
         * Get the parent values for the Random Variable Xi from the provided event.
         * 
         * @param Xi
         *            a Node for the Random Variable Xi whose parent values are to
         *            be extracted from the provided event in the correct order.
         * @param event
         *            an event containing assignments for Xi's parents.
         * @return an ordered set of values for the parents of Xi from the provided
         *         event.
         */

        public static Object[] getEventValuesForParents(Node Xi,
                                                        Map<RandomVariable, Object> evt)
        {
            Object[] parentValues = new Object[Xi.getParents().Count];
            int i = 0;
            foreach (Node pn in Xi.getParents())
            {
                object val;
                if (evt.TryGetValue(pn.getRandomVariable(), out val))
                {
                    parentValues[i] = val;
                }
                i++;
            }
            return parentValues;
        }
开发者ID:PaulMineau,项目名称:AIMA.Net,代码行数:28,代码来源:ProbUtil.cs

示例4: MemberInfoExpression

        private JST.Expression MemberInfoExpression(Seq<JST.Statement> body, TypeCompilerEnvironment innerTypeCompEnv)
        {
            var sharedMethodInfos = new Map<CST.MethodSignature, JST.Identifier>();
            var id = default(JST.Identifier);
            foreach (var propDef in Parent.Properties)
            {
                if (propDef.Get != null)
                {
                    var infoExp = MethodInfoFromMethod(body, innerTypeCompEnv, innerTypeCompEnv.Type.ResolveMethod(propDef.Get));
                    if (infoExp != null)
                    {
                        id = innerTypeCompEnv.NameSupply.GenSym();
                        body.Add(JST.Statement.Var(id, infoExp));
                        sharedMethodInfos.Add(propDef.Get, id);
                    }
                }
                if (propDef.Set != null)
                {
                    var infoExp = MethodInfoFromMethod(body, innerTypeCompEnv, innerTypeCompEnv.Type.ResolveMethod(propDef.Set));
                    if (infoExp != null)
                    {
                        id = innerTypeCompEnv.NameSupply.GenSym();
                        body.Add(JST.Statement.Var(id, infoExp));
                        sharedMethodInfos.Add(propDef.Set, id);
                    }
                }
            }
            foreach (var eventDef in Parent.Events)
            {
                if (eventDef.Add != null)
                {
                    var infoExp = MethodInfoFromMethod(body, innerTypeCompEnv, innerTypeCompEnv.Type.ResolveMethod(eventDef.Add));
                    if (infoExp != null)
                    {
                        id = innerTypeCompEnv.NameSupply.GenSym();
                        body.Add(JST.Statement.Var(id, infoExp));
                        sharedMethodInfos.Add(eventDef.Add, id);
                    }

                }
                if (eventDef.Remove != null)
                {
                    var infoExp = MethodInfoFromMethod(body, innerTypeCompEnv, innerTypeCompEnv.Type.ResolveMethod(eventDef.Remove));
                    if (infoExp != null)
                    {
                        id = innerTypeCompEnv.NameSupply.GenSym();
                        body.Add(JST.Statement.Var(id, infoExp));
                        sharedMethodInfos.Add(eventDef.Remove, id);
                    }
                }
            }

            var infoExps = new Seq<JST.Expression>();
            foreach (var methodDef in Parent.Methods)
            {
                if (sharedMethodInfos.TryGetValue(methodDef.MethodSignature, out id))
                    infoExps.Add(id.ToE());
                else
                {
                    var infoExp = MethodInfoFromMethod(body, innerTypeCompEnv, methodDef);
                    if (infoExp != null)
                        infoExps.Add(infoExp);
                }
            }

            foreach (var fieldDef in Parent.Fields)
            {
                var infoExp = FieldInfoFromField(body, innerTypeCompEnv, fieldDef);
                if (infoExp != null)
                    infoExps.Add(infoExp);
            }

            foreach (var propDef in Parent.Properties)
            {
                var infoExp = PropertyInfoFromProperty(body, innerTypeCompEnv, sharedMethodInfos, propDef);
                if (infoExp != null)
                    infoExps.Add(infoExp);
            }

            foreach (var eventDef in Parent.Events)
            {
                var infoExp = EventInfoFromEvent(body, innerTypeCompEnv, sharedMethodInfos, eventDef);
                if (infoExp != null)
                    infoExps.Add(infoExp);
            }

            return new JST.ArrayLiteral(infoExps);
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:88,代码来源:TypeCompiler.cs

示例5: EmitAssemblyBindings

 // Each referenced assembly is assigned an assembly builder function in the referencing
 // assembly of the form
 //   A<slot name> : () -> <assembly structure>
 private void EmitAssemblyBindings(Seq<JST.Statement> body)
 {
     switch (Env.CompilationMode)
     {
     case CompilationMode.Plain:
     case CompilationMode.Collecting:
         {
             if (Env.DebugMode)
                 body.Add(new JST.CommentStatement("Referenced assemblies"));
             var args = new Seq<JST.Expression>();
             args.Add(assemblyId.ToE());
             args.Add(new JST.NullExpression());
             foreach (var nm in assmEnv.AllAssembliesInLoadOrder())
             {
                 if (!nm.Equals(Env.Global.MsCorLibName) && !nm.Equals(assmEnv.Assembly.Name))
                 {
                     var assmName = CST.CSTWriter.WithAppend(Env.Global, CST.WriterStyle.Uniform, nm.Append);
                     var slotName = Env.GlobalMapping.ResolveAssemblyReferenceToSlot(assmEnv.Assembly, nm);
                     args.Add(new JST.StringLiteral(slotName));
                     args.Add(new JST.StringLiteral(assmName));
                 }
                 // else: don't need ref to mscorlib or self
             }
             if (args.Count > 2)
                 body.Add
                     (JST.Statement.DotCall(rootId.ToE(), Constants.RootBindAssemblyBuilders, args));
             break;
         }
     case CompilationMode.Traced:
         {
             // Assemblies in the initial trace, this trace, or the remainder trace are bound via a builder
             // which is given the null trace name. All other assemblies are bound by a builder given their
             // containing trace name.
             var traceToArgs = new Map<string, Seq<JST.Expression>>();
             var remainingArgs = new Seq<JST.Expression>();
             remainingArgs.Add(assemblyId.ToE());
             remainingArgs.Add(new JST.NullExpression());
             foreach (var nm in assmEnv.AllAssembliesInLoadOrder())
             {
                 if (!nm.Equals(Env.Global.MsCorLibName) && !nm.Equals(assmEnv.Assembly.Name))
                 {
                     var assmName = CST.CSTWriter.WithAppend(Env.Global, CST.WriterStyle.Uniform, nm.Append);
                     var slotName = Env.GlobalMapping.ResolveAssemblyReferenceToSlot(assmEnv.Assembly, nm);
                     var defTrace = Env.Traces.AssemblyToTrace[nm];
                     if (defTrace.Flavor == TraceFlavor.OnDemand && defTrace != assemblyTrace.Parent)
                     {
                         var args = default(Seq<JST.Expression>);
                         if (!traceToArgs.TryGetValue(defTrace.Name, out args))
                         {
                             args = new Seq<JST.Expression>();
                             args.Add(assemblyId.ToE());
                             args.Add(new JST.StringLiteral(defTrace.Name));
                             traceToArgs.Add(defTrace.Name, args);
                         }
                         args.Add(new JST.StringLiteral(slotName));
                         args.Add(new JST.StringLiteral(assmName));
                     }
                     else
                     {
                         remainingArgs.Add(new JST.StringLiteral(slotName));
                         remainingArgs.Add(new JST.StringLiteral(assmName));
                     }
                 }
                 // else: don't need ref to mscorlib or self
             }
             foreach (var kv in traceToArgs)
                 body.Add(JST.Statement.DotCall(rootId.ToE(), Constants.RootBindAssemblyBuilders, kv.Value));
             if (remainingArgs.Count > 2)
                 body.Add
                     (JST.Statement.DotCall(rootId.ToE(), Constants.RootBindAssemblyBuilders, remainingArgs));
             break;
         }
     default:
         throw new ArgumentOutOfRangeException();
     }
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:79,代码来源:AssemblyCompiler.cs

示例6: EmitTypeBindings

 // Each type is assigned a builder function
 //   typeArg1, ..., typeArgn, phase -> type
 private void EmitTypeBindings(Seq<JST.Statement> body)
 {
     switch (Env.CompilationMode)
     {
         case CompilationMode.Plain:
         case CompilationMode.Collecting:
         {
             if (Env.DebugMode)
                 body.Add(new JST.CommentStatement("Type builders"));
             var args = new Seq<JST.Expression>();
             args.Add(assemblyId.ToE());
             args.Add(new JST.NullExpression());
             foreach (var typeDef in typeDefs)
             {
                 var slotName = Env.GlobalMapping.ResolveTypeDefToSlot(assmEnv.Assembly, typeDef);
                 var typeName = CST.CSTWriter.WithAppend
                     (Env.Global, CST.WriterStyle.Uniform, typeDef.EffectiveName(Env.Global).Append);
                 args.Add(new JST.StringLiteral(slotName));
                 args.Add(new JST.StringLiteral(typeName));
             }
             if (args.Count > 2)
                 body.Add(JST.Statement.DotCall(rootId.ToE(), Constants.RootBindTypeBuilders, args));
             break;
         }
     case CompilationMode.Traced:
         {
             // Types in the initial trace, this trace, or remainder trace are bound via builder with
             // null trace name. All other types are bound via builder with their containing trace name.
             var traceToArgs = new Map<string, Seq<JST.Expression>>();
             var remainingArgs = new Seq<JST.Expression>();
             remainingArgs.Add(assemblyId.ToE());
             remainingArgs.Add(new JST.NullExpression());
             foreach (var typeDef in typeDefs)
             {
                 var typeName = CST.CSTWriter.WithAppend
                     (Env.Global, CST.WriterStyle.Uniform, typeDef.EffectiveName(Env.Global).Append);
                 var slotName = Env.GlobalMapping.ResolveTypeDefToSlot(assmEnv.Assembly, typeDef);
                 var defTrace = Env.Traces.TypeToTrace[typeDef.QualifiedTypeName(Env.Global, assmEnv.Assembly)];
                 if (defTrace.Flavor == TraceFlavor.OnDemand && defTrace != assemblyTrace.Parent)
                 {
                     var args = default(Seq<JST.Expression>);
                     if (!traceToArgs.TryGetValue(defTrace.Name, out args))
                     {
                         args = new Seq<JST.Expression>();
                         args.Add(assemblyId.ToE());
                         args.Add(new JST.StringLiteral(defTrace.Name));
                         traceToArgs.Add(defTrace.Name, args);
                     }
                     args.Add(new JST.StringLiteral(slotName));
                     args.Add(new JST.StringLiteral(typeName));
                 }
                 else
                 {
                     remainingArgs.Add(new JST.StringLiteral(slotName));
                     remainingArgs.Add(new JST.StringLiteral(typeName));
                 }
             }
             foreach (var kv in traceToArgs)
                 body.Add(JST.Statement.DotCall(rootId.ToE(), Constants.RootBindTypeBuilders, kv.Value));
             if (remainingArgs.Count > 2)
                 body.Add(JST.Statement.DotCall(rootId.ToE(), Constants.RootBindTypeBuilders, remainingArgs));
             break;
         }
     default:
         throw new ArgumentOutOfRangeException();
     }
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:69,代码来源:AssemblyCompiler.cs

示例7: TryReduceSwitch

        private string TryReduceSwitch(BasicBlock root, SwitchBasicBlock switchbb)
        {
            // Build a map from basic blocks to the cases which enter it.
            // Also collect some simple stats.
            var caseMap = new Map<BasicBlock, Set<int>> { { switchbb.Fallthrough, new Set<int> { -1 } } };
            var allNonReturning = switchbb.Fallthrough is NonReturningBasicBlock;
            var allHaveOneSource = switchbb.Fallthrough.Sources.Count == 1;
            var jumpTargets = new Set<BasicBlock>();
            var jumpbb = switchbb.Fallthrough as JumpBasicBlock;
            if (jumpbb != null)
                jumpTargets.Add(jumpbb.Target);
            for (var i = 0; i < switchbb.CaseTargets.Count; i++)
            {
                var t = switchbb.CaseTargets[i];
                if (!(t is NonReturningBasicBlock))
                    allNonReturning = false;
                if (t.Sources.Count != 1)
                    allHaveOneSource = false;
                jumpbb = t as JumpBasicBlock;
                if (jumpbb != null)
                    jumpTargets.Add(jumpbb.Target);
                var values = default(Set<int>);
                if (caseMap.TryGetValue(t, out values))
                    // Block is shared amongst switch cases
                    values.Add(i);
                else
                    caseMap.Add(t, new Set<int> { i });
            }

            if (caseMap.Count == 1)
            {
                // CASE 1: all switch cases go to the same block, so replace the switch with a pop and jump
                var instructions = switchbb.Block.CopyContents();
                instructions.Add
                    (new MiscInstruction(NextInstructionId--, MiscOp.Pop)
                     { BeforeState = switchbb.Block.BeforeState, AfterState = switchbb.Fallthrough.Block.BeforeState });
                var newbb = new JumpBasicBlock
                    (nextBlockId++, Peephole(switchbb.Block.BeforeState, instructions), switchbb.Fallthrough);
                root.Coalesce(switchbb, new Set<BasicBlock> { switchbb }, newbb);
                return string.Format("removed switch at B{0}", switchbb.Id);
            }

            if (allNonReturning && allHaveOneSource)
            {
                // CASE 2: all switch cases are non-returning and have one source, so move them all into
                //         a non-returing block with switch
                var group = new Set<BasicBlock> { switchbb };
                var cases = new Seq<StructuralCase>();
                foreach (var kv in caseMap)
                {
                    cases.Add(new StructuralCase(kv.Value, kv.Key.Block));
                    group.Add(kv.Key);
                }
                var ssi = new StructuralSwitchInstruction(NextInstructionId--, switchbb.Block, cases)
                              {
                                  BeforeState = switchbb.Block.BeforeState,
                                  AfterState = switchbb.Fallthrough.Block.AfterState
                              };
                var newbb = new NonReturningBasicBlock(nextBlockId++, new Instructions(ssi));
                root.Coalesce(switchbb, group, newbb);
                return String.Format("non-returning structural switch from B{0}", switchbb.Id);
            }

            if (jumpTargets.Count == 1)
            {
                var theJumpTarget = jumpTargets[0];
                var allIntermediateAreNonReturningOrJumpToTarget = true;
                foreach (var kv in caseMap)
                {
                    if (!kv.Key.Equals(theJumpTarget))
                    {
                        if (kv.Key.Sources.Count > 1 ||
                            !(kv.Key is NonReturningBasicBlock || kv.Key is JumpBasicBlock))
                            allIntermediateAreNonReturningOrJumpToTarget = false;
                    }
                }
                if (allIntermediateAreNonReturningOrJumpToTarget)
                {
                    // CASE 3: all switch cases either jump directly to the switch successor or go via jump block,
                    //         or don't return. Inline all the cases and place the switch in a jump to target block
                    var group = new Set<BasicBlock> { switchbb };
                    var cases = new Seq<StructuralCase>();
                    var afterState = default(MachineState);
                    foreach (var kv in caseMap)
                    {
                        var block = default(Instructions);
                        if (kv.Key.Equals(theJumpTarget))
                        {
                            var bci = new BreakContinueInstruction(NextInstructionId--, BreakContinueOp.Break, null)
                                          {
                                              BeforeState = theJumpTarget.Block.BeforeState,
                                              AfterState = theJumpTarget.Block.BeforeState
                                          };
                            // Fallthrough to final jump target
                            block = new Instructions(bci);
                        }
                        else
                        {
                            // Inline case block, and if not non-returning then fallthrough to final jump target
                            var instructions = kv.Key.Block.CopyContents();
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:IL2JS,代码行数:101,代码来源:ControlFlowRecovery.cs


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