@@ -333,7 +333,7 @@ private string[] OwnMethodNames
333333
334334 private string [ ] EnumeratedMethodNames
335335 {
336- get { return engine . EnumerateExtensionMethods ? AllMethodNames : OwnMethodNames ; }
336+ get { return engine . EnumerateInstanceMethods ? ( engine . EnumerateExtensionMethods ? AllMethodNames : OwnMethodNames ) : MiscHelpers . GetEmptyArray < string > ( ) ; }
337337 }
338338
339339 private string [ ] AllPropertyNames
@@ -366,6 +366,12 @@ private PropertyInfo[] AllProperties
366366 set { targetMemberData . AllProperties = value ; }
367367 }
368368
369+ private object EnumerationSettingsToken
370+ {
371+ get { return targetMemberData . EnumerationSettingsToken ; }
372+ set { targetMemberData . EnumerationSettingsToken = value ; }
373+ }
374+
369375 private ExtensionMethodSummary ExtensionMethodSummary
370376 {
371377 get { return targetMemberData . ExtensionMethodSummary ; }
@@ -760,6 +766,20 @@ private void UpdatePropertyNames(out bool updated)
760766 }
761767 }
762768
769+ private void UpdateEnumerationSettingsToken ( out bool updated )
770+ {
771+ var enumerationSettingsToken = engine . EnumerationSettingsToken ;
772+ if ( EnumerationSettingsToken != enumerationSettingsToken )
773+ {
774+ EnumerationSettingsToken = enumerationSettingsToken ;
775+ updated = true ;
776+ }
777+ else
778+ {
779+ updated = false ;
780+ }
781+ }
782+
763783 private void AddExpandoMemberName ( string name )
764784 {
765785 if ( ExpandoMemberNames == null )
@@ -1185,6 +1205,8 @@ private object InvokeHostMember(string name, BindingFlags invokeFlags, object[]
11851205 {
11861206 return target ;
11871207 }
1208+
1209+ return result ;
11881210 }
11891211
11901212 throw new NotSupportedException ( "Object does not support the requested invocation operation" ) ;
@@ -1292,35 +1314,75 @@ private object GetHostProperty(string name, BindingFlags invokeFlags, object[] a
12921314 return GetHostProperty ( defaultProperty , invokeFlags , args , culture ) ;
12931315 }
12941316
1317+ if ( TargetDynamicMetaObject != null )
1318+ {
1319+ object result ;
1320+ if ( TargetDynamicMetaObject . TryGetIndex ( args , out result ) )
1321+ {
1322+ return result ;
1323+ }
1324+ }
1325+
12951326 return Nonexistent . Value ;
12961327 }
12971328
1298- if ( ( TargetDynamicMetaObject != null ) && ( TargetDynamicMetaObject . GetDynamicMemberNames ( ) . Contains ( name ) ) )
1329+ if ( ( TargetDynamicMetaObject != null ) && ( args . Length < 1 ) )
12991330 {
1331+ int index ;
13001332 object result ;
1301- if ( TargetDynamicMetaObject . TryGetMember ( name , out result ) )
1302- {
1303- return result ;
1304- }
13051333
1306- if ( includeBoundMembers )
1334+ if ( TargetDynamicMetaObject . GetDynamicMemberNames ( ) . Contains ( name ) )
13071335 {
1308- if ( HostMethodMap == null )
1336+ if ( TargetDynamicMetaObject . TryGetMember ( name , out result ) )
13091337 {
1310- HostMethodMap = new Dictionary < string , HostMethod > ( ) ;
1338+ return result ;
13111339 }
13121340
1313- HostMethod hostMethod ;
1314- if ( ! HostMethodMap . TryGetValue ( name , out hostMethod ) )
1341+ if ( int . TryParse ( name , NumberStyles . Integer , CultureInfo . InvariantCulture , out index ) )
13151342 {
1316- hostMethod = new HostMethod ( this , name ) ;
1317- HostMethodMap . Add ( name , hostMethod ) ;
1343+ if ( TargetDynamicMetaObject . TryGetIndex ( new object [ ] { index } , out result ) )
1344+ {
1345+ return result ;
1346+ }
13181347 }
13191348
1320- return hostMethod ;
1349+ if ( TargetDynamicMetaObject . TryGetIndex ( new object [ ] { name } , out result ) )
1350+ {
1351+ return result ;
1352+ }
1353+
1354+ if ( includeBoundMembers )
1355+ {
1356+ if ( HostMethodMap == null )
1357+ {
1358+ HostMethodMap = new Dictionary < string , HostMethod > ( ) ;
1359+ }
1360+
1361+ HostMethod hostMethod ;
1362+ if ( ! HostMethodMap . TryGetValue ( name , out hostMethod ) )
1363+ {
1364+ hostMethod = new HostMethod ( this , name ) ;
1365+ HostMethodMap . Add ( name , hostMethod ) ;
1366+ }
1367+
1368+ return hostMethod ;
1369+ }
1370+
1371+ return Nonexistent . Value ;
13211372 }
13221373
1323- return Nonexistent . Value ;
1374+ if ( int . TryParse ( name , NumberStyles . Integer , CultureInfo . InvariantCulture , out index ) )
1375+ {
1376+ if ( TargetDynamicMetaObject . TryGetIndex ( new object [ ] { index } , out result ) )
1377+ {
1378+ return result ;
1379+ }
1380+ }
1381+
1382+ if ( TargetDynamicMetaObject . TryGetIndex ( new object [ ] { name } , out result ) )
1383+ {
1384+ return result ;
1385+ }
13241386 }
13251387
13261388 var property = target . Type . GetScriptableProperty ( name , invokeFlags , bindArgs , defaultAccess ) ;
@@ -1412,15 +1474,29 @@ private object SetHostProperty(string name, BindingFlags invokeFlags, object[] a
14121474 {
14131475 if ( name == SpecialMemberNames . Default )
14141476 {
1477+ if ( args . Length < 2 )
1478+ {
1479+ throw new InvalidOperationException ( "Invalid argument count" ) ;
1480+ }
1481+
1482+ object result ;
1483+
14151484 var defaultProperty = target . Type . GetScriptableDefaultProperty ( invokeFlags , bindArgs . Take ( bindArgs . Length - 1 ) . ToArray ( ) , defaultAccess ) ;
14161485 if ( defaultProperty != null )
14171486 {
14181487 return SetHostProperty ( defaultProperty , invokeFlags , args , culture ) ;
14191488 }
14201489
1490+ if ( TargetDynamicMetaObject != null )
1491+ {
1492+ if ( TargetDynamicMetaObject . TrySetIndex ( args . Take ( args . Length - 1 ) . ToArray ( ) , args [ args . Length - 1 ] , out result ) )
1493+ {
1494+ return result ;
1495+ }
1496+ }
1497+
14211498 // special case to enable JScript/VBScript "x(a) = b" syntax when x is a host indexed property
14221499
1423- object result ;
14241500 if ( InvokeHelpers . TryInvokeObject ( this , target , invokeFlags , args , bindArgs , false , out result ) )
14251501 {
14261502 return result ;
@@ -1432,10 +1508,25 @@ private object SetHostProperty(string name, BindingFlags invokeFlags, object[] a
14321508 if ( ( TargetDynamicMetaObject != null ) && ( args . Length == 1 ) )
14331509 {
14341510 object result ;
1511+
14351512 if ( TargetDynamicMetaObject . TrySetMember ( name , args [ 0 ] , out result ) )
14361513 {
14371514 return result ;
14381515 }
1516+
1517+ int index ;
1518+ if ( int . TryParse ( name , NumberStyles . Integer , CultureInfo . InvariantCulture , out index ) )
1519+ {
1520+ if ( TargetDynamicMetaObject . TrySetIndex ( new object [ ] { index } , args [ 0 ] , out result ) )
1521+ {
1522+ return result ;
1523+ }
1524+ }
1525+
1526+ if ( TargetDynamicMetaObject . TrySetIndex ( new object [ ] { name } , args [ 0 ] , out result ) )
1527+ {
1528+ return result ;
1529+ }
14391530 }
14401531
14411532 if ( args . Length < 1 )
@@ -1790,7 +1881,12 @@ bool IDynamic.DeleteProperty(string name)
17901881 if ( TargetDynamicMetaObject != null )
17911882 {
17921883 bool result ;
1793- if ( TargetDynamicMetaObject . TryDeleteMember ( name , out result ) )
1884+ if ( TargetDynamicMetaObject . TryDeleteMember ( name , out result ) && result )
1885+ {
1886+ return true ;
1887+ }
1888+
1889+ if ( TargetDynamicMetaObject . TryDeleteIndex ( new object [ ] { name } , out result ) )
17941890 {
17951891 return result ;
17961892 }
@@ -1815,7 +1911,10 @@ string[] IDynamic.GetPropertyNames()
18151911 bool updatedPropertyNames ;
18161912 UpdatePropertyNames ( out updatedPropertyNames ) ;
18171913
1818- if ( updatedFieldNames || updatedMethodNames || updatedPropertyNames || ( AllMemberNames == null ) )
1914+ bool updatedEnumerationSettingsToken ;
1915+ UpdateEnumerationSettingsToken ( out updatedEnumerationSettingsToken ) ;
1916+
1917+ if ( updatedFieldNames || updatedMethodNames || updatedPropertyNames || updatedEnumerationSettingsToken || ( AllMemberNames == null ) )
18191918 {
18201919 AllMemberNames = AllFieldNames . Concat ( EnumeratedMethodNames ) . Concat ( AllPropertyNames ) . ExcludeIndices ( ) . Distinct ( ) . ToArray ( ) ;
18211920 }
@@ -1851,7 +1950,13 @@ bool IDynamic.DeleteProperty(int index)
18511950 if ( TargetDynamicMetaObject != null )
18521951 {
18531952 bool result ;
1854- if ( TargetDynamicMetaObject . TryDeleteMember ( index . ToString ( CultureInfo . InvariantCulture ) , out result ) )
1953+
1954+ if ( TargetDynamicMetaObject . TryDeleteMember ( index . ToString ( CultureInfo . InvariantCulture ) , out result ) && result )
1955+ {
1956+ return true ;
1957+ }
1958+
1959+ if ( TargetDynamicMetaObject . TryDeleteIndex ( new object [ ] { index } , out result ) )
18551960 {
18561961 return result ;
18571962 }
@@ -2087,6 +2192,18 @@ void IExpando.RemoveMember(MemberInfo member)
20872192 {
20882193 RemoveExpandoMemberName ( member . Name ) ;
20892194 }
2195+ else
2196+ {
2197+ int index ;
2198+ if ( int . TryParse ( member . Name , NumberStyles . Integer , CultureInfo . InvariantCulture , out index ) && TargetDynamicMetaObject . TryDeleteIndex ( new object [ ] { index } , out result ) )
2199+ {
2200+ RemoveExpandoMemberName ( index . ToString ( CultureInfo . InvariantCulture ) ) ;
2201+ }
2202+ else if ( TargetDynamicMetaObject . TryDeleteIndex ( new object [ ] { member . Name } , out result ) )
2203+ {
2204+ RemoveExpandoMemberName ( member . Name ) ;
2205+ }
2206+ }
20902207 }
20912208 else
20922209 {
0 commit comments