Ticket #368: DynamicArrayIndex.patch
File DynamicArrayIndex.patch, 1.0 KB (added by hopscc, 11 years ago) |
---|
-
Source/Cobra.Core/Native.cs
1038 1038 var pi = type.GetProperty("Item", PropertyFlags); 1039 1039 if (pi != null) { 1040 1040 return pi.GetValue(obj, args); 1041 } else {1042 throw new UnknownMemberException(obj, "[]", type);1043 1041 } 1042 // try as an array 1043 if (type.IsArray) { 1044 var arr = obj as System.Array; 1045 if (arr != null) { 1046 var rank = arr.Rank; 1047 var idx = Convert.ToInt32(args[0]); 1048 if (rank == 1) { 1049 return arr.GetValue(idx); 1050 } else { 1051 throw new DynamicOperationException("Cannot dynamically index arrays other than rank 1."); 1052 } 1053 } 1054 } 1055 throw new UnknownMemberException(obj, "[]", type); 1044 1056 } 1045 1057 1046 1058 static public object SetIndexerValue(Object obj, Object value, params object[] args) {