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
fc353381
Commit
fc353381
authored
Oct 14, 2012
by
csharptest
Committed by
rogerk
Oct 14, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored uses of CreateDelegate for compatibility with CF2
parent
1ab73c6a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
16 deletions
+69
-16
TestUtil.cs
src/ProtocolBuffers.Test/TestUtil.cs
+7
-0
ReflectionUtil.cs
src/ProtocolBuffers/FieldAccess/ReflectionUtil.cs
+58
-8
RepeatedPrimitiveAccessor.cs
src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs
+2
-3
SinglePrimitiveAccessor.cs
src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs
+2
-5
No files found.
src/ProtocolBuffers.Test/TestUtil.cs
View file @
fc353381
...
@@ -1823,6 +1823,13 @@ namespace Google.ProtocolBuffers
...
@@ -1823,6 +1823,13 @@ namespace Google.ProtocolBuffers
action
();
action
();
Assert
.
Fail
(
"Exception was not thrown"
);
Assert
.
Fail
(
"Exception was not thrown"
);
}
}
// Not a general case, however, Compact Framework v2 does use Invoke
catch
(
System
.
Reflection
.
TargetInvocationException
te
)
{
if
(
te
.
InnerException
.
GetType
()
!=
typeof
(
ArgumentNullException
))
throw
;
}
// Normally expected exception
catch
(
ArgumentNullException
)
catch
(
ArgumentNullException
)
{
{
// We expect this exception.
// We expect this exception.
...
...
src/ProtocolBuffers/FieldAccess/ReflectionUtil.cs
View file @
fc353381
...
@@ -70,8 +70,7 @@ namespace Google.ProtocolBuffers.FieldAccess
...
@@ -70,8 +70,7 @@ namespace Google.ProtocolBuffers.FieldAccess
{
{
// Convert the reflection call into an open delegate, i.e. instead of calling x.Method()
// Convert the reflection call into an open delegate, i.e. instead of calling x.Method()
// we'll call getter(x).
// we'll call getter(x).
Func
<
TSource
,
TResult
>
getter
=
Func
<
TSource
,
TResult
>
getter
=
ReflectionUtil
.
CreateDelegateFunc
<
TSource
,
TResult
>(
method
);
(
Func
<
TSource
,
TResult
>)
FrameworkPortability
.
CreateDelegate
(
typeof
(
Func
<
TSource
,
TResult
>),
null
,
method
);
// Implicit upcast to object (within the delegate)
// Implicit upcast to object (within the delegate)
return
delegate
(
TSource
source
)
{
return
getter
(
source
);
};
return
delegate
(
TSource
source
)
{
return
getter
(
source
);
};
...
@@ -92,8 +91,7 @@ namespace Google.ProtocolBuffers.FieldAccess
...
@@ -92,8 +91,7 @@ namespace Google.ProtocolBuffers.FieldAccess
{
{
// Convert the reflection call into an open delegate, i.e. instead of calling x.Method(y) we'll
// Convert the reflection call into an open delegate, i.e. instead of calling x.Method(y) we'll
// call Method(x, y)
// call Method(x, y)
Action
<
TSource
,
TParam
>
call
=
Action
<
TSource
,
TParam
>
call
=
ReflectionUtil
.
CreateDelegateAction
<
TSource
,
TParam
>(
method
);
(
Action
<
TSource
,
TParam
>)
FrameworkPortability
.
CreateDelegate
(
typeof
(
Action
<
TSource
,
TParam
>),
null
,
method
);
return
delegate
(
TSource
source
,
object
parameter
)
{
call
(
source
,
(
TParam
)
parameter
);
};
return
delegate
(
TSource
source
,
object
parameter
)
{
call
(
source
,
(
TParam
)
parameter
);
};
}
}
...
@@ -115,9 +113,7 @@ namespace Google.ProtocolBuffers.FieldAccess
...
@@ -115,9 +113,7 @@ namespace Google.ProtocolBuffers.FieldAccess
{
{
// Convert the reflection call into an open delegate, i.e. instead of calling x.Method(y) we'll
// Convert the reflection call into an open delegate, i.e. instead of calling x.Method(y) we'll
// call Method(x, y)
// call Method(x, y)
Func
<
TSource
,
TParam
,
TReturn
>
call
=
(
Func
<
TSource
,
TParam
,
TReturn
>)
Func
<
TSource
,
TParam
,
TReturn
>
call
=
ReflectionUtil
.
CreateDelegateFunc
<
TSource
,
TParam
,
TReturn
>(
method
);
FrameworkPortability
.
CreateDelegate
(
typeof
(
Func
<
TSource
,
TParam
,
TReturn
>),
null
,
method
);
return
delegate
(
TSource
source
,
object
parameter
)
{
call
(
source
,
(
TParam
)
parameter
);
};
return
delegate
(
TSource
source
,
object
parameter
)
{
call
(
source
,
(
TParam
)
parameter
);
};
}
}
...
@@ -134,8 +130,61 @@ namespace Google.ProtocolBuffers.FieldAccess
...
@@ -134,8 +130,61 @@ namespace Google.ProtocolBuffers.FieldAccess
public
static
Func
<
IBuilder
>
CreateStaticUpcastDelegateImpl
<
T
>(
MethodInfo
method
)
public
static
Func
<
IBuilder
>
CreateStaticUpcastDelegateImpl
<
T
>(
MethodInfo
method
)
{
{
Func
<
T
>
call
=
(
Func
<
T
>)
FrameworkPortability
.
CreateDelegate
(
typeof
(
Func
<
T
>),
null
,
method
);
Func
<
T
>
call
=
ReflectionUtil
.
CreateDelegateFunc
<
T
>(
method
);
return
delegate
{
return
(
IBuilder
)
call
();
};
return
delegate
{
return
(
IBuilder
)
call
();
};
}
}
internal
static
Func
<
TResult
>
CreateDelegateFunc
<
TResult
>(
MethodInfo
method
)
{
#if !NOCREATEDELEGATE
object
tdelegate
=
Delegate
.
CreateDelegate
(
typeof
(
Func
<
TResult
>),
null
,
method
,
true
);
return
(
Func
<
TResult
>)
tdelegate
;
#else
return
delegate
()
{
return
(
TResult
)
method
.
Invoke
(
null
,
null
);
};
#endif
}
internal
static
Func
<
T
,
TResult
>
CreateDelegateFunc
<
T
,
TResult
>(
MethodInfo
method
)
{
#if !NOCREATEDELEGATE
object
tdelegate
=
Delegate
.
CreateDelegate
(
typeof
(
Func
<
T
,
TResult
>),
null
,
method
,
true
);
return
(
Func
<
T
,
TResult
>)
tdelegate
;
#else
if
(
method
.
IsStatic
)
{
return
delegate
(
T
arg1
)
{
return
(
TResult
)
method
.
Invoke
(
null
,
new
object
[]
{
arg1
});
};
}
return
delegate
(
T
arg1
)
{
return
(
TResult
)
method
.
Invoke
(
arg1
,
null
);
};
#endif
}
internal
static
Func
<
T1
,
T2
,
TResult
>
CreateDelegateFunc
<
T1
,
T2
,
TResult
>(
MethodInfo
method
)
{
#if !NOCREATEDELEGATE
object
tdelegate
=
Delegate
.
CreateDelegate
(
typeof
(
Func
<
T1
,
T2
,
TResult
>),
null
,
method
,
true
);
return
(
Func
<
T1
,
T2
,
TResult
>)
tdelegate
;
#else
if
(
method
.
IsStatic
)
{
return
delegate
(
T1
arg1
,
T2
arg2
)
{
return
(
TResult
)
method
.
Invoke
(
null
,
new
object
[]
{
arg1
,
arg2
});
};
}
return
delegate
(
T1
arg1
,
T2
arg2
)
{
return
(
TResult
)
method
.
Invoke
(
arg1
,
new
object
[]
{
arg2
});
};
#endif
}
internal
static
Action
<
T1
,
T2
>
CreateDelegateAction
<
T1
,
T2
>(
MethodInfo
method
)
{
#if !NOCREATEDELEGATE
object
tdelegate
=
Delegate
.
CreateDelegate
(
typeof
(
Action
<
T1
,
T2
>),
null
,
method
,
true
);
return
(
Action
<
T1
,
T2
>)
tdelegate
;
#else
if
(
method
.
IsStatic
)
{
return
delegate
(
T1
arg1
,
T2
arg2
)
{
method
.
Invoke
(
null
,
new
object
[]
{
arg1
,
arg2
});
};
}
return
delegate
(
T1
arg1
,
T2
arg2
)
{
method
.
Invoke
(
arg1
,
new
object
[]
{
arg2
});
};
#endif
}
}
}
}
}
\ No newline at end of file
src/ProtocolBuffers/FieldAccess/RepeatedPrimitiveAccessor.cs
View file @
fc353381
...
@@ -84,9 +84,8 @@ namespace Google.ProtocolBuffers.FieldAccess
...
@@ -84,9 +84,8 @@ namespace Google.ProtocolBuffers.FieldAccess
{
{
throw
new
ArgumentException
(
"Not all required properties/methods available"
);
throw
new
ArgumentException
(
"Not all required properties/methods available"
);
}
}
clearDelegate
=
(
Func
<
TBuilder
,
IBuilder
>)
clearDelegate
=
ReflectionUtil
.
CreateDelegateFunc
<
TBuilder
,
IBuilder
>(
clearMethod
);
FrameworkPortability
.
CreateDelegate
(
typeof
(
Func
<
TBuilder
,
IBuilder
>),
null
,
clearMethod
);
countDelegate
=
ReflectionUtil
.
CreateDelegateFunc
<
TMessage
,
int
>(
countProperty
.
GetGetMethod
());
countDelegate
=
(
Func
<
TMessage
,
int
>)
FrameworkPortability
.
CreateDelegate
(
typeof
(
Func
<
TMessage
,
int
>),
null
,
countProperty
.
GetGetMethod
());
getValueDelegate
=
ReflectionUtil
.
CreateUpcastDelegate
<
TMessage
>(
messageProperty
.
GetGetMethod
());
getValueDelegate
=
ReflectionUtil
.
CreateUpcastDelegate
<
TMessage
>(
messageProperty
.
GetGetMethod
());
addValueDelegate
=
ReflectionUtil
.
CreateDowncastDelegateIgnoringReturn
<
TBuilder
>(
addMethod
);
addValueDelegate
=
ReflectionUtil
.
CreateDowncastDelegateIgnoringReturn
<
TBuilder
>(
addMethod
);
getRepeatedWrapperDelegate
=
ReflectionUtil
.
CreateUpcastDelegate
<
TBuilder
>(
builderProperty
.
GetGetMethod
());
getRepeatedWrapperDelegate
=
ReflectionUtil
.
CreateUpcastDelegate
<
TBuilder
>(
builderProperty
.
GetGetMethod
());
...
...
src/ProtocolBuffers/FieldAccess/SinglePrimitiveAccessor.cs
View file @
fc353381
...
@@ -67,11 +67,8 @@ namespace Google.ProtocolBuffers.FieldAccess
...
@@ -67,11 +67,8 @@ namespace Google.ProtocolBuffers.FieldAccess
throw
new
ArgumentException
(
"Not all required properties/methods available"
);
throw
new
ArgumentException
(
"Not all required properties/methods available"
);
}
}
clrType
=
messageProperty
.
PropertyType
;
clrType
=
messageProperty
.
PropertyType
;
hasDelegate
=
hasDelegate
=
ReflectionUtil
.
CreateDelegateFunc
<
TMessage
,
bool
>(
hasProperty
.
GetGetMethod
());
(
Func
<
TMessage
,
bool
>)
clearDelegate
=
ReflectionUtil
.
CreateDelegateFunc
<
TBuilder
,
IBuilder
>(
clearMethod
);
FrameworkPortability
.
CreateDelegate
(
typeof
(
Func
<
TMessage
,
bool
>),
null
,
hasProperty
.
GetGetMethod
());
clearDelegate
=
(
Func
<
TBuilder
,
IBuilder
>)
FrameworkPortability
.
CreateDelegate
(
typeof
(
Func
<
TBuilder
,
IBuilder
>),
null
,
clearMethod
);
getValueDelegate
=
ReflectionUtil
.
CreateUpcastDelegate
<
TMessage
>(
messageProperty
.
GetGetMethod
());
getValueDelegate
=
ReflectionUtil
.
CreateUpcastDelegate
<
TMessage
>(
messageProperty
.
GetGetMethod
());
setValueDelegate
=
ReflectionUtil
.
CreateDowncastDelegate
<
TBuilder
>(
builderProperty
.
GetSetMethod
());
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