Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
57e5746a
Commit
57e5746a
authored
Jun 04, 2012
by
Jon Skeet
Browse files
Options
Browse Files
Download
Plain Diff
Merge.
parents
1c789143
34378b49
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
88 additions
and
21 deletions
+88
-21
unittest_issues.proto
protos/extest/unittest_issues.proto
+6
-2
IssuesTest.cs
src/ProtocolBuffers.Test/IssuesTest.cs
+59
-0
ProtocolBuffers.Test.csproj
src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj
+1
-0
UnitTestExtrasIssuesProtoFile.cs
...lBuffers.Test/TestProtos/UnitTestExtrasIssuesProtoFile.cs
+0
-0
ReflectionUtil.cs
src/ProtocolBuffers/FieldAccess/ReflectionUtil.cs
+5
-0
RepeatedPrimitiveAccessor.cs
src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs
+9
-9
SingleMessageAccessor.cs
src/ProtocolBuffers/FieldAccess/SingleMessageAccessor.cs
+1
-1
SinglePrimitiveAccessor.cs
src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs
+7
-9
No files found.
protos/extest/unittest_issues.proto
View file @
57e5746a
...
...
@@ -129,4 +129,9 @@ message DeprecatedFieldsMessage {
optional
DeprecatedEnum
EnumValue
=
5
[
deprecated
=
true
];
repeated
DeprecatedEnum
EnumArray
=
6
[
deprecated
=
true
];
}
\ No newline at end of file
}
// Issue 45: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=45
message
ItemField
{
optional
int32
item
=
1
;
}
src/ProtocolBuffers.Test/IssuesTest.cs
0 → 100644
View file @
57e5746a
#
region
Copyright
notice
and
license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using
Google.ProtocolBuffers.Descriptors
;
using
NUnit.Framework
;
using
UnitTest.Issues.TestProtos
;
namespace
Google.ProtocolBuffers
{
/// <summary>
/// Tests for issues which aren't easily compartmentalized into other unit tests.
/// </summary>
[
TestFixture
]
public
class
IssuesTest
{
// Issue 45
[
Test
]
public
void
FieldCalledItem
()
{
ItemField
message
=
new
ItemField
.
Builder
{
Item
=
3
}.
Build
();
FieldDescriptor
field
=
ItemField
.
Descriptor
.
FindFieldByName
(
"item"
);
Assert
.
IsNotNull
(
field
);
Assert
.
AreEqual
(
3
,
message
[
field
]);
}
}
}
src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj
View file @
57e5746a
...
...
@@ -94,6 +94,7 @@
<Compile
Include=
"ExtendableMessageTest.cs"
/>
<Compile
Include=
"GeneratedBuilderTest.cs"
/>
<Compile
Include=
"GeneratedMessageTest.cs"
/>
<Compile
Include=
"IssuesTest.cs"
/>
<Compile
Include=
"MessageStreamIteratorTest.cs"
/>
<Compile
Include=
"MessageStreamWriterTest.cs"
/>
<Compile
Include=
"MessageTest.cs"
/>
...
...
src/ProtocolBuffers.Test/TestProtos/UnitTestExtrasIssuesProtoFile.cs
View file @
57e5746a
This diff is collapsed.
Click to expand it.
src/ProtocolBuffers/FieldAccess/ReflectionUtil.cs
View file @
57e5746a
...
...
@@ -44,6 +44,11 @@ namespace Google.ProtocolBuffers.FieldAccess
/// </summary>
internal
static
class
ReflectionUtil
{
/// <summary>
/// Empty Type[] used when calling GetProperty to force property instead of indexer fetching.
/// </summary>
internal
static
readonly
Type
[]
EmptyTypes
=
new
Type
[
0
];
/// <summary>
/// Creates a delegate which will execute the given method and then return
/// the result as an object.
...
...
src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs
View file @
57e5746a
...
...
@@ -66,14 +66,14 @@ namespace Google.ProtocolBuffers.FieldAccess
internal
RepeatedPrimitiveAccessor
(
string
name
)
{
PropertyInfo
messageProperty
=
typeof
(
TMessage
).
GetProperty
(
name
+
"List"
);
PropertyInfo
builderProperty
=
typeof
(
TBuilder
).
GetProperty
(
name
+
"List"
);
PropertyInfo
countProperty
=
typeof
(
TMessage
).
GetProperty
(
name
+
"Count"
);
MethodInfo
clearMethod
=
typeof
(
TBuilder
).
GetMethod
(
"Clear"
+
name
,
EmptyTypes
);
getElementMethod
=
typeof
(
TMessage
).
GetMethod
(
"Get"
+
name
,
new
Type
[]
{
typeof
(
int
)});
PropertyInfo
messageProperty
=
typeof
(
TMessage
).
GetProperty
(
name
+
"List"
,
ReflectionUtil
.
EmptyTypes
);
PropertyInfo
builderProperty
=
typeof
(
TBuilder
).
GetProperty
(
name
+
"List"
,
ReflectionUtil
.
EmptyTypes
);
PropertyInfo
countProperty
=
typeof
(
TMessage
).
GetProperty
(
name
+
"Count"
,
ReflectionUtil
.
EmptyTypes
);
MethodInfo
clearMethod
=
typeof
(
TBuilder
).
GetMethod
(
"Clear"
+
name
,
EmptyTypes
);
getElementMethod
=
typeof
(
TMessage
).
GetMethod
(
"Get"
+
name
,
new
Type
[]
{
typeof
(
int
)});
clrType
=
getElementMethod
.
ReturnType
;
MethodInfo
addMethod
=
typeof
(
TBuilder
).
GetMethod
(
"Add"
+
name
,
new
Type
[]
{
ClrType
});
setElementMethod
=
typeof
(
TBuilder
).
GetMethod
(
"Set"
+
name
,
new
Type
[]
{
typeof
(
int
),
ClrType
});
MethodInfo
addMethod
=
typeof
(
TBuilder
).
GetMethod
(
"Add"
+
name
,
new
Type
[]
{
ClrType
});
setElementMethod
=
typeof
(
TBuilder
).
GetMethod
(
"Set"
+
name
,
new
Type
[]
{
typeof
(
int
),
ClrType
});
if
(
messageProperty
==
null
||
builderProperty
==
null
||
countProperty
==
null
...
...
@@ -85,9 +85,9 @@ namespace Google.ProtocolBuffers.FieldAccess
throw
new
ArgumentException
(
"Not all required properties/methods available"
);
}
clearDelegate
=
(
Func
<
TBuilder
,
IBuilder
>)
Delegate
.
CreateDelegate
(
typeof
(
Func
<
TBuilder
,
IBuilder
>),
null
,
clearMethod
);
(
Func
<
TBuilder
,
IBuilder
>)
Delegate
.
CreateDelegate
(
typeof
(
Func
<
TBuilder
,
IBuilder
>),
null
,
clearMethod
);
countDelegate
=
(
Func
<
TMessage
,
int
>)
Delegate
.
CreateDelegate
(
typeof
(
Func
<
TMessage
,
int
>),
null
,
countProperty
.
GetGetMethod
());
(
typeof
(
Func
<
TMessage
,
int
>),
null
,
countProperty
.
GetGetMethod
());
getValueDelegate
=
ReflectionUtil
.
CreateUpcastDelegate
<
TMessage
>(
messageProperty
.
GetGetMethod
());
addValueDelegate
=
ReflectionUtil
.
CreateDowncastDelegateIgnoringReturn
<
TBuilder
>(
addMethod
);
getRepeatedWrapperDelegate
=
ReflectionUtil
.
CreateUpcastDelegate
<
TBuilder
>(
builderProperty
.
GetGetMethod
());
...
...
src/ProtocolBuffers/FieldAccess/SingleMessageAccessor.cs
View file @
57e5746a
...
...
@@ -50,7 +50,7 @@ namespace Google.ProtocolBuffers.FieldAccess
internal
SingleMessageAccessor
(
string
name
)
:
base
(
name
)
{
MethodInfo
createBuilderMethod
=
ClrType
.
GetMethod
(
"CreateBuilder"
,
EmptyTypes
);
MethodInfo
createBuilderMethod
=
ClrType
.
GetMethod
(
"CreateBuilder"
,
ReflectionUtil
.
EmptyTypes
);
if
(
createBuilderMethod
==
null
)
{
throw
new
ArgumentException
(
"No public static CreateBuilder method declared in "
+
ClrType
.
Name
);
...
...
src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs
View file @
57e5746a
...
...
@@ -47,8 +47,6 @@ namespace Google.ProtocolBuffers.FieldAccess
private
readonly
Func
<
TMessage
,
bool
>
hasDelegate
;
private
readonly
Func
<
TBuilder
,
IBuilder
>
clearDelegate
;
internal
static
readonly
Type
[]
EmptyTypes
=
new
Type
[
0
];
/// <summary>
/// The CLR type of the field (int, the enum type, ByteString, the message etc).
/// As declared by the property.
...
...
@@ -60,14 +58,14 @@ namespace Google.ProtocolBuffers.FieldAccess
internal
SinglePrimitiveAccessor
(
string
name
)
{
PropertyInfo
messageProperty
=
typeof
(
TMessage
).
GetProperty
(
name
);
PropertyInfo
builderProperty
=
typeof
(
TBuilder
).
GetProperty
(
name
);
PropertyInfo
messageProperty
=
typeof
(
TMessage
).
GetProperty
(
name
,
ReflectionUtil
.
EmptyTypes
);
PropertyInfo
builderProperty
=
typeof
(
TBuilder
).
GetProperty
(
name
,
ReflectionUtil
.
EmptyTypes
);
if
(
builderProperty
==
null
)
{
builderProperty
=
typeof
(
TBuilder
).
GetProperty
(
name
);
builderProperty
=
typeof
(
TBuilder
).
GetProperty
(
name
,
ReflectionUtil
.
EmptyTypes
);
}
PropertyInfo
hasProperty
=
typeof
(
TMessage
).
GetProperty
(
"Has"
+
name
);
MethodInfo
clearMethod
=
typeof
(
TBuilder
).
GetMethod
(
"Clear"
+
name
,
EmptyTypes
);
PropertyInfo
hasProperty
=
typeof
(
TMessage
).
GetProperty
(
"Has"
+
name
,
ReflectionUtil
.
EmptyTypes
);
MethodInfo
clearMethod
=
typeof
(
TBuilder
).
GetMethod
(
"Clear"
+
name
,
ReflectionUtil
.
EmptyTypes
);
if
(
messageProperty
==
null
||
builderProperty
==
null
||
hasProperty
==
null
||
clearMethod
==
null
)
{
throw
new
ArgumentException
(
"Not all required properties/methods available"
);
...
...
@@ -75,9 +73,9 @@ namespace Google.ProtocolBuffers.FieldAccess
clrType
=
messageProperty
.
PropertyType
;
hasDelegate
=
(
Func
<
TMessage
,
bool
>)
Delegate
.
CreateDelegate
(
typeof
(
Func
<
TMessage
,
bool
>),
null
,
hasProperty
.
GetGetMethod
());
Delegate
.
CreateDelegate
(
typeof
(
Func
<
TMessage
,
bool
>),
null
,
hasProperty
.
GetGetMethod
());
clearDelegate
=
(
Func
<
TBuilder
,
IBuilder
>)
Delegate
.
CreateDelegate
(
typeof
(
Func
<
TBuilder
,
IBuilder
>),
null
,
clearMethod
);
(
Func
<
TBuilder
,
IBuilder
>)
Delegate
.
CreateDelegate
(
typeof
(
Func
<
TBuilder
,
IBuilder
>),
null
,
clearMethod
);
getValueDelegate
=
ReflectionUtil
.
CreateUpcastDelegate
<
TMessage
>(
messageProperty
.
GetGetMethod
());
setValueDelegate
=
ReflectionUtil
.
CreateDowncastDelegate
<
TBuilder
>(
builderProperty
.
GetSetMethod
());
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment