@@ -398,6 +398,7 @@ internal static readonly Type
398398 _enumeratorType = typeof ( IEnumerator < > ) ,
399399 _genericKeyValuePairType = typeof ( KeyValuePair < , > ) ,
400400 _invalidJSONExceptionType = typeof ( NetJSONInvalidJSONException ) ,
401+ _typeMismatchExceptionType = typeof ( NetJSONTypeMismatchException ) ,
401402 _serializerType = typeof ( NetJSONSerializer < > ) ,
402403 _expandoObjectType = typeof ( ExpandoObject ) ,
403404 _genericDictionaryEnumerator = typeof ( Dictionary < , > . Enumerator ) ,
@@ -550,6 +551,7 @@ internal static readonly Type
550551
551552 static ConstructorInfo _strCtorWithPtr = _stringType . GetConstructor ( new [ ] { typeof ( char * ) , _intType , _intType } ) ;
552553 static ConstructorInfo _invalidJSONCtor = _invalidJSONExceptionType . GetConstructor ( Type . EmptyTypes ) ;
554+ static ConstructorInfo _typeMismatchExceptionCtor = _typeMismatchExceptionType . GetConstructor ( Type . EmptyTypes ) ;
553555 static ConstructorInfo _settingsCtor = _settingsType . GetConstructor ( Type . EmptyTypes ) ;
554556
555557 private static ConcurrentDictionary < string , object > _dictLockObjects = new ConcurrentDictionary < string , object > ( ) ;
@@ -4807,6 +4809,9 @@ private static MethodInfo GenerateGetClassOrDictFor(TypeBuilder typeBuilder, Typ
48074809
48084810 var countLabel = il . DefineLabel ( ) ;
48094811 var isNullObjectLabel = il . DefineLabel ( ) ;
4812+ var isNotDictOrClass = il . DefineLabel ( ) ;
4813+
4814+ var isNotDictOrClassStartChar = il . DefineLabel ( ) ;
48104815
48114816
48124817 var isDict = type . IsDictionaryType ( ) ;
@@ -4974,6 +4979,37 @@ private static MethodInfo GenerateGetClassOrDictFor(TypeBuilder typeBuilder, Typ
49744979 il . Emit ( OpCodes . Ldc_I4_0 ) ;
49754980 il . Emit ( OpCodes . Stloc , isTag ) ;
49764981
4982+ //if current != '{' throw exception
4983+ il . Emit ( OpCodes . Ldc_I4_0 ) ;
4984+ il . Emit ( OpCodes . Ldloc , count ) ;
4985+ il . Emit ( OpCodes . Bne_Un , isNotDictOrClass ) ;
4986+
4987+ il . Emit ( OpCodes . Ldc_I4 , ( int ) '{' ) ;
4988+ il . Emit ( OpCodes . Ldloc , current ) ;
4989+ il . Emit ( OpCodes . Beq , isNotDictOrClass ) ;
4990+
4991+
4992+ // ignore whitespace and ":"
4993+ il . Emit ( OpCodes . Ldc_I4 , ( int ) ' ' ) ;
4994+ il . Emit ( OpCodes . Ldloc , current ) ;
4995+ il . Emit ( OpCodes . Beq , isNotDictOrClassStartChar ) ;
4996+
4997+ il . Emit ( OpCodes . Ldc_I4 , ( int ) ':' ) ;
4998+ il . Emit ( OpCodes . Ldloc , current ) ;
4999+ il . Emit ( OpCodes . Beq , isNotDictOrClassStartChar ) ;
5000+
5001+ il . Emit ( OpCodes . Ldc_I4 , ( int ) 'n' ) ;
5002+ il . Emit ( OpCodes . Ldloc , current ) ;
5003+ il . Emit ( OpCodes . Beq , isNotDictOrClassStartChar ) ;
5004+
5005+ il . Emit ( OpCodes . Newobj , _typeMismatchExceptionCtor ) ;
5006+ il . Emit ( OpCodes . Throw ) ;
5007+
5008+ il . MarkLabel ( isNotDictOrClassStartChar ) ;
5009+
5010+ il . MarkLabel ( isNotDictOrClass ) ;
5011+
5012+
49775013 //if (count == 0 && current == 'n') {
49785014 // index += 3;
49795015 // return null;
0 commit comments