Example #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));
        }
Example #2
0
 public static void WriteAttributeTo(TextWriter writer, string name, PositionTagged <string> prefix, PositionTagged <string> suffix, params AttributeValue[] values)
 {
     WebPageExecutingBase.WriteAttributeTo(writer, name, prefix, suffix, values);
 }
 private static void WritePositionTaggedLiteral(TextWriter writer, PositionTagged <string> value)
 {
     WritePositionTaggedLiteral(writer, value.Value);
 }
        public static 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)
            {
                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

                    if (val.Value == null)
                    {
                        continue;
                    }

                    string stringValue;

                    if (val.Value is bool)
                    {
                        if ((bool)val.Value)
                        {
                            stringValue = name;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        stringValue = val.Value as string;
                    }

                    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;

                    // The extra branching here is to ensure that we call the Write*To(string) overload when
                    // possible.
                    if (attrVal.Literal && stringValue != null)
                    {
                        WriteLiteralTo(writer, stringValue);
                    }
                    else if (attrVal.Literal)
                    {
                        WriteLiteralTo(writer, val.Value);
                    }
                    else if (stringValue != null)
                    {
                        WriteTo(writer, stringValue);
                    }
                    else
                    {
                        WriteTo(writer, val.Value);
                    }

                    wroteSomething = true;
                }
                if (wroteSomething)
                {
                    WritePositionTaggedLiteral(writer, suffix);
                }
            }
        }
Example #5
0
 public AttributeValue(PositionTagged <string> prefix, PositionTagged <object> value, bool literal)
 {
     Prefix  = prefix;
     Value   = value;
     Literal = literal;
 }