Exemple #1
0
 internal static int GetId(RuntimeTypeHandle typeHandle)
 {
     lock (s_cacheLock)
     {
         IntRef id;
         s_typeHandleRef.Value = typeHandle;
         if (!s_typeToIDCache.TryGetValue(s_typeHandleRef, out id))
         {
             int value = s_dataContractID++;
             if (value >= s_dataContractCache.Length)
             {
                 int newSize = (value < Int32.MaxValue / 2) ? value * 2 : Int32.MaxValue;
                 if (newSize <= value)
                 {
                     Fx.Assert("DataContract cache overflow");
                     throw new SerializationException(SR.DataContractCacheOverflow);
                 }
                 Array.Resize<JsonDataContract>(ref s_dataContractCache, newSize);
             }
             id = new IntRef(value);
             try
             {
                 s_typeToIDCache.Add(new TypeHandleRef(typeHandle), id);
             }
             catch (Exception ex)
             {
                 if (DiagnosticUtility.IsFatal(ex))
                 {
                     throw;
                 }
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperFatal(ex.Message, ex);
             }
         }
         return id.Value;
     }
 }
 internal static int GetId(RuntimeTypeHandle typeHandle)
 {
     lock (cacheLock)
     {
         IntRef ref2;
         typeHandleRef.Value = typeHandle;
         if (!typeToIDCache.TryGetValue(typeHandleRef, out ref2))
         {
             int num = dataContractID++;
             if (num >= dataContractCache.Length)
             {
                 int newSize = (num < 0x3fffffff) ? (num * 2) : 0x7fffffff;
                 if (newSize <= num)
                 {
                     throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SerializationException(System.Runtime.Serialization.SR.GetString("DataContractCacheOverflow")));
                 }
                 Array.Resize<JsonDataContract>(ref dataContractCache, newSize);
             }
             ref2 = new IntRef(num);
             try
             {
                 typeToIDCache.Add(new TypeHandleRef(typeHandle), ref2);
             }
             catch (Exception exception)
             {
                 if (Fx.IsFatal(exception))
                 {
                     throw;
                 }
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperFatal(exception.Message, exception);
             }
         }
         return ref2.Value;
     }
 }