示例#1
0
        /// <summary>Determines whether the specified <see cref="System.Object" }, is equal to this instance.</summary>
        /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
        /// <returns><c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            PositionTagged <T> other = obj as PositionTagged <T>;

            return(other != null &&
                   other.Position == Position &&
                   Equals(other.Value, Value));
        }
示例#2
0
 /// <summary>Initializes a new instance of the <see cref="AttributeValue"/> class.</summary>
 /// <param name="prefix">The prefix.</param>
 /// <param name="value">The value.</param>
 /// <param name="literal">if set to <c>true</c> [literal].</param>
 public AttributeValue(PositionTagged <string> prefix, PositionTagged <object> value, bool literal)
 {
     Prefix  = prefix;
     Value   = value;
     Literal = literal;
 }
示例#3
0
 /// <summary>Writes a <see cref="PositionTagged{string}" /> literal to the result.</summary>
 /// <param name="value">The value.</param>
 private void WritePositionTaggedLiteral(PositionTagged <string> value)
 {
     WriteLiteral(value.Value);
 }
示例#4
0
        /// <summary>Writes an attribute to the result.</summary>
        /// <param name="name">The name of the attribute.</param>
        /// <param name="prefix">The prefix.</param>
        /// <param name="suffix">The suffix.</param>
        /// <param name="values">The values.</param>
        public virtual void WriteAttribute(string name, PositionTagged <string> prefix, PositionTagged <string> suffix, params AttributeValue[] values)
        {
            bool first          = true;
            bool wroteSomething = false;

            if (values.Length == 0)
            {
                // Explicitly empty attribute, so write the prefix and suffix
                WritePositionTaggedLiteral(prefix);
                WritePositionTaggedLiteral(suffix);
            }
            else
            {
                for (int i = 0; i < values.Length; i++)
                {
                    AttributeValue          attrVal = values[i];
                    PositionTagged <object> val     = attrVal.Value;

                    bool?boolVal = null;
                    if (val.Value is bool)
                    {
                        boolVal = (bool)val.Value;
                    }

                    if (val.Value != null && (boolVal == null || boolVal.Value))
                    {
                        string valStr = val.Value as string;
                        if (valStr == null)
                        {
                            valStr = val.Value.ToString();
                        }
                        if (boolVal != null)
                        {
                            valStr = name;
                        }

                        if (first)
                        {
                            WritePositionTaggedLiteral(prefix);
                            first = false;
                        }
                        else
                        {
                            WritePositionTaggedLiteral(attrVal.Prefix);
                        }

                        if (attrVal.Literal)
                        {
                            WriteLiteral(valStr);
                        }
                        else
                        {
                            Write(valStr);                             // Write value
                        }
                        wroteSomething = true;
                    }
                }
                if (wroteSomething)
                {
                    WritePositionTaggedLiteral(suffix);
                }
            }
        }