summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorMormegil <mormegil@centrum.cz>2015-05-06 16:33:50 +0200
committerWouter van Oortmerssen <wvo@google.com>2015-05-06 11:55:07 -0700
commit0ee1b99c5d38636c2ab8eb8e05dcd42b328c0cca (patch)
tree2f6164f8da6d120c66b42b39ba155c654ae23e36 /net
parenta50711ad13de9ae9082e19453f91c89c3f505bda (diff)
downloadflatbuffers-0ee1b99c5d38636c2ab8eb8e05dcd42b328c0cca.tar.gz
flatbuffers-0ee1b99c5d38636c2ab8eb8e05dcd42b328c0cca.tar.bz2
flatbuffers-0ee1b99c5d38636c2ab8eb8e05dcd42b328c0cca.zip
[BREAKING CHANGE] Field accessors should use property getters in C#
In C#, plain field accessors should not be nonparametric methods but should be standard property getters. The accessor methods with parameters were renamed to `GetXxx` because a method cannot be named identically to a property. Also, `ByteBuffer.Position`, `FlatBufferBuilder.Offset` and `FlatBufferBuilder.DataBuffer` are now properties instead of nonparametric accessor methods, for more idiomatic C# style. This is a breaking change, all client C# code accessing these fields needs to be changed (i.e. remove those `()` or add the `Get` prefix). Issue: #77 Change-Id: Iaabe9ada076e5ea2c69911cf6170fdda2df3487e
Diffstat (limited to 'net')
-rwxr-xr-xnet/FlatBuffers/ByteBuffer.cs3
-rw-r--r--net/FlatBuffers/FlatBufferBuilder.cs28
-rw-r--r--net/FlatBuffers/Table.cs2
3 files changed, 16 insertions, 17 deletions
diff --git a/net/FlatBuffers/ByteBuffer.cs b/net/FlatBuffers/ByteBuffer.cs
index ee79b1c9..aadd0ea5 100755
--- a/net/FlatBuffers/ByteBuffer.cs
+++ b/net/FlatBuffers/ByteBuffer.cs
@@ -17,7 +17,6 @@
//#define UNSAFE_BYTEBUFFER // uncomment this line to use faster ByteBuffer
using System;
-using System.Linq;
namespace FlatBuffers
{
@@ -42,7 +41,7 @@ namespace FlatBuffers
_pos = 0;
}
- public int position() { return _pos; }
+ public int Position { get { return _pos; } }
// Pre-allocated helper arrays for convertion.
private float[] floathelper = new[] { 0.0f };
diff --git a/net/FlatBuffers/FlatBufferBuilder.cs b/net/FlatBuffers/FlatBufferBuilder.cs
index c46a7709..453b6e5c 100644
--- a/net/FlatBuffers/FlatBufferBuilder.cs
+++ b/net/FlatBuffers/FlatBufferBuilder.cs
@@ -50,7 +50,7 @@ namespace FlatBuffers
}
- public int Offset() { return _bb.Length - _space; }
+ public int Offset { get { return _bb.Length - _space; } }
public void Pad(int size)
{
@@ -181,10 +181,10 @@ namespace FlatBuffers
public void AddOffset(int off)
{
Prep(sizeof(int), 0); // Ensure alignment is already done.
- if (off > Offset())
+ if (off > Offset)
throw new ArgumentException();
- off = Offset() - off + sizeof(int);
+ off = Offset - off + sizeof(int);
PutInt(off);
}
@@ -199,7 +199,7 @@ namespace FlatBuffers
public int EndVector()
{
PutInt(_vectorNumElems);
- return Offset();
+ return Offset;
}
public void Nested(int obj)
@@ -207,7 +207,7 @@ namespace FlatBuffers
// Structs are always stored inline, so need to be created right
// where they are used. You'll get this assert if you created it
// elsewhere.
- if (obj != Offset())
+ if (obj != Offset)
throw new Exception(
"FlatBuffers: struct must be serialized inline.");
}
@@ -225,7 +225,7 @@ namespace FlatBuffers
{
NotNested();
_vtable = new int[numfields];
- _objectStart = Offset();
+ _objectStart = Offset;
}
@@ -233,7 +233,7 @@ namespace FlatBuffers
// buffer.
public void Slot(int voffset)
{
- _vtable[voffset] = Offset();
+ _vtable[voffset] = Offset;
}
// Add a scalar to a table at `o` into its vtable, with value `x` and default `d`
@@ -280,7 +280,7 @@ namespace FlatBuffers
"Flatbuffers: calling endObject without a startObject");
AddInt((int)0);
- var vtableloc = Offset();
+ var vtableloc = Offset;
// Write out the current vtable.
for (int i = _vtable.Length - 1; i >= 0 ; i--) {
// Offset relative to the start of the table.
@@ -333,9 +333,9 @@ namespace FlatBuffers
_vtables = newvtables;
};
- _vtables[_numVtables++] = Offset();
+ _vtables[_numVtables++] = Offset;
// Point table to current vtable.
- _bb.PutInt(_bb.Length - vtableloc, Offset() - vtableloc);
+ _bb.PutInt(_bb.Length - vtableloc, Offset - vtableloc);
}
_vtable = null;
@@ -361,14 +361,14 @@ namespace FlatBuffers
AddOffset(rootTable);
}
- public ByteBuffer DataBuffer() { return _bb; }
+ public ByteBuffer DataBuffer { get { return _bb; } }
// Utility function for copying a byte array that starts at 0.
public byte[] SizedByteArray()
{
- var newArray = new byte[_bb.Data.Length - _bb.position()];
- Buffer.BlockCopy(_bb.Data, _bb.position(), newArray, 0,
- _bb.Data.Length - _bb.position());
+ var newArray = new byte[_bb.Data.Length - _bb.Position];
+ Buffer.BlockCopy(_bb.Data, _bb.Position, newArray, 0,
+ _bb.Data.Length - _bb.Position);
return newArray;
}
diff --git a/net/FlatBuffers/Table.cs b/net/FlatBuffers/Table.cs
index d6396a6f..218258ab 100644
--- a/net/FlatBuffers/Table.cs
+++ b/net/FlatBuffers/Table.cs
@@ -81,7 +81,7 @@ namespace FlatBuffers
for (var i = 0; i < FlatBufferConstants.FileIdentifierLength; i++)
{
- if (ident[i] != (char)bb.Get(bb.position() + sizeof(int) + i)) return false;
+ if (ident[i] != (char)bb.Get(bb.Position + sizeof(int) + i)) return false;
}
return true;