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


C# Context.Lookup方法代码示例

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


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

示例1: Render

        /// <summary>
        /// Renders a tokens representation (or interpolated lambda result) escaping the
        /// result
        /// </summary>
        /// <param name="writer">The writer to write the token to</param>
        /// <param name="context">The context to discover values from</param>
        /// <param name="partials">The partial templates available to the token</param>
        /// <param name="originalTemplate">The original template</param>
        /// <returns>The rendered token result that has been escaped</returns>
        public string Render(Writer writer, Context context, IDictionary<string, string> partials, string originalTemplate)
        {
            var value = context.Lookup(Value);
            value = InterpolateLambdaValueIfPossible(value, writer, context, partials);

            return value != null ? WebUtility.HtmlEncode(value.ToString()) : null;
        }
开发者ID:StubbleOrg,项目名称:Stubble,代码行数:16,代码来源:EscapedValueToken.cs

示例2: Render

        /// <summary>
        /// Renders a tokens representation if the value (or interpolated value result)
        /// is truthy
        /// </summary>
        /// <param name="writer">The writer to write the token to</param>
        /// <param name="context">The context to discover values from</param>
        /// <param name="partials">The partial templates available to the token</param>
        /// <param name="originalTemplate">The original template</param>
        /// <returns>The rendered result of the token if the resolved value is not truthy</returns>
        public string Render(Writer writer, Context context, IDictionary<string, string> partials, string originalTemplate)
        {
            var value = context.Lookup(Value);
            value = InterpolateLambdaValueIfPossible(value, writer, context, partials);

            return !context.IsTruthyValue(value) ? writer.RenderTokens(ChildTokens, context, partials, originalTemplate) : null;
        }
开发者ID:StubbleOrg,项目名称:Stubble,代码行数:16,代码来源:InvertedToken.cs

示例3: Render

        /// <summary>
        /// Renders a tokens representation (or interpolated lambda result)
        /// </summary>
        /// <param name="writer">The writer to write the token to</param>
        /// <param name="context">The context to discover values from</param>
        /// <param name="partials">The partial templates available to the token</param>
        /// <param name="originalTemplate">The original template</param>
        /// <returns>The rendered token result</returns>
        public string Render(Writer writer, Context context, IDictionary<string, string> partials, string originalTemplate)
        {
            var value = context.Lookup(Value);
            value = InterpolateLambdaValueIfPossible(value, writer, context, partials);

            return value?.ToString();
        }
开发者ID:StubbleOrg,项目名称:Stubble,代码行数:15,代码来源:UnescapedValueToken.cs

示例4: TestNullValueDoesntAlterDictionary

 public void TestNullValueDoesntAlterDictionary()
 {
     var copyField = new Scalar(new QName("value"), FastType.I32, Operator.Copy, new IntegerValue(10), true);
     var field = new Scalar(new QName("value"), FastType.I32, Operator.Default, new IntegerValue(10), true);
     MessageTemplate copyTemplate = Template(copyField);
     MessageTemplate template = Template(field);
     var context = new Context();
     var encoder = new FastEncoder(context);
     encoder.RegisterTemplate(1, template);
     encoder.RegisterTemplate(2, copyTemplate);
     var message = (Message)copyTemplate.CreateValue(null);
     message.SetInteger(1, 11);
     encoder.Encode(message);
     Assert.AreEqual(11, context.Lookup("global", copyTemplate, new QName("value")).ToInt());
     message = (Message)template.CreateValue(null);
     encoder.Encode(message);
     Assert.AreEqual(11, context.Lookup("global", copyTemplate, new QName("value")).ToInt());
 }
开发者ID:shariqkudcs,项目名称:openfastdotnet,代码行数:18,代码来源:DefaultOperatorTest.cs

示例5: TestLookup

        public void TestLookup()
        {
            var allocationInstruction =
                new MessageTemplate(ObjectMother.AllocationInstruction)
                    {
                        TypeReference = new QName("AllocationInstruction")
                    };

            var allocations = new Sequence(ObjectMother.Allocations) {TypeReference = new QName("Allocation")};

            var context = new Context();

            context.Store(DictionaryFields.Type, allocationInstruction, new QName("ID"), String("1234"));

            Assert.AreEqual(String("1234"),
                            context.Lookup(DictionaryFields.Type, allocationInstruction, new QName("ID")));
            Assert.AreEqual(ScalarValue.Undefined,
                            context.Lookup(DictionaryFields.Type, allocations.Group, new QName("ID")));
        }
开发者ID:shariqkudcs,项目名称:openfastdotnet,代码行数:19,代码来源:ApplicationTypeDictionaryTest.cs

示例6: Render

        /// <summary>
        /// Returns the rendered result of all the child tokens of the section
        /// if the token value is truthy
        /// </summary>
        /// <param name="writer">The writer to write the token to</param>
        /// <param name="context">The context to discover values from</param>
        /// <param name="partials">The partial templates available to the token</param>
        /// <param name="originalTemplate">The original template</param>
        /// <returns>The rendered result of all the sections children</returns>
        public string Render(Writer writer, Context context, IDictionary<string, string> partials, string originalTemplate)
        {
            var buffer = new StringBuilder();
            var value = context.Lookup(Value);

            if (!context.IsTruthyValue(value))
            {
                return null;
            }

            if (value is IEnumerable && !EnumerableBlacklist.Any(x => x.IsInstanceOfType(value)))
            {
                var arrayValue = value as IEnumerable;

                foreach (var v in arrayValue)
                {
                    buffer.Append(writer.RenderTokens(ChildTokens, context.Push(v), partials, originalTemplate));
                }
            }
            else if (value is IEnumerator)
            {
                var enumeratorValue = value as IEnumerator;
                while (enumeratorValue.MoveNext())
                {
                    buffer.Append(writer.RenderTokens(ChildTokens, context.Push(enumeratorValue.Current), partials, originalTemplate));
                }
            }
            else if (value is Func<dynamic, string, object> || value is Func<string, object>)
            {
                var functionDynamicValue = value as Func<dynamic, string, object>;
                var functionStringValue = value as Func<string, object>;
                var sectionContent = originalTemplate.Slice(End, ParentSectionEnd);
                value = functionDynamicValue != null ? functionDynamicValue.Invoke(context.View, sectionContent) : functionStringValue.Invoke(sectionContent);
                value = writer.Render(value.ToString(), context, partials, Tags);

                if (value != null)
                {
                    buffer.Append(value);
                }
            }
            else if (value is IDictionary || value != null)
            {
                buffer.Append(writer.RenderTokens(ChildTokens, context.Push(value), partials, originalTemplate));
            }

            return buffer.ToString();
        }
开发者ID:StubbleOrg,项目名称:Stubble,代码行数:56,代码来源:SectionToken.cs

示例7: Encode

 public override byte[] Encode(FieldValue fieldValue, Group encodeTemplate, Context context, BitVectorBuilder presenceMapBuilder)
 {
     var priorValue = context.Lookup(Dictionary, encodeTemplate, Key);
     var value_Renamed = (ScalarValue) fieldValue;
     if (!operatorCodec.CanEncode(value_Renamed, this))
     {
         Global.HandleError(Error.FastConstants.D3_CANT_ENCODE_VALUE, "The scalar " + this + " cannot encode the value " + value_Renamed);
     }
     var valueToEncode = operatorCodec.GetValueToEncode(value_Renamed, priorValue, this, presenceMapBuilder);
     if (operator_Renamed.ShouldStoreValue(value_Renamed))
     {
         context.Store(Dictionary, encodeTemplate, Key, value_Renamed);
     }
     if (valueToEncode == null)
     {
         return new byte[0];
     }
     byte[] encoding = typeCodec.Encode(valueToEncode);
     if (context.TraceEnabled && encoding.Length > 0)
     {
         context.GetEncodeTrace().Field(this, fieldValue, valueToEncode, encoding, presenceMapBuilder.Index);
     }
     return encoding;
 }
开发者ID:marlonbomfim,项目名称:openfastdotnet,代码行数:24,代码来源:Scalar.cs

示例8: Encode

        public override byte[] Encode(IFieldValue fieldValue, Group encodeTemplate, Context context,
                                      BitVectorBuilder presenceMapBuilder)
        {
            IDictionary dict = context.GetDictionary(Dictionary);

            ScalarValue priorValue = context.Lookup(dict, encodeTemplate, Key);
            var value = (ScalarValue) fieldValue;
            if (!_operatorCodec.CanEncode(value, this))
            {
                Global.ErrorHandler.OnError(null, DynError.CantEncodeValue,
                                            "The scalar {0} cannot encode the value {1}", this, value);
            }
            ScalarValue valueToEncode = _operatorCodec.GetValueToEncode(value, priorValue, this,
                                                                        presenceMapBuilder);
            if (_operator.ShouldStoreValue(value))
            {
                context.Store(dict, encodeTemplate, Key, value);
            }
            if (valueToEncode == null)
            {
                return ByteUtil.EmptyByteArray;
            }
            byte[] encoding = _typeCodec.Encode(valueToEncode);
            if (context.TraceEnabled && encoding.Length > 0)
            {
                context.EncodeTrace.Field(this, fieldValue, valueToEncode, encoding, presenceMapBuilder.Index);
            }
            return encoding;
        }
开发者ID:shariqkudcs,项目名称:openfastdotnet,代码行数:29,代码来源:Scalar.cs

示例9: Decode

 public override FieldValue Decode(System.IO.Stream in_Renamed, Group decodeTemplate, Context context, BitVectorReader presenceMapReader)
 {
     try
     {
         ScalarValue previousValue = null;
         if (operator_Renamed.UsesDictionary())
         {
             previousValue = context.Lookup(Dictionary, decodeTemplate, Key);
             ValidateDictionaryTypeAgainstFieldType(previousValue, type);
         }
         ScalarValue value_Renamed;
         int pmapIndex = presenceMapReader.Index;
         if (IsPresent(presenceMapReader))
         {
             if (context.TraceEnabled)
                 in_Renamed = new RecordingInputStream(in_Renamed);
             if (!operatorCodec.ShouldDecodeType())
             {
                 return operatorCodec.DecodeValue(null, null, this);
             }
             ScalarValue decodedValue = typeCodec.Decode(in_Renamed);
             value_Renamed = DecodeValue(decodedValue, previousValue);
             if (context.TraceEnabled)
                 context.DecodeTrace.Field(this, value_Renamed, decodedValue, ((RecordingInputStream) in_Renamed).Buffer, pmapIndex);
         }
         else
         {
             value_Renamed = Decode(previousValue);
         }
         ValidateDecodedValueIsCorrectForType(value_Renamed, type);
         if (!((Operator == Template.Operator.Operator.DELTA) && (value_Renamed == null)))
         {
             context.Store(Dictionary, decodeTemplate, Key, value_Renamed);
         }
         return value_Renamed;
     }
     catch (FastException e)
     {
         throw new FastException("Error occurred while decoding " + this, e.Code, e);
     }
 }
开发者ID:marlonbomfim,项目名称:openfastdotnet,代码行数:41,代码来源:Scalar.cs

示例10: Propogate

        public override void Propogate(Context env, object matched, double strength)
        {
            base.Propogate(env, matched, strength);

            if (strength > .5 && matched is IParsedPhrase)
                ((Variable)env.Lookup("%verb")).Propogate(env, new WordPhrase(verbs.InputToBase(((IParsedPhrase) matched).Text), "VB"), .5 * strength);
        }
开发者ID:killix,项目名称:Virsona-ChatBot-Tools,代码行数:7,代码来源:GrammarVariables.cs

示例11: Decode

        public override IFieldValue Decode(Stream inStream, Group decodeTemplate, Context context,
                                           BitVectorReader presenceMapReader)
        {
            try
            {
                ScalarValue priorValue = null;
                IDictionary dict = null;
                QName key = Key;

                ScalarValue value;
                int pmapIndex = presenceMapReader.Index;
                if (IsPresent(presenceMapReader))
                {
                    if (context.TraceEnabled)
                        inStream = new RecordingInputStream(inStream);

                    if (!_operatorCodec.ShouldDecodeType)
                        return _operatorCodec.DecodeValue(null, null, this);

                    if (_operatorCodec.DecodeNewValueNeedsPrevious)
                    {
                        dict = context.GetDictionary(Dictionary);
                        priorValue = context.Lookup(dict, decodeTemplate, key);
                        ValidateDictionaryTypeAgainstFieldType(priorValue, _fastType);
                    }

                    ScalarValue decodedValue = _typeCodec.Decode(inStream);
                    value = _operatorCodec.DecodeValue(decodedValue, priorValue, this);

                    if (context.TraceEnabled)
                        context.DecodeTrace.Field(this, value, decodedValue,
                                                  ((RecordingInputStream) inStream).Buffer, pmapIndex);
                }
                else
                {
                    if (_operatorCodec.DecodeEmptyValueNeedsPrevious)
                    {
                        dict = context.GetDictionary(Dictionary);
                        priorValue = context.Lookup(dict, decodeTemplate, key);
                        ValidateDictionaryTypeAgainstFieldType(priorValue, _fastType);
                    }

                    value = _operatorCodec.DecodeEmptyValue(priorValue, this);
                }

                ValidateDecodedValueIsCorrectForType(value, _fastType);

            #warning TODO: Review if this previous "if" statement is needed.
                // if (Operator != Template.Operator.Operator.DELTA || value != null)
                if (value != null &&
                    (_operatorCodec.DecodeNewValueNeedsPrevious || _operatorCodec.DecodeEmptyValueNeedsPrevious))
                {
                    context.Store(dict ?? context.GetDictionary(Dictionary), decodeTemplate, key, value);
                }

                return value;
            }
            catch (DynErrorException e)
            {
                throw new DynErrorException(e, e.Error, "Error occurred while decoding {0}", this);
            }
        }
开发者ID:shariqkudcs,项目名称:openfastdotnet,代码行数:62,代码来源:Scalar.cs

示例12: RenderSection

            string RenderSection(Token token, Context context, object partials, string originalTemplate)
            {
                var buffer = "";
                var value = context.Lookup(token.Value);

                // This function is used to Render an arbitrary template
                // in the current context by higher-order sections.
                Func<string, string> subRender = template => Render(template, context, partials);

                if (value == null || value is bool && !(bool) value)
                    return ""; // this would have returned null/undefined instead of a string in JS version?

                //if (IsArray(Value)) {
                // TODO: HORRIBLE HACK to differentiate Jobject and iterables.
                if ((value.GetType().ToString().Contains("Jobject")))
                {
                    buffer += RenderTokens(token.SubTokens, context.Push(value), partials, originalTemplate);
                }
                else if (IsArray(value))
                {
                    foreach (var item in (IList) value)
                    {
                        buffer += RenderTokens(token.SubTokens, context.Push(item), partials, originalTemplate);
                    }
                    //} else if (typeof Value === 'object' || typeof Value === 'string' || typeof Value === 'number') {
                    //    buffer += this.RenderTokens(token[4], context.Push(Value), partials, originalTemplate);
                }
                else if (value is Func<string, Func<string, string>, string>)
                {
                    var lambda =
                        value as Func<string, Func<string, string>, string>;
                    //Value = lambda(context._view, originalTemplate.Substring(token.End, token.EndSection), subRender);
                    // TODO: how do we set the "this" in c#? Do we care?
                    value = lambda(originalTemplate.Substring(token.End, token.EndSection - token.End), subRender);

                    if (value != null)
                        buffer += value;

                    //} else if (Value as dynamic != null) {
                    //    buffer += this.RenderTokens(token.SubTokens, context.Push(Value), partials, originalTemplate);
                }
                else
                {
                    buffer += RenderTokens(token.SubTokens, context, partials, originalTemplate);
                }
                return buffer;
            }
开发者ID:vahpetr,项目名称:MustacheCs2,代码行数:47,代码来源:Mustache.cs

示例13: UnescapedValue

 string UnescapedValue(Token token, Context context)
 {
     var value = context.Lookup(token.Value);
     return (string) value;
 }
开发者ID:vahpetr,项目名称:MustacheCs2,代码行数:5,代码来源:Mustache.cs

示例14: EscapedValue

 string EscapedValue(Token token, Context context)
 {
     var value = context.Lookup(token.Value);
     if (value == null) return null;
     var str = token.Format != null ? ((DateTime) value).ToString(token.Format) : value.ToString();
     return SecurityElement.Escape(str);
 }
开发者ID:vahpetr,项目名称:MustacheCs2,代码行数:7,代码来源:Mustache.cs

示例15: RenderInverted

            string RenderInverted(Token token, Context context, object partials, string originalTemplate)
            {
                var value = context.Lookup(token.Value);

                // Use JavaScript's definition of falsy. Include empty arrays.
                // See https://github.com/janl/mustache.js/issues/186
                //if (!Value || (IsArray(Value) && Value.length === 0))
                if (value == null || IsEmptyArray(value))
                    return RenderTokens(token.SubTokens, context, partials, originalTemplate);

                return null; // TODO?
            }
开发者ID:vahpetr,项目名称:MustacheCs2,代码行数:12,代码来源:Mustache.cs


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