BCL接口和beforefieldinit标志

本文关键字:标志 beforefieldinit 接口 BCL | 更新日期: 2023-09-27 18:02:44

我写了一个程序来扫描BCL类型并检查beforefieldinit标志。所以有些接口没有beforefieldinit标志(icollections, IEnumerable),有些接口有。有人知道为什么吗?对什么?

BCL接口和beforefieldinit标志

你说:

所以有些接口有beforefieldinit标志(ICollection, IEnumerable)

无论是反射器还是ildasm都显示不出这个…

例如(通过ildasm):

.class interface public abstract auto ansi System.Collections.IEnumerable
{
  .custom instance void System.Runtime.InteropServices.ComVisibleAttribute::.ctor(bool) = ( 01 00 01 00 00 ) 
  .custom instance void System.Runtime.InteropServices.GuidAttribute::.ctor(string) = ( 01 00 24 34 39 36 42 30 41 42 45 2D 43 44 45 45   // ..$496B0ABE-CDEE
                                                                                        2D 31 31 64 33 2D 38 38 45 38 2D 30 30 39 30 32   // -11d3-88E8-00902
                                                                                        37 35 34 43 34 33 41 00 00 )                      // 754C43A..
} // end of class System.Collections.IEnumerable
.class interface public abstract auto ansi System.Collections.ICollection
       implements System.Collections.IEnumerable
{
  .custom instance void System.Runtime.InteropServices.ComVisibleAttribute::.ctor(bool) = ( 01 00 01 00 00 ) 
} // end of class System.Collections.ICollection
.class interface public abstract auto ansi System.Collections.Generic.IEnumerable`1<+ T>
       implements System.Collections.IEnumerable
{
  .custom instance void System.Runtime.CompilerServices.TypeDependencyAttribute::.ctor(string) = ( 01 00 14 53 79 73 74 65 6D 2E 53 5A 41 72 72 61   // ...System.SZArra
                                                                                                   79 48 65 6C 70 65 72 00 00 )                      // yHelper..
} // end of class System.Collections.Generic.IEnumerable`1
.class interface public abstract auto ansi System.Collections.Generic.ICollection`1<T>
       implements class System.Collections.Generic.IEnumerable`1<!T>,
                  System.Collections.IEnumerable
{
  .custom instance void System.Runtime.CompilerServices.TypeDependencyAttribute::.ctor(string) = ( 01 00 14 53 79 73 74 65 6D 2E 53 5A 41 72 72 61   // ...System.SZArra
                                                                                                   79 48 65 6C 70 65 72 00 00 )                      // yHelper..
} // end of class System.Collections.Generic.ICollection`1

Comparer的对比有这个标志:

.class public auto ansi serializable sealed beforefieldinit System.Collections.Comparer
       extends System.Object
       implements System.Collections.IComparer,
                  System.Runtime.Serialization.ISerializable
{
  .custom instance void System.Runtime.InteropServices.ComVisibleAttribute::.ctor(bool) = ( 01 00 01 00 00 ) 
} // end of class System.Collections.Comparer

I suspect这只是程序中的误报。