summaryrefslogtreecommitdiff
path: root/docs
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 /docs
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 'docs')
-rwxr-xr-xdocs/source/JavaUsage.md26
1 files changed, 23 insertions, 3 deletions
diff --git a/docs/source/JavaUsage.md b/docs/source/JavaUsage.md
index d52cd09a..9fa3647d 100755
--- a/docs/source/JavaUsage.md
+++ b/docs/source/JavaUsage.md
@@ -5,8 +5,8 @@ Generate code for Java with the `-j` option to `flatc`, or for C# with `-n`
(think .Net).
Note that this document is from the perspective of Java. Code for both languages
-is generated in the same way, with only very subtle differences, for example
-any `camelCase` Java call will be `CamelCase` in C#.
+is generated in the same way, with only minor differences. These differences
+are [explained in a section below](#differences-in-c-sharp).
See `javaTest.java` for an example. Essentially, you read a FlatBuffer binary
file into a `byte[]`, which you then turn into a `ByteBuffer`, which you pass to
@@ -151,7 +151,27 @@ not start from offset 0 in this buffer, but from `fbb.dataBuffer().position()`
It ends at `fbb.capacity()`.
-## Text Parsing
+## Differences in C-sharp
+
+C# code works almost identically to Java, with only a few minor differences.
+You can see an example of C# code in `tests/FlatBuffers.Test/FlatBuffersExampleTests.cs`.
+
+First of all, naming follows standard C# style with `PascalCasing` identifiers,
+e.g. `GetRootAsMyRootType`. Also, values (except vectors and unions) are available
+as properties instead of parameterless accessor methods as in Java. The
+performance-enhancing methods to which you can pass an already created object
+are prefixed with `Get`, e.g.:
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
+ // property
+ var pos = monster.Pos;
+ // method filling a preconstructed object
+ var preconstructedPos = new Vec3();
+ monster.GetPos(preconstructedPos);
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+## Text parsing
There currently is no support for parsing text (Schema's and JSON) directly
from Java, though you could use the C++ parser through JNI. Please see the