@@ -71,9 +71,6 @@ protected static Dictionary<string, string> GetBindingData(object value, IBinder
7171 {
7272 Dictionary < string , string > bindingData = new Dictionary < string , string > ( ) ;
7373
74- // first apply any existing binding data
75- ApplyAmbientBindingData ( binder , bindingData ) ;
76-
7774 // If there are any parameters in the bindings,
7875 // get the binding data. In dynamic script cases we need
7976 // 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
8279 if ( outputBindings . Any ( p => p . HasBindingParameters ) ||
8380 inputBindings . Any ( p => p . HasBindingParameters ) )
8481 {
82+ // first apply any existing binding data
83+ ApplyAmbientBindingData ( binder , bindingData ) ;
84+
8585 try
8686 {
8787 string json = value as string ;
@@ -115,24 +115,43 @@ protected static Dictionary<string, string> GetBindingData(object value, IBinder
115115 /// </summary>
116116 protected static void ApplyAmbientBindingData ( IBinder binder , IDictionary < string , string > bindingData )
117117 {
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 ) ;
126119 if ( ambientBindingData != null )
127120 {
128121 // apply the binding data to ours
129122 foreach ( var item in ambientBindingData )
130123 {
131- bindingData [ item . Key ] = item . Value . ToString ( ) ;
124+ if ( item . Value != null )
125+ {
126+ bindingData [ item . Key ] = item . Value . ToString ( ) ;
127+ }
132128 }
133129 }
134130 }
135131
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+
136155 protected static bool IsJson ( string input )
137156 {
138157 input = input . Trim ( ) ;
0 commit comments