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
6e1ec5f6
Commit
6e1ec5f6
authored
May 01, 2015
by
Jie Luo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix commends from Jon Skeet
parent
24ae5105
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
62 additions
and
48 deletions
+62
-48
AddressBook.csproj
csharp/src/AddressBook/AddressBook.csproj
+20
-0
app.config
csharp/src/AddressBook/app.config
+12
-3
FieldPresenceTest.cs
csharp/src/ProtocolBuffers.Test/FieldPresenceTest.cs
+21
-25
FieldPresence.cs
csharp/src/ProtocolBuffers.Test/TestProtos/FieldPresence.cs
+0
-0
FileDescriptor.cs
csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs
+3
-8
FieldAccessorTable.cs
csharp/src/ProtocolBuffers/FieldAccess/FieldAccessorTable.cs
+1
-5
SinglePrimitiveAccessor.cs
...rc/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs
+5
-7
No files found.
csharp/src/AddressBook/AddressBook.csproj
View file @
6e1ec5f6
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"4.0"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<Import
Project=
"..\packages\xunit.runner.visualstudio.2.1.0-beta1-build1051\build\net20\xunit.runner.visualstudio.props"
Condition=
"Exists('..\packages\xunit.runner.visualstudio.2.1.0-beta1-build1051\build\net20\xunit.runner.visualstudio.props')"
/>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
...
...
@@ -14,6 +15,8 @@
<FileAlignment>
512
</FileAlignment>
<StartupObject>
Google.ProtocolBuffers.Examples.AddressBook.Program
</StartupObject>
<TargetFrameworkProfile>
Client
</TargetFrameworkProfile>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<DebugSymbols>
true
</DebugSymbols>
...
...
@@ -45,6 +48,14 @@
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Xml"
/>
<Reference
Include=
"xunit, Version=1.9.2.1705, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"
>
<HintPath>
..\packages\xunit.1.9.2\lib\net20\xunit.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"xunit.should, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"
>
<HintPath>
..\packages\xunit.should.1.1\lib\net35\xunit.should.dll
</HintPath>
<Private>
True
</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"AddPerson.cs"
/>
...
...
@@ -62,8 +73,17 @@
</ItemGroup>
<ItemGroup>
<None
Include=
"app.config"
/>
<None
Include=
"packages.config"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Target
Name=
"EnsureNuGetPackageBuildImports"
BeforeTargets=
"PrepareForBuild"
>
<PropertyGroup>
<ErrorText>
This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
</ErrorText>
</PropertyGroup>
<Error
Condition=
"!Exists('..\packages\xunit.runner.visualstudio.2.1.0-beta1-build1051\build\net20\xunit.runner.visualstudio.props')"
Text=
"$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.1.0-beta1-build1051\build\net20\xunit.runner.visualstudio.props'))"
/>
<Error
Condition=
"!Exists('..\packages\xunit.MSBuild.1.9.2.3\build\xunit.MSBuild.targets')"
Text=
"$([System.String]::Format('$(ErrorText)', '..\packages\xunit.MSBuild.1.9.2.3\build\xunit.MSBuild.targets'))"
/>
</Target>
<Import
Project=
"..\packages\xunit.MSBuild.1.9.2.3\build\xunit.MSBuild.targets"
Condition=
"Exists('..\packages\xunit.MSBuild.1.9.2.3\build\xunit.MSBuild.targets')"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
...
...
csharp/src/AddressBook/app.config
View file @
6e1ec5f6
<?
xml
version
=
"1.0"
?>
<
configuration
>
<
startup
><
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.0,Profile=Client"
/></
startup
></
configuration
>
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
configuration
>
<
startup
><
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.0,Profile=Client"
/></
startup
>
<
runtime
>
<
assemblyBinding
xmlns
=
"urn:schemas-microsoft-com:asm.v1"
>
<
dependentAssembly
>
<
assemblyIdentity
name
=
"xunit"
publicKeyToken
=
"8d05b1bb7a6fdb6c"
culture
=
"neutral"
/>
<
bindingRedirect
oldVersion
=
"0.0.0.0-1.9.2.1705"
newVersion
=
"1.9.2.1705"
/>
</
dependentAssembly
>
</
assemblyBinding
>
</
runtime
>
</
configuration
>
csharp/src/ProtocolBuffers.Test/FieldPresenceTest.cs
View file @
6e1ec5f6
...
...
@@ -32,16 +32,13 @@
#endregion
using
System
;
using
System.Reflection
;
using
System.Collections.Generic
;
using
Google.ProtocolBuffers.Descriptors
;
using
Google.ProtocolBuffers.TestProtos.FieldPresence
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Xunit
;
namespace
Google.ProtocolBuffers
{
[
TestClass
]
class
FieldPresenceTest
public
class
FieldPresenceTest
{
private
void
CheckHasMethodRemoved
(
Type
proto2Type
,
Type
proto3Type
,
string
name
)
{
...
...
@@ -51,7 +48,7 @@ namespace Google.ProtocolBuffers
Assert
.
Null
(
proto3Type
.
GetProperty
(
"Has"
+
name
));
}
[
TestMethod
]
[
Fact
]
public
void
TestHasMethod
()
{
// Optional non-message fields don't have HasFoo method generated
...
...
@@ -74,7 +71,7 @@ namespace Google.ProtocolBuffers
Assert
.
False
(
TestAllTypes
.
CreateBuilder
().
HasOptionalNestedMessage
);
}
[
TestMethod
]
[
Fact
]
public
void
TestFieldPresence
()
{
// Optional non-message fields set to their default value are treated the same
...
...
@@ -87,7 +84,7 @@ namespace Google.ProtocolBuffers
builder
.
SetOptionalBytes
(
ByteString
.
Empty
);
builder
.
SetOptionalNestedEnum
(
TestAllTypes
.
Types
.
NestedEnum
.
FOO
);
TestAllTypes
message
=
builder
.
Build
();
Assert
.
Are
Equal
(
0
,
message
.
SerializedSize
);
Assert
.
Equal
(
0
,
message
.
SerializedSize
);
// Test merge
TestAllTypes
.
Builder
a
=
TestAllTypes
.
CreateBuilder
();
...
...
@@ -97,19 +94,19 @@ namespace Google.ProtocolBuffers
a
.
SetOptionalNestedEnum
(
TestAllTypes
.
Types
.
NestedEnum
.
BAR
);
a
.
MergeFrom
(
message
);
TestAllTypes
messageA
=
a
.
Build
();
Assert
.
Are
Equal
(
1
,
messageA
.
OptionalInt32
);
Assert
.
Are
Equal
(
"x"
,
messageA
.
OptionalString
);
Assert
.
Are
Equal
(
ByteString
.
CopyFromUtf8
(
"y"
),
messageA
.
OptionalBytes
);
Assert
.
Are
Equal
(
TestAllTypes
.
Types
.
NestedEnum
.
BAR
,
messageA
.
OptionalNestedEnum
);
Assert
.
Equal
(
1
,
messageA
.
OptionalInt32
);
Assert
.
Equal
(
"x"
,
messageA
.
OptionalString
);
Assert
.
Equal
(
ByteString
.
CopyFromUtf8
(
"y"
),
messageA
.
OptionalBytes
);
Assert
.
Equal
(
TestAllTypes
.
Types
.
NestedEnum
.
BAR
,
messageA
.
OptionalNestedEnum
);
// equals/hashCode should produce the same results
TestAllTypes
empty
=
TestAllTypes
.
CreateBuilder
().
Build
();
Assert
.
True
(
empty
.
Equals
(
message
));
Assert
.
True
(
message
.
Equals
(
empty
));
Assert
.
Are
Equal
(
empty
.
GetHashCode
(),
message
.
GetHashCode
());
Assert
.
Equal
(
empty
.
GetHashCode
(),
message
.
GetHashCode
());
}
[
TestMethod
]
[
Fact
]
public
void
TestFieldPresenceReflection
()
{
MessageDescriptor
descriptor
=
TestAllTypes
.
Descriptor
;
...
...
@@ -135,7 +132,7 @@ namespace Google.ProtocolBuffers
Assert
.
False
(
message
.
HasField
(
optionalStringField
));
Assert
.
False
(
message
.
HasField
(
optionalBytesField
));
Assert
.
False
(
message
.
HasField
(
optionalNestedEnumField
));
Assert
.
Are
Equal
(
0
,
message
.
AllFields
.
Count
);
Assert
.
Equal
(
0
,
message
.
AllFields
.
Count
);
// Set t0 non-defalut value is seen as present
message
=
TestAllTypes
.
CreateBuilder
()
...
...
@@ -148,10 +145,10 @@ namespace Google.ProtocolBuffers
Assert
.
True
(
message
.
HasField
(
optionalStringField
));
Assert
.
True
(
message
.
HasField
(
optionalBytesField
));
Assert
.
True
(
message
.
HasField
(
optionalNestedEnumField
));
Assert
.
Are
Equal
(
4
,
message
.
AllFields
.
Count
);
Assert
.
Equal
(
4
,
message
.
AllFields
.
Count
);
}
[
TestMethod
]
[
Fact
]
public
void
TestMessageField
()
{
TestAllTypes
.
Builder
builder
=
TestAllTypes
.
CreateBuilder
();
...
...
@@ -163,11 +160,10 @@ namespace Google.ProtocolBuffers
builder
.
SetOptionalNestedMessage
(
TestAllTypes
.
Types
.
NestedMessage
.
DefaultInstance
);
Assert
.
True
(
builder
.
HasOptionalNestedMessage
);
Assert
.
True
(
builder
.
Build
().
HasOptionalNestedMessage
);
}
[
TestMethod
]
public
void
TestSeralizeAndPar
e
se
()
[
Fact
]
public
void
TestSeralizeAndParse
()
{
TestAllTypes
.
Builder
builder
=
TestAllTypes
.
CreateBuilder
();
builder
.
SetOptionalInt32
(
1234
);
...
...
@@ -176,12 +172,12 @@ namespace Google.ProtocolBuffers
ByteString
data
=
builder
.
Build
().
ToByteString
();
TestAllTypes
message
=
TestAllTypes
.
ParseFrom
(
data
);
Assert
.
Are
Equal
(
1234
,
message
.
OptionalInt32
);
Assert
.
Are
Equal
(
"hello"
,
message
.
OptionalString
);
Assert
.
Are
Equal
(
ByteString
.
Empty
,
message
.
OptionalBytes
);
Assert
.
Are
Equal
(
TestAllTypes
.
Types
.
NestedEnum
.
FOO
,
message
.
OptionalNestedEnum
);
Assert
.
Equal
(
1234
,
message
.
OptionalInt32
);
Assert
.
Equal
(
"hello"
,
message
.
OptionalString
);
Assert
.
Equal
(
ByteString
.
Empty
,
message
.
OptionalBytes
);
Assert
.
Equal
(
TestAllTypes
.
Types
.
NestedEnum
.
FOO
,
message
.
OptionalNestedEnum
);
Assert
.
True
(
message
.
HasOptionalNestedMessage
);
Assert
.
Are
Equal
(
0
,
message
.
OptionalNestedMessage
.
Value
);
Assert
.
Equal
(
0
,
message
.
OptionalNestedMessage
.
Value
);
}
}
}
csharp/src/ProtocolBuffers.Test/TestProtos/FieldPresen
s
e.cs
→
csharp/src/ProtocolBuffers.Test/TestProtos/FieldPresen
c
e.cs
View file @
6e1ec5f6
File moved
csharp/src/ProtocolBuffers/Descriptors/FileDescriptor.cs
View file @
6e1ec5f6
...
...
@@ -54,20 +54,15 @@ namespace Google.ProtocolBuffers.Descriptors
private
readonly
IList
<
FileDescriptor
>
publicDependencies
;
private
readonly
DescriptorPool
pool
;
public
enum
Syntax
public
enum
Proto
Syntax
{
UNKNOWN
,
PROTO2
,
PROTO3
}
public
Syntax
GetSyntax
()
public
ProtoSyntax
Syntax
{
if
(
proto
.
Syntax
==
"proto3"
)
{
return
Syntax
.
PROTO3
;
}
return
Syntax
.
PROTO2
;
get
{
return
proto
.
Syntax
==
"proto3"
?
ProtoSyntax
.
PROTO3
:
ProtoSyntax
.
PROTO2
;
}
}
private
FileDescriptor
(
FileDescriptorProto
proto
,
FileDescriptor
[]
dependencies
,
DescriptorPool
pool
,
bool
allowUnknownDependencies
)
...
...
csharp/src/ProtocolBuffers/FieldAccess/FieldAccessorTable.cs
View file @
6e1ec5f6
...
...
@@ -68,11 +68,7 @@ namespace Google.ProtocolBuffers.FieldAccess
{
this
.
descriptor
=
descriptor
;
accessors
=
new
IFieldAccessor
<
TMessage
,
TBuilder
>[
descriptor
.
Fields
.
Count
];
bool
supportFieldPresence
=
false
;
if
(
descriptor
.
File
.
GetSyntax
()
==
FileDescriptor
.
Syntax
.
PROTO2
)
{
supportFieldPresence
=
true
;
}
bool
supportFieldPresence
=
descriptor
.
File
.
Syntax
==
FileDescriptor
.
ProtoSyntax
.
PROTO2
;
for
(
int
i
=
0
;
i
<
accessors
.
Length
;
i
++)
{
accessors
[
i
]
=
CreateAccessor
(
descriptor
.
Fields
[
i
],
propertyNames
[
i
],
supportFieldPresence
);
...
...
csharp/src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs
View file @
6e1ec5f6
...
...
@@ -58,9 +58,8 @@ namespace Google.ProtocolBuffers.FieldAccess
get
{
return
clrType
;
}
}
internal
SinglePrimitiveAccessor
(
FieldDescriptor
fieldDesriptor
,
string
name
,
bool
supportFieldPresence
)
internal
SinglePrimitiveAccessor
(
FieldDescriptor
fieldDes
c
riptor
,
string
name
,
bool
supportFieldPresence
)
{
field
=
fieldDesriptor
;
PropertyInfo
messageProperty
=
typeof
(
TMessage
).
GetProperty
(
name
,
null
,
ReflectionUtil
.
EmptyTypes
);
PropertyInfo
builderProperty
=
typeof
(
TBuilder
).
GetProperty
(
name
,
null
,
ReflectionUtil
.
EmptyTypes
);
MethodInfo
clearMethod
=
typeof
(
TBuilder
).
GetMethod
(
"Clear"
+
name
);
...
...
@@ -77,8 +76,11 @@ namespace Google.ProtocolBuffers.FieldAccess
throw
new
ArgumentException
(
"Has properties not available"
);
}
hasDelegate
=
ReflectionUtil
.
CreateDelegateFunc
<
TMessage
,
bool
>(
hasProperty
.
GetGetMethod
());
}
else
{
hasDelegate
=
message
=>
!
GetValue
(
message
).
Equals
(
fieldDescriptor
.
DefaultValue
);
}
clrType
=
messageProperty
.
PropertyType
;
clearDelegate
=
ReflectionUtil
.
CreateDelegateFunc
<
TBuilder
,
IBuilder
>(
clearMethod
);
getValueDelegate
=
ReflectionUtil
.
CreateUpcastDelegate
<
TMessage
>(
messageProperty
.
GetGetMethod
());
...
...
@@ -87,10 +89,6 @@ namespace Google.ProtocolBuffers.FieldAccess
public
bool
Has
(
TMessage
message
)
{
if
(
hasDelegate
==
null
)
{
return
!
GetValue
(
message
).
Equals
(
field
.
DefaultValue
);
}
return
hasDelegate
(
message
);
}
...
...
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