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


C# Map.ContainsKey方法代码示例

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


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

示例1: FetchUnhandledMailCount

        public Map<string, long> FetchUnhandledMailCount()
        {
            Map<string, long> count = new Map<string, long>();
            StringBuilder sql = new StringBuilder();
            sql.Append("select mail_date from ML_Mail where folder = 'INBOX' ")
               .Append("and owner_user_id = @owner_user_id ");

            sql.Append("and (is_handled is null or is_handled = 0) ");

            SQLiteCommand cmd = null;
            DataSet ds = null;
            try
            {
                cmd = new SQLiteCommand(sql.ToString(), DBWorker.GetConnection());
                cmd.Parameters.AddWithValue("@owner_user_id", Desktop.instance.loginedPrincipal.id);

                ds = new DataSet();
                SQLiteDataAdapter q = new SQLiteDataAdapter(cmd);
                q.Fill(ds);
            }
            finally
            {
                if (cmd != null)
                    cmd.Dispose();
            }

            DataTable dt = ds.Tables[0];
            foreach (DataRow row in dt.Rows)
            {
                if (row[0] is System.DBNull)
                    continue;
                DateTime date = (DateTime)row[0];
                foreach (TimePhase phase in timePhases)
                {
                    if (date >= phase.begin && date < phase.end)
                    {
                        if (!count.ContainsKey(phase.name))
                            count.Add(phase.name, 1);
                        else
                        {
                            long index = count[phase.name];
                            count.Add(phase.name, index + 1);
                        }
                    }
                }
            }
            return count;
        }
开发者ID:nbhopson,项目名称:QMail,代码行数:48,代码来源:UnhandledMailProvider.cs

示例2: SetupInterfaceData

 protected override void SetupInterfaceData()
 {
     RoutingNetworkMap = new Map<string, List<Tuple<IPAddress, IPAddress>>>();
     RipDatabase = new Map<IPAddress, RipRoute>();
     foreach (NetworkElement networkData in RipSection.GetConfigSection().Networks)
     {
         IPAddress network = IPAddress.From(networkData.Network);
         IPAddress networkMask = network.GetClassMask();
         IPAddress classedNetwork = network.GetClassAddress();
         //++ create interface candidate list
         List<string> list = GetInterfaceListForAddress(classedNetwork, allowConnectionOverSeconaryIP: true);
         if (Collection.IsNullOrEmpty(list))
         {
             continue;
         }
         //++ using the candidates as a basis, save each network worthy of cataloging
         foreach (string item in list)
         {
             if (!RoutingNetworkMap.ContainsKey(item))
             {
                 RoutingNetworkMap.Add(item, new List<Tuple<IPAddress, IPAddress>>());
             }
             Device device = Controller.DeviceConfigurationMap[item];
             if (device.PrimaryIPConfiguration.Address.IsSameNetwork(network, networkMask))
             {
                 RoutingNetworkMap[item].Add(new Tuple<IPAddress, IPAddress>(device.PrimaryIPConfiguration.Address.GetNetwork(device.PrimaryIPConfiguration.Mask), device.PrimaryIPConfiguration.Mask));
             }
             foreach (IPConfiguration ipData in device.SecondaryIPList)
             {
                 if (device.PrimaryIPConfiguration.Address.IsSameNetwork(network, networkMask))
                 {
                     RoutingNetworkMap[item].Add(new Tuple<IPAddress, IPAddress>(ipData.Network, ipData.Mask));
                 }
             }
             ActiveInterfaceList.Add(item);
         }
     }
 }
开发者ID:davidbetz,项目名称:netrouter,代码行数:38,代码来源:RipModule.cs

示例3: TranslationContext

            public TranslationContext(TypeRef resultType, PE.Instruction[] instructions, IImSeq<PE.ExceptionHandlingClause> handlers)
            {
                Parent = null;
                Start = 0;

                ResultType = resultType;
                Instructions = instructions;
                Handlers = handlers;

                var offsetToIndex = new Map<int, int>();
                for (var i = 0; i < instructions.Length; i++)
                {
                    if (offsetToIndex.ContainsKey(instructions[i].Offset))
                        throw new InvalidOperationException("instructions share same offset");
                    offsetToIndex.Add(instructions[i].Offset, i);
                }
                OffsetToIndex = offsetToIndex;

                var tryOffsets = new Set<int>();
                var indexToHandler = new Map<int, PE.ExceptionHandlingClause>();
                var indexToFilter = new Map<int, PE.ExceptionHandlingClause>();
                foreach (var ehc in handlers)
                {
                    if (!tryOffsets.Contains(ehc.TryOffset))
                        tryOffsets.Add(ehc.TryOffset);
                    var i = OffsetToIndex[ehc.HandlerOffset];
                    indexToHandler.Add(i, ehc);
                    if (ehc.Flags == PE.CorILExceptionClause.Filter)
                    {
                        var j = OffsetToIndex[ehc.FilterOffset];
                        indexToHandler.Add(j, ehc);
                    }
                }
                TryOffsets = tryOffsets;
                IndexToHandler = indexToHandler;
                IndexToFilter = indexToFilter;
            }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:37,代码来源:InstructionLoader.cs

示例4: Install

 public override void Install()
 {
     RouteList = new Map<IPAddress, Route>();
     Controller.RouteDiscovered += (s, e) =>
                                   {
                                       Route existing = RouteList.Where(p => p.Value.Network == e.Route.Network).OrderByDescending(p => p.Value.Mask.GetBitCount()).FirstOrDefault().Value;
                                       if (existing == null)
                                       {
                                           RouteList.Add(e.Route.Network, e.Route);
                                           Log.Write("SYSTEM", "RIB", "Add: " + e.Route.Network);
                                       }
                                       else
                                       {
                                           if (e.Route.Mask.GetBitCount() > existing.Mask.GetBitCount())
                                           {
                                               //++ most specific mask means different network; so AD isn't even a competitor for it
                                               RouteList[e.Route.Network] = e.Route;
                                               Log.Write("SYSTEM", "RIB", "Replaced via bit count: " + e.Route.Network);
                                           }
                                           else if (e.Route.AdministrativeDistance > RouteList[e.Route.Network].AdministrativeDistance)
                                           {
                                               //++ new AD is better? OK
                                               RouteList[e.Route.Network] = e.Route;
                                               Log.Write("SYSTEM", "RIB", "Replaced via AD: " + e.Route.Network);
                                           }
                                       }
                                   };
     Controller.RouteRemoved += (s, e) =>
                                {
                                    if (!RouteList.ContainsKey(e.Route.Network))
                                    {
                                        return;
                                    }
                                    RouteList.Remove(e.Route.Network);
                                    Log.Write("SYSTEM", "RIB", "Removed: " + e.Route.Network);
                                };
 }
开发者ID:davidbetz,项目名称:netrouter,代码行数:37,代码来源:SystemModule.cs

示例5: Main

        static void Main(string[] args)
        {
            Console.WriteLine("---LinkedList test---");

            var list = new LinkedList<string>();
            list.Add("x");
            list.Add("g");
            list.Add("s");

            Console.WriteLine(list.Count); //output: 3

            list.InsertAfter("g", "a");
            list.InsertBefore("g", "a");
            Console.WriteLine(list.InsertAt(10, "z")); //output: False
            list.InsertAt(2, "z");
            list.Remove("z");
            list[1] = "m";

            foreach (string value in list)
            {
                Console.WriteLine(value);
            }
            //output:
            //x
            //m
            //g
            //a
            //s

            Console.WriteLine("---DynamicArray test---");

            var dArray = new DynamicArray<string>();
            dArray.Add("x");
            dArray.Add("g");
            dArray.Add("s");

            Console.WriteLine(dArray.Count); //output: 3

            dArray.InsertAt(1, "a");
            dArray.InsertAt(3, "a");
            Console.WriteLine(dArray.InsertAt(10, "z")); //output: False
            dArray.InsertAt(2, "z");
            dArray.Remove("z");
            dArray[1] = "m";

            for (int i = 0; i < dArray.Count; i++)
            {
                Console.WriteLine(dArray[i]);
            }
            //output:
            //x
            //m
            //g
            //a
            //s

            Console.WriteLine("---Map test---");

            var map = new Map<int, string>();

            map.Add(1, "a");
            map.Add(2, "a");
            map.Add(3, "s");

            Console.WriteLine(map.Count); //output: 3

            try
            {
                map.Add(2, "v");
            }
            catch (ArgumentException argEx)
            {
                Console.WriteLine(argEx.Message); //exception message
            }

            Console.WriteLine(map.ContainsKey(2)); //output: True
            Console.WriteLine(map.ContainsValue("a")); //output: True
            map.Remove(2);
            Console.WriteLine(map.ContainsKey(2)); //output: False
            Console.WriteLine(map.ContainsValue("a")); //output: True

            Console.WriteLine(map.Count); //output: 2

            Console.WriteLine("---Hash Map test---");

            var hashMap = new Map<int, string>();

            hashMap.Add(1, "a");
            hashMap.Add(2, "a");
            hashMap.Add(3, "s");

            Console.WriteLine(hashMap.Count); //output: 3

            try
            {
                hashMap.Add(2, "v");
            }
            catch (ArgumentException argEx)
            {
                Console.WriteLine(argEx.Message); //exception message
//.........这里部分代码省略.........
开发者ID:abdonkov,项目名称:HackBulgaria-CSharp,代码行数:101,代码来源:Program.cs

示例6: EventInfoFromEvent

 private JST.Expression EventInfoFromEvent(Seq<JST.Statement> body, TypeCompilerEnvironment innerTypeCompEnv, Map<CST.MethodSignature, JST.Identifier> sharedMethodInfos, CST.EventDef eventDef)
 {
     var slot = Env.GlobalMapping.ResolveEventDefToSlot(innerTypeCompEnv.Assembly, innerTypeCompEnv.Type, eventDef);
     var slotExp = new JST.StringLiteral(Constants.ObjectEventSlot(slot));
     return JST.Expression.DotCall
         (RootId.ToE(),
          Constants.RootReflectionEventInfo,
          slotExp,
          TypeId.ToE(),
          new JST.BooleanLiteral(eventDef.IsStatic),
          new JST.BooleanLiteral(!eventDef.IsStatic),
          new JST.StringLiteral(eventDef.Name),
          CustomAttributesExpression
              (body, innerTypeCompEnv,
               CST.MessageContextBuilders.Member(Env.Global, innerTypeCompEnv.Assembly, innerTypeCompEnv.Type, eventDef),
               eventDef.CustomAttributes),
          innerTypeCompEnv.ResolveType(eventDef.HandlerType, TypePhase.Constructed),
          eventDef.Add == null || !sharedMethodInfos.ContainsKey(eventDef.Add)
              ? (JST.Expression)new JST.NullExpression()
              : sharedMethodInfos[eventDef.Add].ToE(),
          eventDef.Remove == null || !sharedMethodInfos.ContainsKey(eventDef.Remove)
              ? (JST.Expression)new JST.NullExpression()
              : sharedMethodInfos[eventDef.Remove].ToE());
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:24,代码来源:TypeCompiler.cs

示例7: SetupInterfaceData

 //internal Stack<Tuple<IPHeader, ospfHeader, ospfHelloHeader>> HelloMessageList { get; set; }
 protected override void SetupInterfaceData()
 {
     ASExternalLSAMap = new Map<string, OspfLsaExternalHeader>();
     VirtualLinkMap = new Map<IPAddress, IPAddress>();
     AreaMap = new Map<uint, Area>();
     AreaMap.Add(0, Area.Create(this, Controller, 0));
     OspfInterfaceMap = new Map<string, Interface>();
     //+
     var networkInterfaceMap = new Map<string, IPConfiguration>();
     //+
     OspfSection config = OspfSection.GetConfigSection();
     foreach (NetworkElement networkData in config.Networks)
     {
         //++ get broad list of interfaces by networks
         IPAddress network = IPAddress.From(networkData.Network);
         IPAddress wildcardMask = IPAddress.From(networkData.Mask).FlipBits();
         List<string> deviceIDList = GetInterfaceListForAddress(network, wildcardMask)
             .Where(p => Controller.DeviceConfigurationMap[p].IsEnabled)
             .Where(p =>
                    {
                        if (config.Interfaces.PassiveDefault)
                        {
                            if (config.Interfaces.Any(d => d.IsPassive))
                            {
                                return false;
                            }
                            else if (!config.Interfaces.Any(d => d.IsPassive))
                            {
                                return true;
                            }
                        }
                        return !config.Interfaces.Any(d => d.IsPassive);
                    }).ToList();
         if (Collection.IsNullOrEmpty(deviceIDList))
         {
             continue;
         }
         deviceIDList
             .Select(deviceID => new
                                 {
                                     device = Controller.DeviceConfigurationMap[deviceID],
                                     deviceID
                                 })
             .ToList()
             .ForEach(p => networkInterfaceMap.Add(p.deviceID, IPConfiguration.Create(
                 p.device.PrimaryIPConfiguration.Address,
                 p.device.PrimaryIPConfiguration.Mask)));
         ActiveInterfaceList.AddRange(deviceIDList.Where(p => !ActiveInterfaceList.Contains(p)));
     }
     foreach (string deviceID in networkInterfaceMap.Keys)
     {
         IPConfiguration ipConfiguration = networkInterfaceMap[deviceID];
         //++ find matching "network commands"
         List<NetworkElement> networkElementList = config.Networks.
             Select(networkData => new { main = networkData, mask = IPAddress.From(networkData.Mask).FlipBits() })
             .Where(networkData =>
                 IPAddress.GetNetwork(IPAddress.From(networkData.main.Network), networkData.mask)
                     .IsSameNetwork(ipConfiguration.Address, networkData.mask)
             )
             .Select(p => p.main)
             .ToList();
         if (networkElementList.Count == 0)
         {
             continue;
         }
         //++ find most specific maask;
         //++    inverted mask, so look for weakest here; that would be the strongest wildard mask
         NetworkElement networkElement = networkElementList.OrderBy(p => IPAddress.From(p.Mask)).First();
         //++ normalize area style
         uint areaID = GetArea(networkElement.Area);
         //++ ensure area exists
         if (!AreaMap.ContainsKey(areaID))
         {
             AreaMap.Add(areaID, Area.Create(this, Controller, areaID));
         }
         Area area = AreaMap[areaID];
         //++ create interface
         InterfaceElement interfaceConfig = config.Interfaces.FirstOrDefault(p => p.DeviceID.Equals(deviceID, StringComparison.InvariantCultureIgnoreCase))
             ?? new InterfaceElement
             {
             };
         Interface ospfInterface = Interface.Create(this, Controller, deviceID, area, interfaceConfig);
         Controller.DeviceConfigurationMap[deviceID].StateChanged += (s, e) =>
                                                                     {
                                                                         //++ ospf is only usable when the lower-level interface has a state of full
                                                                         if (e.InterfaceState == Routing.InterfaceState.L2UpL3Up)
                                                                         {
                                                                             //++ per-state machine, only do this when in the down state
                                                                             if (ospfInterface.InterfaceState == InterfaceState.Down)
                                                                             {
                                                                                 ospfInterface.RaiseEvent(InterfaceEventType.InterfaceUp);
                                                                             }
                                                                         }
                                                                         else
                                                                         {
                                                                             ospfInterface.RaiseEvent(InterfaceEventType.InterfaceDown);
                                                                         }
                                                                     };
         area.InterfaceList.Add(ospfInterface);
//.........这里部分代码省略.........
开发者ID:davidbetz,项目名称:netrouter,代码行数:101,代码来源:OspfModule.cs

示例8: PropertyInfoFromProperty

 private JST.Expression PropertyInfoFromProperty(Seq<JST.Statement> body, TypeCompilerEnvironment innerTypeCompEnv, Map<CST.MethodSignature, JST.Identifier> sharedMethodInfos, CST.PropertyDef propDef)
 {
     var slot = Env.GlobalMapping.ResolvePropertyDefToSlot(innerTypeCompEnv.Assembly, innerTypeCompEnv.Type, propDef);
     var slotExp = new JST.StringLiteral(Constants.ObjectPropertySlot(slot));
     return JST.Expression.DotCall
         (RootId.ToE(),
          Constants.RootReflectionPropertyInfo,
          slotExp,
          TypeId.ToE(),
          new JST.BooleanLiteral(propDef.IsStatic),
          new JST.BooleanLiteral(!propDef.IsStatic),
          new JST.StringLiteral(propDef.Name),
          CustomAttributesExpression
              (body, innerTypeCompEnv,
               CST.MessageContextBuilders.Member(Env.Global, innerTypeCompEnv.Assembly, innerTypeCompEnv.Type, propDef),
               propDef.CustomAttributes),
          innerTypeCompEnv.ResolveType(propDef.FieldType, TypePhase.Constructed),
          propDef.Get == null || !sharedMethodInfos.ContainsKey(propDef.Get) ? (JST.Expression)new JST.NullExpression() : sharedMethodInfos[propDef.Get].ToE(),
          propDef.Set == null || !sharedMethodInfos.ContainsKey(propDef.Set) ? (JST.Expression)new JST.NullExpression() : sharedMethodInfos[propDef.Set].ToE());
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:20,代码来源:TypeCompiler.cs

示例9: UpdateReadyQueue

 static void UpdateReadyQueue(Bar b, int currentTime)
 {
     readyQueue = readyQueue.RemoveKey(currentTime);
     foreach (Bar b1 in schedule.Values)
     {
         if (b.triggers.Contains(b1.name))
         {
             if (readyQueue.ContainsKey(currentTime + (int)b.duration)){
                 Set<Bar> bars = readyQueue[currentTime+(int)b.duration];
                 readyQueue = readyQueue.RemoveKey(currentTime+(int)b.duration);
                 readyQueue = readyQueue.Add(currentTime + (int)b.duration,bars.Add(b1));
             }
             else
                 readyQueue = readyQueue.Add(currentTime + (int)b.duration, new Set<Bar>(b1));
         }
     }
     if (b.offset < Scheduler.inf)
         if (readyQueue.ContainsKey(currentTime + (int)b.offset))
         {
             Set<Bar> bars = readyQueue[currentTime + (int)b.offset];
             readyQueue = readyQueue.RemoveKey(currentTime + (int)b.offset);
             readyQueue = readyQueue.Add(currentTime + (int)b.offset, bars.Add(b));
         }
         else
             readyQueue = readyQueue.Add(currentTime + (int)b.offset, new Set<Bar>(b));
 }
开发者ID:juhan,项目名称:NModel,代码行数:26,代码来源:Scheduler.cs

示例10: GetScopeToModify

        /// <summary>
        /// Get the scope to modify based on values in 'map'.
        ///		:level = the number of parents up the chain to modify
        ///		:map   = if present, the map to modify
        /// </summary>
        internal static IScope GetScopeToModify(Map map, IScope scope, bool bIncludeMap)
        {
            if (!map.ContainsKey("map") && !map.ContainsKey("level"))
                return scope;

            ValueMap valueMap = (bIncludeMap ? map["map"] as ValueMap : null);
            int level = (map.ContainsKey("level") ? map["level"].AsInt : 0);

            // scope we're going to modify
            IScope toModify = scope;
            if (valueMap != null)
                toModify = new ScopeChain(valueMap.AsMap);
            else
                for (int i = 0; i < level && toModify.Parent != null; i++)
                    toModify = toModify.Parent;
            if (toModify == null)
                toModify = scope;
            return toModify;
        }
开发者ID:loki3,项目名称:loki-pl1,代码行数:24,代码来源:Utility.cs

示例11: GetFromKeyOrValue

 /// <summary>If :key is present, lookup value, else if :value is present, return value.</summary>
 internal static Value GetFromKeyOrValue(Map map, IScope scope)
 {
     // either lookup up value w/ specified key or just get specified value
     Value value = null;
     Value key = map["key"];
     if (key != ValueNil.Nil)
     {
         Token token = new Token(key.AsString);
         value = scope.GetValue(token);
         if (value == null)
             throw new Loki3Exception().AddBadToken(token);
     }
     else if (map.ContainsKey("value"))
     {
         value = map["value"];
     }
     if (value == null)
         // todo: better error
         throw new Loki3Exception().AddMissingKey(new ValueString("key or value required"));
     return value;
 }
开发者ID:loki3,项目名称:loki-pl1,代码行数:22,代码来源:Utility.cs

示例12: PartitionsAreConsistent

 /// <summary>
 /// Returns true if both partitions have the same number of elements
 /// and the same keys, and for each key, the corresponding partitions 
 /// have the same size and order-idependence property.
 /// </summary>
 private static bool PartitionsAreConsistent(Map<Pair<IComparable,bool>, Set<Node>> xPartitions, Map<Pair<IComparable,bool>, Set<Node>> yPartitions)
 {
     if (xPartitions.Count != yPartitions.Count)
         return false;
     foreach (Pair<IComparable, bool> label in xPartitions.Keys)
     {
         if (!yPartitions.ContainsKey(label))
             return false;
         Set<Node> xPartition = xPartitions[label];
         Set<Node> yPartition = yPartitions[label];
         if (xPartition.Count != yPartition.Count)
             return false;
     }
     return true;
 }
开发者ID:juhan,项目名称:NModel,代码行数:20,代码来源:GraphIsomorphism.cs


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