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
9163a6f1
Commit
9163a6f1
authored
May 06, 2019
by
Sydney Acksman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for extension accessor
parent
0c80570a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
9 deletions
+65
-9
FieldAccessTest.cs
...rp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs
+0
-0
SampleMessages.cs
csharp/src/Google.Protobuf.Test/SampleMessages.cs
+58
-3
FieldDescriptor.cs
csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
+6
-5
ReflectionUtil.cs
csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs
+1
-1
No files found.
csharp/src/Google.Protobuf.Test/Reflection/FieldAccessTest.cs
View file @
9163a6f1
This diff is collapsed.
Click to expand it.
csharp/src/Google.Protobuf.Test/SampleMessages.cs
View file @
9163a6f1
...
...
@@ -32,7 +32,9 @@
using
System
;
using
Google.Protobuf.TestProtos
;
using
Proto2
=
Google
.
Protobuf
.
TestProtos
.
Proto2
;
using
Proto2
=
Google
.
Protobuf
.
TestProtos
.
Proto2
;
using
static
Google
.
Protobuf
.
TestProtos
.
Proto2
.
UnittestExtensions
;
namespace
Google.Protobuf
{
...
...
@@ -61,7 +63,7 @@ namespace Google.Protobuf
SingleImportMessage
=
new
ImportMessage
{
D
=
20
},
SingleInt32
=
100
,
SingleInt64
=
3210987654321
,
SingleNestedEnum
=
TestAllTypes
.
Types
.
NestedEnum
.
Foo
,
SingleNestedEnum
=
Test
Protos
.
Test
AllTypes
.
Types
.
NestedEnum
.
Foo
,
SingleNestedMessage
=
new
TestAllTypes
.
Types
.
NestedMessage
{
Bb
=
35
},
SinglePublicImportMessage
=
new
PublicImportMessage
{
E
=
54
},
SingleSfixed32
=
-
123
,
...
...
@@ -83,7 +85,7 @@ namespace Google.Protobuf
RepeatedImportMessage
=
{
new
ImportMessage
{
D
=
20
},
new
ImportMessage
{
D
=
25
}
},
RepeatedInt32
=
{
100
,
200
},
RepeatedInt64
=
{
3210987654321
,
Int64
.
MaxValue
},
RepeatedNestedEnum
=
{
Test
AllTypes
.
Types
.
NestedEnum
.
Foo
,
TestAllTypes
.
Types
.
NestedEnum
.
Neg
},
RepeatedNestedEnum
=
{
Test
Protos
.
TestAllTypes
.
Types
.
NestedEnum
.
Foo
,
TestProtos
.
TestAllTypes
.
Types
.
NestedEnum
.
Neg
},
RepeatedNestedMessage
=
{
new
TestAllTypes
.
Types
.
NestedMessage
{
Bb
=
35
},
new
TestAllTypes
.
Types
.
NestedMessage
{
Bb
=
10
}
},
RepeatedPublicImportMessage
=
{
new
PublicImportMessage
{
E
=
54
},
new
PublicImportMessage
{
E
=
-
1
}
},
RepeatedSfixed32
=
{
-
123
,
123
},
...
...
@@ -149,5 +151,57 @@ namespace Google.Protobuf
OneofString
=
"Oneof string"
};
}
public
static
Proto2
.
TestAllExtensions
CreateFullTestAllExtensions
()
{
var
message
=
new
Proto2
.
TestAllExtensions
();
message
.
SetExtension
(
OptionalBoolExtension
,
true
);
message
.
SetExtension
(
OptionalBytesExtension
,
ByteString
.
CopyFrom
(
1
,
2
,
3
,
4
));
message
.
SetExtension
(
OptionalDoubleExtension
,
23.5
);
message
.
SetExtension
(
OptionalFixed32Extension
,
23u
);
message
.
SetExtension
(
OptionalFixed64Extension
,
1234567890123u
);
message
.
SetExtension
(
OptionalFloatExtension
,
12.25f
);
message
.
SetExtension
(
OptionalForeignEnumExtension
,
Proto2
.
ForeignEnum
.
ForeignBar
);
message
.
SetExtension
(
OptionalForeignMessageExtension
,
new
Proto2
.
ForeignMessage
{
C
=
10
});
message
.
SetExtension
(
OptionalImportEnumExtension
,
Proto2
.
ImportEnum
.
ImportBaz
);
message
.
SetExtension
(
OptionalImportMessageExtension
,
new
Proto2
.
ImportMessage
{
D
=
20
});
message
.
SetExtension
(
OptionalInt32Extension
,
100
);
message
.
SetExtension
(
OptionalInt64Extension
,
3210987654321
);
message
.
SetExtension
(
OptionalNestedEnumExtension
,
Proto2
.
TestAllTypes
.
Types
.
NestedEnum
.
Foo
);
message
.
SetExtension
(
OptionalNestedMessageExtension
,
new
Proto2
.
TestAllTypes
.
Types
.
NestedMessage
{
Bb
=
35
});
message
.
SetExtension
(
OptionalPublicImportMessageExtension
,
new
Proto2
.
PublicImportMessage
{
E
=
54
});
message
.
SetExtension
(
OptionalSfixed32Extension
,
-
123
);
message
.
SetExtension
(
OptionalSfixed64Extension
,
-
12345678901234
);
message
.
SetExtension
(
OptionalSint32Extension
,
-
456
);
message
.
SetExtension
(
OptionalSint64Extension
,
-
12345678901235
);
message
.
SetExtension
(
OptionalStringExtension
,
"test"
);
message
.
SetExtension
(
OptionalUint32Extension
,
UInt32
.
MaxValue
);
message
.
SetExtension
(
OptionalUint64Extension
,
UInt64
.
MaxValue
);
message
.
SetExtension
(
OptionalGroupExtension
,
new
Proto2
.
OptionalGroup_extension
{
A
=
10
});
message
.
GetOrRegisterExtension
(
RepeatedBoolExtension
).
AddRange
(
new
[]
{
true
,
false
});
message
.
GetOrRegisterExtension
(
RepeatedBytesExtension
).
AddRange
(
new
[]
{
ByteString
.
CopyFrom
(
1
,
2
,
3
,
4
),
ByteString
.
CopyFrom
(
5
,
6
),
ByteString
.
CopyFrom
(
new
byte
[
1000
])
});
message
.
GetOrRegisterExtension
(
RepeatedDoubleExtension
).
AddRange
(
new
[]
{
-
12.25
,
23.5
});
message
.
GetOrRegisterExtension
(
RepeatedFixed32Extension
).
AddRange
(
new
[]
{
UInt32
.
MaxValue
,
23u
});
message
.
GetOrRegisterExtension
(
RepeatedFixed64Extension
).
AddRange
(
new
[]
{
UInt64
.
MaxValue
,
1234567890123u
l
});
message
.
GetOrRegisterExtension
(
RepeatedFloatExtension
).
AddRange
(
new
[]
{
100f
,
12.25f
});
message
.
GetOrRegisterExtension
(
RepeatedForeignEnumExtension
).
AddRange
(
new
[]
{
Proto2
.
ForeignEnum
.
ForeignFoo
,
Proto2
.
ForeignEnum
.
ForeignBar
});
message
.
GetOrRegisterExtension
(
RepeatedForeignMessageExtension
).
AddRange
(
new
[]
{
new
Proto2
.
ForeignMessage
(),
new
Proto2
.
ForeignMessage
{
C
=
10
}
});
message
.
GetOrRegisterExtension
(
RepeatedImportEnumExtension
).
AddRange
(
new
[]
{
Proto2
.
ImportEnum
.
ImportBaz
,
Proto2
.
ImportEnum
.
ImportFoo
});
message
.
GetOrRegisterExtension
(
RepeatedImportMessageExtension
).
AddRange
(
new
[]
{
new
Proto2
.
ImportMessage
{
D
=
20
},
new
Proto2
.
ImportMessage
{
D
=
25
}
});
message
.
GetOrRegisterExtension
(
RepeatedInt32Extension
).
AddRange
(
new
[]
{
100
,
200
});
message
.
GetOrRegisterExtension
(
RepeatedInt64Extension
).
AddRange
(
new
[]
{
3210987654321
,
Int64
.
MaxValue
});
message
.
GetOrRegisterExtension
(
RepeatedNestedEnumExtension
).
AddRange
(
new
[]
{
Proto2
.
TestAllTypes
.
Types
.
NestedEnum
.
Foo
,
Proto2
.
TestAllTypes
.
Types
.
NestedEnum
.
Neg
});
message
.
GetOrRegisterExtension
(
RepeatedNestedMessageExtension
).
AddRange
(
new
[]
{
new
Proto2
.
TestAllTypes
.
Types
.
NestedMessage
{
Bb
=
35
},
new
Proto2
.
TestAllTypes
.
Types
.
NestedMessage
{
Bb
=
10
}
});
message
.
GetOrRegisterExtension
(
RepeatedSfixed32Extension
).
AddRange
(
new
[]
{
-
123
,
123
});
message
.
GetOrRegisterExtension
(
RepeatedSfixed64Extension
).
AddRange
(
new
[]
{
-
12345678901234
,
12345678901234
});
message
.
GetOrRegisterExtension
(
RepeatedSint32Extension
).
AddRange
(
new
[]
{
-
456
,
100
});
message
.
GetOrRegisterExtension
(
RepeatedSint64Extension
).
AddRange
(
new
[]
{
-
12345678901235
,
123
});
message
.
GetOrRegisterExtension
(
RepeatedStringExtension
).
AddRange
(
new
[]
{
"foo"
,
"bar"
});
message
.
GetOrRegisterExtension
(
RepeatedUint32Extension
).
AddRange
(
new
[]
{
UInt32
.
MaxValue
,
UInt32
.
MinValue
});
message
.
GetOrRegisterExtension
(
RepeatedUint64Extension
).
AddRange
(
new
[]
{
UInt64
.
MaxValue
,
UInt32
.
MinValue
});
message
.
GetOrRegisterExtension
(
RepeatedGroupExtension
).
AddRange
(
new
[]
{
new
Proto2
.
RepeatedGroup_extension
{
A
=
10
},
new
Proto2
.
RepeatedGroup_extension
{
A
=
20
}
});
message
.
SetExtension
(
OneofStringExtension
,
"Oneof string"
);
return
message
;
}
}
}
\ No newline at end of file
csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
View file @
9163a6f1
...
...
@@ -380,7 +380,12 @@ namespace Google.Protobuf.Reflection
}
private
IFieldAccessor
CreateAccessor
()
{
{
if
(
Extension
!=
null
)
{
return
new
ExtensionAccessor
(
this
);
}
// If we're given no property name, that's because we really don't want an accessor.
// This could be because it's a map message, or it could be that we're loading a FileDescriptor dynamically.
// TODO: Support dynamic messages.
...
...
@@ -389,10 +394,6 @@ namespace Google.Protobuf.Reflection
return
null
;
}
if
(
Extension
!=
null
)
{
return
new
ExtensionAccessor
(
this
);
}
var
property
=
ContainingType
.
ClrType
.
GetProperty
(
propertyName
);
if
(
property
==
null
)
{
...
...
csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs
View file @
9163a6f1
...
...
@@ -123,7 +123,7 @@ namespace Google.Protobuf.Reflection
/// the type that declares the method, and the second argument to the first parameter type of the method.
/// </summary>
internal
static
IExtensionReflectionHelper
CreateExtensionHelper
(
Extension
extension
)
=>
(
IExtensionReflectionHelper
)
Activator
.
CreateInstance
(
typeof
(
ExtensionReflectionHelper
<,>).
MakeGenericType
(
extension
.
TargetType
,
extension
.
GetType
().
GenericTypeArguments
[
1
]));
(
IExtensionReflectionHelper
)
Activator
.
CreateInstance
(
typeof
(
ExtensionReflectionHelper
<,>).
MakeGenericType
(
extension
.
TargetType
,
extension
.
GetType
().
GenericTypeArguments
[
1
])
,
extension
);
/// <summary>
/// Creates a reflection helper for the given type arguments. Currently these are created on demand
...
...
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