Exemplo n.º 1
0
        public override bool Equals(object obj)
        {
            PositionTagged <T> other = obj as PositionTagged <T>;

            return(other != null &&
                   other.Position == Position &&
                   Equals(other.Value, Value));
        }
Exemplo n.º 2
0
 public AttributeValue(PositionTagged <string> prefix, PositionTagged <object> value, bool literal)
 {
     Prefix  = prefix;
     Value   = value;
     Literal = literal;
 }
Exemplo n.º 3
0
        public virtual void WriteAttributeTo(TextWriter writer, 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(writer, prefix);
                WritePositionTaggedLiteral(writer, 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;
                        string valToString = valStr;
                        if (valStr == null)
                        {
                            valToString = val.Value.ToString();
                        }
                        if (boolVal != null)
                        {
                            Debug.Assert(boolVal.Value);
                            valToString = name;
                        }

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

                        if (attrVal.Literal)
                        {
                            WriteLiteralTo(writer, valToString);
                        }
                        else
                        {
                            if (val.Value is IEncodedString && boolVal == null)
                            {
                                WriteTo(writer, val.Value); // Write value
                            }
                            else
                            {
                                WriteTo(writer, valToString); // Write value
                            }
                        }
                        wroteSomething = true;
                    }
                }
                if (wroteSomething)
                {
                    WritePositionTaggedLiteral(writer, suffix);
                }
            }
        }
Exemplo n.º 4
0
 public virtual void WriteAttribute(string name, PositionTagged <string> prefix, PositionTagged <string> suffix, params AttributeValue[] values)
 {
     WriteAttributeTo(CurrentWriter, name, prefix, suffix, values);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Writes a <see cref="PositionTagged{}" /> literal to the result.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="value">The literal to be written.</param>
 private void WritePositionTaggedLiteral(TextWriter writer, PositionTagged <string> value)
 {
     WriteLiteralTo(writer, value.Value);
 }