public override void WriteField(FieldInfo info, IndexableField field)
        {
            Write(FIELD);
            Write(info.Number.ToString(CultureInfo.InvariantCulture));
            NewLine();

            Write(NAME);
            Write(field.Name);
            NewLine();

            Write(TYPE);

            var n = field.NumericValue;

            if (n != null)
            {
                if (n is sbyte? || n is short? || n is int?)
                {
                    Write(TYPE_INT);
                    NewLine();

                    Write(VALUE);
                    Write(((int)n).ToString(CultureInfo.InvariantCulture));
                    NewLine();
                }
                else if (n is long?)
                {
                    Write(TYPE_LONG);
                    NewLine();

                    Write(VALUE);
                    Write(((long)n).ToString(CultureInfo.InvariantCulture));
                    NewLine();
                }
                else if (n is float?)
                {
                    Write(TYPE_FLOAT);
                    NewLine();

                    Write(VALUE);
                    // LUCENENET: Need to specify the "R" for round-trip: http://stackoverflow.com/a/611564/181087
                    Write(((float)n).ToString("R", CultureInfo.InvariantCulture));
                    NewLine();
                }
                else if (n is double?)
                {
                    Write(TYPE_DOUBLE);
                    NewLine();

                    Write(VALUE);
                    // LUCENENET: Need to specify the "R" for round-trip: http://stackoverflow.com/a/611564/181087
                    Write(((double)n).ToString("R", CultureInfo.InvariantCulture));
                    NewLine();
                }
                else
                {
                    throw new ArgumentException("cannot store numeric type " + n.GetType());
                }
            }
            else
            {
                BytesRef bytes = field.BinaryValue;
                if (bytes != null)
                {
                    Write(TYPE_BINARY);
                    NewLine();

                    Write(VALUE);
                    Write(bytes);
                    NewLine();
                }
                else if (field.StringValue == null)
                {
                    throw new ArgumentException("field " + field.Name +
                                                " is stored but does not have binaryValue, stringValue nor numericValue");
                }
                else
                {
                    Write(TYPE_STRING);
                    NewLine();

                    Write(VALUE);
                    Write(field.StringValue);
                    NewLine();
                }
            }
        }
Exemple #2
0
        public override void WriteField(FieldInfo info, IndexableField field)
        {
            Write(FIELD);
            Write(Convert.ToString(info.Number));
            NewLine();

            Write(NAME);
            Write(field.Name());
            NewLine();

            Write(TYPE);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Number n = field.numericValue();
            Number n = field.NumericValue;

            if (n != null)
            {
                if (n is sbyte? || n is short? || n is int?)
                {
                    Write(TYPE_INT);
                    NewLine();

                    Write(VALUE);
                    Write(Convert.ToString((int)n));
                    NewLine();
                }
                else if (n is long?)
                {
                    Write(TYPE_LONG);
                    NewLine();

                    Write(VALUE);
                    Write(Convert.ToString((long)n));
                    NewLine();
                }
                else if (n is float?)
                {
                    Write(TYPE_FLOAT);
                    NewLine();

                    Write(VALUE);
                    Write(Convert.ToString((float)n));
                    NewLine();
                }
                else if (n is double?)
                {
                    Write(TYPE_DOUBLE);
                    NewLine();

                    Write(VALUE);
                    Write(Convert.ToString((double)n));
                    NewLine();
                }
                else
                {
                    throw new System.ArgumentException("cannot store numeric type " + n.GetType());
                }
            }
            else
            {
                BytesRef bytes = field.binaryValue();
                if (bytes != null)
                {
                    Write(TYPE_BINARY);
                    NewLine();

                    Write(VALUE);
                    Write(bytes);
                    NewLine();
                }
                else if (field.stringValue() == null)
                {
                    throw new ArgumentException("field " + field.Name() +
                                                " is stored but does not have binaryValue, stringValue nor numericValue");
                }
                else
                {
                    Write(TYPE_STRING);
                    NewLine();

                    Write(VALUE);
                    Write(field.StringValue());
                    NewLine();
                }
            }
        }
        public override void WriteField(FieldInfo info, IndexableField field)
        {
            Write(FIELD);
            Write(info.Number.ToString(CultureInfo.InvariantCulture));
            NewLine();

            Write(NAME);
            Write(field.Name);
            NewLine();

            Write(TYPE);

            var n = field.NumericValue;

            if (n != null)
            {
                if (n is sbyte? || n is short? || n is int?)
                {
                    Write(TYPE_INT);
                    NewLine();

                    Write(VALUE);
                    Write(((int)n).ToString(CultureInfo.InvariantCulture));
                    NewLine();
                }
                else if (n is long?)
                {
                    Write(TYPE_LONG);
                    NewLine();

                    Write(VALUE);
                    Write(((long)n).ToString(CultureInfo.InvariantCulture));
                    NewLine();
                }
                else if (n is float?)
                {
                    Write(TYPE_FLOAT);
                    NewLine();

                    Write(VALUE);
                    // LUCENENET: Need to specify the "R" for round-trip: http://stackoverflow.com/a/611564/181087
                    Write(((float)n).ToString("R", CultureInfo.InvariantCulture));
                    NewLine();
                }
                else if (n is double?)
                {
                    Write(TYPE_DOUBLE);
                    NewLine();

                    Write(VALUE);
                    // LUCENENET: Need to specify the "R" for round-trip: http://stackoverflow.com/a/611564/181087
                    Write(((double)n).ToString("R", CultureInfo.InvariantCulture));
                    NewLine();
                }
                else
                {
                    throw new ArgumentException("cannot store numeric type " + n.GetType());
                }
            }
            else
            {
                BytesRef bytes = field.BinaryValue;
                if (bytes != null)
                {
                    Write(TYPE_BINARY);
                    NewLine();

                    Write(VALUE);
                    Write(bytes);
                    NewLine();
                }
                else if (field.StringValue == null)
                {
                    throw new ArgumentException("field " + field.Name +
                                                       " is stored but does not have binaryValue, stringValue nor numericValue");
                }
                else
                {
                    Write(TYPE_STRING);
                    NewLine();

                    Write(VALUE);
                    Write(field.StringValue);
                    NewLine();
                }
            }
        }
        public override void WriteField(FieldInfo info, IndexableField field)
        {
            Write(FIELD);
            Write(Convert.ToString(info.Number));
            NewLine();

            Write(NAME);
            Write(field.Name());
            NewLine();

            Write(TYPE);

            var n = field.NumericValue;

            if (n != null)
            {
                if (n is sbyte? || n is short? || n is int?)
                {
                    Write(TYPE_INT);
                    NewLine();

                    Write(VALUE);
                    Write(Convert.ToString((int)n));
                    NewLine();
                }
                else if (n is long?)
                {
                    Write(TYPE_LONG);
                    NewLine();

                    Write(VALUE);
                    Write(Convert.ToString((long)n));
                    NewLine();
                }
                else if (n is float?)
                {
                    Write(TYPE_FLOAT);
                    NewLine();

                    Write(VALUE);
                    Write(Convert.ToString((float)n));
                    NewLine();
                }
                else if (n is double?)
                {
                    Write(TYPE_DOUBLE);
                    NewLine();

                    Write(VALUE);
                    Write(Convert.ToString((double)n));
                    NewLine();
                }
                else
                {
                    throw new ArgumentException("cannot store numeric type " + n.GetType());
                }
            }
            else
            {
                BytesRef bytes = field.BinaryValue();
                if (bytes != null)
                {
                    Write(TYPE_BINARY);
                    NewLine();

                    Write(VALUE);
                    Write(bytes);
                    NewLine();
                }
                else if (field.StringValue == null)
                {
                    throw new ArgumentException("field " + field.Name() +
                                                " is stored but does not have binaryValue, stringValue nor numericValue");
                }
                else
                {
                    Write(TYPE_STRING);
                    NewLine();

                    Write(VALUE);
                    Write(field.StringValue);
                    NewLine();
                }
            }
        }
        public override void WriteField(FieldInfo info, IndexableField field)
        {
            Write(FIELD);
            Write(Convert.ToString(info.Number));
            NewLine();

            Write(NAME);
            Write(field.Name());
            NewLine();

            Write(TYPE);

            var n = field.NumericValue;

            if (n != null)
            {
                if (n is sbyte? || n is short? || n is int?)
                {
                    Write(TYPE_INT);
                    NewLine();

                    Write(VALUE);
                    Write(Convert.ToString((int) n));
                    NewLine();
                }
                else if (n is long?)
                {
                    Write(TYPE_LONG);
                    NewLine();

                    Write(VALUE);
                    Write(Convert.ToString((long) n));
                    NewLine();
                }
                else if (n is float?)
                {
                    Write(TYPE_FLOAT);
                    NewLine();

                    Write(VALUE);
                    Write(Convert.ToString((float) n));
                    NewLine();
                }
                else if (n is double?)
                {
                    Write(TYPE_DOUBLE);
                    NewLine();

                    Write(VALUE);
                    Write(Convert.ToString((double) n));
                    NewLine();
                }
                else
                {
                    throw new ArgumentException("cannot store numeric type " + n.GetType());
                }
            }
            else
            {
                BytesRef bytes = field.BinaryValue();
                if (bytes != null)
                {
                    Write(TYPE_BINARY);
                    NewLine();

                    Write(VALUE);
                    Write(bytes);
                    NewLine();
                }
                else if (field.StringValue == null)
                {
                    throw new ArgumentException("field " + field.Name() +
                                                       " is stored but does not have binaryValue, stringValue nor numericValue");
                }
                else
                {
                    Write(TYPE_STRING);
                    NewLine();

                    Write(VALUE);
                    Write(field.StringValue);
                    NewLine();
                }
            }
        }