Example #1
0
 /// <summary>
 /// Might the given type be, or contain, managed references?  This is used to determine which
 /// fields allocated to temporaries should be cleared when the underlying variable goes out of scope, so
 /// that they do not cause unnecessary object retention.
 /// </summary>
 private bool MightContainReferences(TypeSymbol type)
 {
     if (type.IsReferenceType || type.TypeKind == TypeKind.TypeParameter)
     {
         return(true);                                                                 // type parameter or reference type
     }
     if (type.TypeKind != TypeKind.Struct)
     {
         return(false);                                  // enums, etc
     }
     if (type.SpecialType == SpecialType.System_TypedReference)
     {
         return(true);
     }
     if (type.SpecialType != SpecialType.None)
     {
         return(false);                                      // int, etc
     }
     if (!type.IsFromCompilation(this.CompilationState.ModuleBuilderOpt.Compilation))
     {
         return(true);                                                                             // perhaps from ref assembly
     }
     foreach (var f in _emptyStructTypeCache.GetStructInstanceFields(type))
     {
         if (MightContainReferences(f.Type))
         {
             return(true);
         }
     }
     return(false);
 }
 /// <summary>
 /// Might the given type be, or contain, managed references?  This is used to determine which
 /// fields allocated to temporaries should be cleared when the underlying variable goes out of scope, so
 /// that they do not cause unnecessary object retention.
 /// </summary>
 private bool MightContainReferences(TypeSymbol type)
 {
     if (type.IsReferenceType || type.TypeKind == TypeKind.TypeParameter) return true; // type parameter or reference type
     if (type.TypeKind != TypeKind.Struct) return false; // enums, etc
     if (type.SpecialType == SpecialType.System_TypedReference) return true;
     if (type.SpecialType != SpecialType.None) return false; // int, etc
     if (!type.IsFromCompilation(this.CompilationState.ModuleBuilderOpt.Compilation)) return true; // perhaps from ref assembly
     foreach (var f in _emptyStructTypeCache.GetStructInstanceFields(type))
     {
         if (MightContainReferences(f.Type)) return true;
     }
     return false;
 }