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
9f787cc6
Commit
9f787cc6
authored
Oct 15, 2012
by
csharptest
Committed by
rogerk
Oct 15, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed uses of reflection for enumeration of enum members
parent
efc90f40
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
30 deletions
+8
-30
EnumLite.cs
src/ProtocolBuffers/EnumLite.cs
+8
-30
No files found.
src/ProtocolBuffers/EnumLite.cs
View file @
9f787cc6
...
...
@@ -93,51 +93,28 @@ namespace Google.ProtocolBuffers
}
}
private
readonly
SortedList
<
int
,
IEnumLite
>
items
;
public
EnumLiteMap
()
public
IEnumLite
FindValueByNumber
(
int
number
)
{
items
=
new
SortedList
<
int
,
IEnumLite
>();
#if SILVERLIGHT || COMPACT_FRAMEWORK
// Silverlight doesn't support Enum.GetValues
// TODO(jonskeet): Validate that this reflection is permitted, e.g. in Windows Phone 7
foreach
(
System
.
Reflection
.
FieldInfo
fi
in
typeof
(
TEnum
).
GetFields
(
System
.
Reflection
.
BindingFlags
.
Static
|
System
.
Reflection
.
BindingFlags
.
Public
))
{
TEnum
evalue
=
(
TEnum
)
fi
.
GetValue
(
null
);
items
.
Add
(
Convert
.
ToInt32
(
evalue
),
new
EnumValue
(
evalue
));
}
#else
foreach
(
TEnum
evalue
in
Enum
.
GetValues
(
typeof
(
TEnum
)))
if
(
Enum
.
IsDefined
(
typeof
(
TEnum
),
number
))
{
items
.
Add
(
Convert
.
ToInt32
(
evalue
),
new
EnumValue
(
evalue
)
);
return
new
EnumValue
((
TEnum
)(
object
)
number
);
}
#endif
}
IEnumLite
IEnumLiteMap
.
FindValueByNumber
(
int
number
)
{
return
FindValueByNumber
(
number
);
}
public
IEnumLite
FindValueByNumber
(
int
number
)
{
IEnumLite
val
;
return
items
.
TryGetValue
(
number
,
out
val
)
?
val
:
null
;
return
null
;
}
public
IEnumLite
FindValueByName
(
string
name
)
{
IEnumLite
val
;
if
(
Enum
.
IsDefined
(
typeof
(
TEnum
),
name
))
{
return
items
.
TryGetValue
((
int
)
Enum
.
Parse
(
typeof
(
TEnum
),
name
,
false
),
out
val
)
?
val
:
null
;
object
evalue
=
Enum
.
Parse
(
typeof
(
TEnum
),
name
,
false
);
return
new
EnumValue
((
TEnum
)
evalue
);
}
return
null
;
}
public
bool
IsValidValue
(
IEnumLite
value
)
{
return
items
.
ContainsKey
(
value
.
Number
);
return
Enum
.
IsDefined
(
typeof
(
TEnum
),
value
.
Number
);
}
}
}
\ No newline at end of file
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