Пример #1
0
            internal bool Evaluate(TagData inTag, StringSlice inSource, object inContext, out string outReplace)
            {
                if (m_TryReplaceCallback != null)
                {
                    return(m_TryReplaceCallback(inTag, inContext, out outReplace));
                }

                if (m_HandleClosing && inTag.IsClosing())
                {
                    if (!string.IsNullOrEmpty(m_ConstantClosingText))
                    {
                        outReplace = m_ConstantClosingText;
                        return(true);
                    }

                    if (m_ReplaceClosingCallback != null)
                    {
                        outReplace = m_ReplaceClosingCallback();
                        return(true);
                    }

                    if (m_ReplaceWithContextClosingCallback != null)
                    {
                        outReplace = m_ReplaceWithContextClosingCallback(inTag, inContext);
                        return(true);
                    }

                    if (m_ReplaceSourceContextClosingCallback != null)
                    {
                        outReplace = m_ReplaceSourceContextClosingCallback(inSource, inContext);
                    }
                }

                if (m_ReplaceCallback != null)
                {
                    outReplace = m_ReplaceCallback();
                    return(true);
                }

                if (m_ReplaceWithContextCallback != null)
                {
                    outReplace = m_ReplaceWithContextCallback(inTag, inContext);
                    return(true);
                }

                if (m_ReplaceSourceContextCallback != null)
                {
                    outReplace = m_ReplaceSourceContextCallback(inSource, inContext);
                    return(true);
                }

                outReplace = m_ConstantText ?? string.Empty;
                return(true);
            }
Пример #2
0
            internal bool Evaluate(TagData inData, object inContext, out TagEventData outEvent)
            {
                outEvent           = new TagEventData(m_EventId);
                outEvent.IsClosing = inData.IsClosing();

                switch (m_DataMode)
                {
                case DataMode.String:
                {
                    if (inData.Data.IsEmpty)
                    {
                        outEvent.StringArgument = m_DefaultString;
                    }
                    else
                    {
                        outEvent.StringArgument = inData.Data;
                    }
                    break;
                }

                case DataMode.Float:
                {
                    float arg;
                    if (!StringParser.TryParseFloat(inData.Data, out arg))
                    {
                        arg = m_DefaultValue.AsFloat();
                    }
                    outEvent.Argument0 = arg;
                    break;
                }

                case DataMode.Bool:
                {
                    bool arg;
                    if (!StringParser.TryParseBool(inData.Data, out arg))
                    {
                        arg = m_DefaultValue.AsBool();
                    }
                    outEvent.Argument0 = arg;
                    break;
                }

                case DataMode.StringHash:
                {
                    StringHash32 arg;
                    if (!StringHash32.TryParse(inData.Data, out arg))
                    {
                        arg = m_DefaultValue.AsStringHash();
                    }
                    outEvent.Argument0 = arg;
                    break;
                }
                }

                if (m_HandleClosing && outEvent.IsClosing)
                {
                    outEvent.Type = m_EventClosingId;
                    if (m_EventClosingDelegate != null)
                    {
                        m_EventClosingDelegate(inData, inContext, ref outEvent);
                    }

                    return(true);
                }
                else
                {
                    if (m_EventDelegate != null)
                    {
                        m_EventDelegate(inData, inContext, ref outEvent);
                    }

                    return(true);
                }
            }