예제 #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));
        }
예제 #2
0
 public AttributeValue(PositionTagged <string> prefix, PositionTagged <object> value, bool literal)
 {
     Prefix  = prefix;
     Value   = value;
     Literal = literal;
 }
예제 #3
0
 public virtual void WriteAttribute(string name, PositionTagged <string> prefix, PositionTagged <string> suffix, params AttributeValue[] values)
 {
     WriteAttributeTo(Writer, name, prefix, suffix, values);
 }
예제 #4
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;
                    PositionTagged <string> next    = i == values.Length - 1 ?
                                                      suffix :              // End of the list, grab the suffix
                                                      values[i + 1].Prefix; // Still in the list, grab the next prefix

                    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)
                        {
                            Debug.Assert(boolVal.Value);
                            valStr = name;
                        }

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

                        // Calculate length of the source span by the position of the next value (or suffix)
                        int sourceLength = next.Position - attrVal.Value.Position;

                        if (attrVal.Literal)
                        {
                            WriteLiteralTo(writer, valStr);
                        }
                        else
                        {
                            WriteTo(writer, valStr); // Write value
                        }
                        wroteSomething = true;
                    }
                }
                if (wroteSomething)
                {
                    WritePositionTaggedLiteral(writer, suffix);
                }
            }
        }
예제 #5
0
 private void WritePositionTaggedLiteral(TextWriter writer, PositionTagged <string> value)
 {
     WritePositionTaggedLiteral(writer, value.Value, value.Position);
 }