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


C# Context.ContainsKey方法代码示例

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


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

示例1: InitialCellList

 private void InitialCellList(Context context)
 {
     if (!context.ContainsKey(ContextKeys.CellList))
     {
         List<IACell> cellList = GetCellList(context);
         context.Add(ContextKeys.CellList, cellList);
     } 
 }
开发者ID:xiaoyj,项目名称:Space,代码行数:8,代码来源:BinSuite.cs

示例2: GetCellList

 private List<IACell> GetCellList(Context context)
 {
     List<IACell> cellList = new List<IACell>();
     if (!context.ContainsKey(ContextKeys.TranceiverList))
         return cellList;
     //if (context.ContainsKey(ContextKeys.TranceiverList))
     //{
     List<Transceiver> tranceiverList = (List<Transceiver>)context[ContextKeys.TranceiverList];
     foreach (Transceiver tran in tranceiverList)
         {
             List<IACell> cells = tran.Cells;//GetOneTranceiverCellList(tran);
             cellList.AddRange(cells);                    
         }
     //}
     return cellList;
 }
开发者ID:xiaoyj,项目名称:Space,代码行数:16,代码来源:BinSuite.cs

示例3: Initialize

        private void Initialize(Context context)
        {
            Context = context;
            foreach (var property in GetType().GetProperties())
            {
                var name = property.Name.ToLower();
                if (context.ContainsKey(name))
                {
                    var type = property.PropertyType;
                    if (type == typeof(string))
                    {
                        if (property.IsAnOption())
                        {
                            if (OptionAttribute.IsDefinedOn(property))
                            {
                                var attribute = (OptionAttribute) property.GetCustomAttributes(typeof(OptionAttribute), false)[0];
                                if (attribute.SupportsXPathTemplates)
                                {
                                    propertiesToEvaluate[property] = context[name];
                                }
                            }

                            property.SetValue(this, context[name], null);
                        }
                    }
                    else if (type == typeof(int))
                    {
                        int value;
                        if (Int32.TryParse(context[name], out value))
                        {
                            string description;
                            if (!RangeValidator.Validate(property, value, out description))
                            {
                                var message = string.Format("'{0}' is not a valid value for {1}. {2}", context[name], name, description);
                                throw new TaskExecutionException(message);
                            }
                            property.SetValue(this, value, null);
                        }
                        else
                        {
                            var message = string.Format("'{0}' is not a valid value for {1}. An integer value is required.", context[name], name);
                            throw new TaskExecutionException(message);
                        }
                    }
                    else if (type == typeof(bool))
                    {
                        bool value;
                        if (string.IsNullOrEmpty(context[name]))
                        {
                            property.SetValue(this, true, null);
                        }
                        else if (Boolean.TryParse(context[name], out value))
                        {
                            property.SetValue(this, value, null);
                        }
                        else
                        {
                            var message = string.Format("'{0}' is not a valid value for {1}. A value of 'true' or 'false' is required.", context[name], name);
                            throw new TaskExecutionException(message);
                        }
                    }
                }
                else
                {
                    if (property.IsAnOption())
                    {
                        if (OptionAttribute.IsDefinedOn(property))
                        {
                            var attribute = (OptionAttribute) property.GetCustomAttributes(typeof(OptionAttribute), false)[0];
                            if (attribute.SupportsXPathTemplates)
                            {
                                var value = property.GetValue(this, null) ?? string.Empty;
                                context[name] = value.ToString();
                                propertiesToEvaluate[property] = context[name];
                            }
                        }
                    }
                }
            }
        }
开发者ID:rh,项目名称:mix,代码行数:80,代码来源:Task.cs

示例4: CreateTermDefinition

        private void CreateTermDefinition(string term, Context context, JObject localContext, IDictionary<string, bool> defined)
        {
            if (defined.ContainsKey(term))
            {
                if (!defined[term])
                {
                    throw new InvalidOperationException("Cyclic IRI mapping detected.");
                }

                return;
            }

            if (IsKeyWord(term))
            {
                throw new InvalidOperationException("Keyword redefinition detected.");
            }

            defined[term] = false;
            context.Remove(term);
            JToken value = ((localContext != null) && (localContext.Property(term) != null) ? localContext[term].DeepClone() : null);
            if ((value == null) || ((value is JValue) && (((JValue)value).Value == null)) || ((value is JObject) && (((JObject)value).Property(Id) != null) && (((JObject)value).Property(Id).ValueEquals(null))))
            {
                context[term] = null;
                return;
            }
            else if ((value is JValue) && (((JValue)value).Type == JTokenType.String))
            {
                JObject newObject = new JObject();
                newObject[Id] = value;
                value = newObject;
            }
            else if (!(value is JObject))
            {
                throw new InvalidOperationException("Invalid term definition.");
            }

            TermDefinition definition = new TermDefinition() { Original = value };
            if (((JObject)value).Property(Type) != null)
            {
                if (!((JObject)value).Property(Type).ValueIs<string>())
                {
                    throw new InvalidOperationException("Invalid type mapping.");
                }

                string result = ((JObject)value).Property(Type).ValueAs<string>();
                result = ExpandIri(result, context, localContext, false, true, defined);
                if ((result != Id) && (result != Vocab) && (!Regex.IsMatch(result, "[a-zA-Z0-9_]+:.+")))
                {
                    throw new InvalidOperationException("Invalid type mapping.");
                }

                definition.Type = result;
            }

            if (((JObject)value).Property(Reverse) != null)
            {
                JProperty reverse = ((JObject)value).Property(Reverse);
                if (((JObject)value).Property(Id) != null)
                {
                    throw new InvalidOperationException("Invalid reverse property.");
                }

                if (!reverse.ValueIs<string>())
                {
                    throw new InvalidOperationException("Invalid IRI mapping.");
                }

                definition.Iri = ExpandIri(reverse.ValueAs<string>(), context, localContext, false, true, defined);

                if (((JObject)value).Property(Container) != null)
                {
                    definition.Container = (string)((JObject)value)[Container];
                }

                definition.IsReverse = true;
                context[term] = definition;
                defined[term] = true;
                return;
            }

            definition.IsReverse = false;
            if ((value is JObject) && (((JObject)value).Property(Id) != null) && (!((JObject)value).Property(Id).ValueEquals(term)))
            {
                if ((!(((JObject)value).Property(Id).Value is JValue)) || (((JValue)((JObject)value).Property(Id).Value).Type != JTokenType.String))
                {
                    throw new InvalidOperationException("Invalid IRI mapping.");
                }

                string iri = ExpandIri((string)((JValue)((JObject)value).Property(Id).Value).Value, context, localContext, false, true, defined).ToString();
                if ((!IsKeyWord((string)iri)) && (!Regex.IsMatch(iri, "[a-zA-Z0-9_]+:.+")))
                {
                    throw new InvalidOperationException("Invalid IRI mapping.");
                }

                if ((string)iri == Context)
                {
                    throw new InvalidOperationException("Invalid keyword alias.");
                }

                definition.Iri = iri;
//.........这里部分代码省略.........
开发者ID:rafalrosochacki,项目名称:RomanticWeb,代码行数:101,代码来源:JsonLdProcessor.expand.cs

示例5: ExpandIri

        private string ExpandIri(object value, Context context, JObject localContext = null, bool documentRelative = false, bool vocab = false, IDictionary<string, bool> defined = null)
        {
            if (value == null)
            {
                return null;
            }

            string valueString = (value as string);
            if (valueString == null)
            {
                throw new InvalidOperationException(System.String.Format("Cannot expand iri of type '{0}'.", value.GetType()));
            }

            if (IsKeyWord(valueString))
            {
                return valueString;
            }

            if ((localContext != null) && (localContext.IsPropertySet(valueString)) && (!defined.ContainsKey(valueString)))
            {
                CreateTermDefinition(valueString, context, localContext, defined);
            }

            if ((vocab) && (context.ContainsKey(valueString)))
            {
                return (context[valueString] != null ? context[valueString].Iri : null);
            }

            if (Regex.IsMatch(valueString, "[a-zA-Z0-9_]+:.+"))
            {
                string prefix = valueString.Substring(0, valueString.IndexOf(':'));
                string suffix = valueString.Substring(prefix.Length + 1);
                if ((prefix == "_") || (suffix.StartsWith("//")))
                {
                    return valueString;
                }

                if ((localContext != null) && (!defined.ContainsKey(prefix)))
                {
                    CreateTermDefinition(prefix, context, localContext, defined);
                }

                if (context.ContainsKey(prefix))
                {
                    return context[prefix].Iri.ToString() + suffix;
                }

                return valueString;
            }

            if ((vocab) && (context.Vocabulary != null))
            {
                return MakeAbsoluteUri(context.Vocabulary, valueString);
            }

            if (documentRelative)
            {
                return MakeAbsoluteUri(context.BaseIri, valueString);
            }

            return valueString;
        }
开发者ID:rafalrosochacki,项目名称:RomanticWeb,代码行数:62,代码来源:JsonLdProcessor.expand.cs

示例6: Expand

        private JToken Expand(string activeProperty, JObject @object, Context activeContext, IList<string> remoteContexts)
        {
            JObject result = new JObject();
            foreach (JProperty _property in @object.Properties().OrderBy(item => item.Name))
            {
                string key = _property.Name;
                JToken value = _property.Value;
                if (key == Context)
                {
                    activeContext = ProcessContext(activeContext, (JToken)value, remoteContexts);
                    continue;
                }

                string expandedProperty = ExpandIri(key, activeContext, (JObject)null, false, true, null);
                JToken expandedValue = null;
                if ((expandedProperty == null) || ((expandedProperty.IndexOf(':') == -1) && (!IsKeyWord(expandedProperty))))
                {
                    continue;
                }

                if (IsKeyWord(expandedProperty))
                {
                    if (ExpandKeyword(result, _property, activeProperty, expandedProperty, activeContext, remoteContexts, out expandedValue))
                    {
                        continue;
                    }
                }
                else if ((activeContext.ContainsKey(key)) && (activeContext[key].Container == Language) && (value is JObject))
                {
                    expandedValue = ExpandLanguageMap(result, _property, activeProperty, expandedProperty, activeContext, remoteContexts);
                }
                else if ((activeContext.ContainsKey(key)) && (activeContext[key].Container == Index) && (value is JObject))
                {
                    expandedValue = ExpandIndexMap(result, _property, activeProperty, expandedProperty, activeContext, remoteContexts);
                }
                else
                {
                    expandedValue = Expand(key, value, activeContext, remoteContexts);
                }

                if (expandedValue == null)
                {
                    continue;
                }

                if ((activeContext.ContainsKey(key)) && (activeContext[key].Container == List))
                {
                    expandedValue = (expandedValue is JArray ? new JObject(new JProperty(List, expandedValue)) : expandedValue);
                    expandedValue = ((!(expandedValue is JObject)) || (!((JObject)expandedValue).IsPropertySet(List)) ? new JObject(new JProperty(List, new JArray(expandedValue))) : expandedValue);
                }

                if ((activeContext.ContainsKey(key)) && (activeContext[key].IsReverse))
                {
                    JObject reverseMap = (JObject)(!result.IsPropertySet(Reverse) ? result[Reverse] = new JObject() : result[Reverse]);
                    foreach (JToken item in (JArray)(expandedValue = expandedValue.AsArray()))
                    {
                        if ((item is JObject) && ((((JObject)item).IsPropertySet(Value)) || (((JObject)item).IsPropertySet(List))))
                        {
                            throw new InvalidOperationException("Invalid reverse property value.");
                        }

                        ((JArray)(!reverseMap.IsPropertySet(expandedProperty) ? reverseMap[expandedProperty] = new JArray() : reverseMap[expandedProperty])).Merge(item);
                    }
                }
                else
                {
                    ((JArray)(!result.IsPropertySet(expandedProperty) ? result[expandedProperty] = new JArray() : result[expandedProperty])).Merge(expandedValue);
                }
            }

            return ValidateExpandedObject(activeProperty, result);
        }
开发者ID:rafalrosochacki,项目名称:RomanticWeb,代码行数:72,代码来源:JsonLdProcessor.expand.cs


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