Exemplo n.º 1
0
 /// <summary>
 /// 是否需要清除数组
 /// </summary>
 /// <param name="type">类型</param>
 /// <returns>需要清除数组</returns>
 public static bool IsClearArray(Type type)
 {
     if (type.IsPointer)
     {
         return(false);
     }
     if (type.IsClass || type.IsInterface)
     {
         return(true);
     }
     if (type.IsEnum)
     {
         return(false);
     }
     if (type.IsValueType)
     {
         bool            isClear;
         hashCode <Type> hashType = type;
         while (Interlocked.CompareExchange(ref isClearArrayLock, 1, 0) != 0)
         {
             Thread.Sleep(1);
         }
         try
         {
             if (isClearArrayCache.TryGetValue(hashType, out isClear))
             {
                 return(isClear);
             }
             isClearArrayCache.Add(hashType, isClear = isClearArray(type));
         }
         finally { isClearArrayLock = 0; }
         return(isClear);
     }
     else
     {
         log.Default.Add(type.fullName(), false, false);
         return(true);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 是否需要清除数组
 /// </summary>
 /// <param name="type">类型</param>
 /// <returns>需要清除数组</returns>
 private static bool isClearArray(Type type)
 {
     foreach (FieldInfo field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
     {
         Type fieldType = field.FieldType;
         if (fieldType != type && !fieldType.IsPointer)
         {
             if (fieldType.IsClass || fieldType.IsInterface)
             {
                 return(true);
             }
             if (!fieldType.IsEnum)
             {
                 if (fieldType.IsValueType)
                 {
                     bool            isClear;
                     hashCode <Type> hashType = fieldType;
                     if (!isClearArrayCache.TryGetValue(hashType, out isClear))
                     {
                         isClearArrayCache.Add(hashType, isClear = isClearArray(fieldType));
                     }
                     if (isClear)
                     {
                         return(true);
                     }
                 }
                 else
                 {
                     log.Default.Add(fieldType.fullName(), false, false);
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Exemplo n.º 3
0
 /// <summary>
 /// 判断是否相等
 /// </summary>
 /// <param name="other">比较对象</param>
 /// <returns>是否相等</returns>
 public bool Equals(hashCode <valueType> other)
 {
     return(hashValue == other.hashValue && value == other.value);
 }