@@ -71,9 +71,6 @@ protected static Dictionary<string, string> GetBindingData(object value, IBinder
71
71
{
72
72
Dictionary < string , string > bindingData = new Dictionary < string , string > ( ) ;
73
73
74
- // first apply any existing binding data
75
- ApplyAmbientBindingData ( binder , bindingData ) ;
76
-
77
74
// If there are any parameters in the bindings,
78
75
// get the binding data. In dynamic script cases we need
79
76
// to parse this POCO data ourselves - it won't be in the existing
@@ -82,6 +79,9 @@ protected static Dictionary<string, string> GetBindingData(object value, IBinder
82
79
if ( outputBindings . Any ( p => p . HasBindingParameters ) ||
83
80
inputBindings . Any ( p => p . HasBindingParameters ) )
84
81
{
82
+ // first apply any existing binding data
83
+ ApplyAmbientBindingData ( binder , bindingData ) ;
84
+
85
85
try
86
86
{
87
87
string json = value as string ;
@@ -115,24 +115,43 @@ protected static Dictionary<string, string> GetBindingData(object value, IBinder
115
115
/// </summary>
116
116
protected static void ApplyAmbientBindingData ( IBinder binder , IDictionary < string , string > bindingData )
117
117
{
118
- // TEMP: Dig the ambient binding data out of the binder
119
- FieldInfo fieldInfo = binder . GetType ( ) . GetField ( "_bindingSource" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
120
- var bindingSource = fieldInfo . GetValue ( binder ) ;
121
- PropertyInfo propertyInfo = bindingSource . GetType ( ) . GetProperty ( "AmbientBindingContext" ) ;
122
- var ambientBindingContext = propertyInfo . GetValue ( bindingSource ) ;
123
- propertyInfo = ambientBindingContext . GetType ( ) . GetProperty ( "BindingData" ) ;
124
- IDictionary < string , object > ambientBindingData = ( IDictionary < string , object > ) propertyInfo . GetValue ( ambientBindingContext ) ;
125
-
118
+ var ambientBindingData = GetAmbientBindingData ( binder ) ;
126
119
if ( ambientBindingData != null )
127
120
{
128
121
// apply the binding data to ours
129
122
foreach ( var item in ambientBindingData )
130
123
{
131
- bindingData [ item . Key ] = item . Value . ToString ( ) ;
124
+ if ( item . Value != null )
125
+ {
126
+ bindingData [ item . Key ] = item . Value . ToString ( ) ;
127
+ }
132
128
}
133
129
}
134
130
}
135
131
132
+ private static IDictionary < string , object > GetAmbientBindingData ( IBinder binder )
133
+ {
134
+ IDictionary < string , object > ambientBindingData = null ;
135
+
136
+ try
137
+ {
138
+ // TEMP: Dig the ambient binding data out of the binder
139
+ FieldInfo fieldInfo = binder . GetType ( ) . GetField ( "_bindingSource" , BindingFlags . NonPublic | BindingFlags . Instance ) ;
140
+ var bindingSource = fieldInfo . GetValue ( binder ) ;
141
+ PropertyInfo propertyInfo = bindingSource . GetType ( ) . GetProperty ( "AmbientBindingContext" ) ;
142
+ var ambientBindingContext = propertyInfo . GetValue ( bindingSource ) ;
143
+ propertyInfo = ambientBindingContext . GetType ( ) . GetProperty ( "BindingData" ) ;
144
+ ambientBindingData = ( IDictionary < string , object > ) propertyInfo . GetValue ( ambientBindingContext ) ;
145
+ }
146
+ catch
147
+ {
148
+ // If this fails for whatever reason we just won't
149
+ // have any binding data
150
+ }
151
+
152
+ return ambientBindingData ;
153
+ }
154
+
136
155
protected static bool IsJson ( string input )
137
156
{
138
157
input = input . Trim ( ) ;
0 commit comments