private void SerializeNamespaceScopeMetadata(IMethodBody methodBody, ArrayBuilder <MemoryStream> customDebugInfo) { if (ShouldForwardToPreviousMethodWithUsingInfo(methodBody)) { Debug.Assert(!ReferenceEquals(this.previousMethodBodyWithUsingInfo, methodBody)); SerializeReferenceToPreviousMethodWithUsingInfo(customDebugInfo); return; } MemoryStream customMetadata = new MemoryStream(); List <ushort> usingCounts = new List <ushort>(); BinaryWriter cmw = new BinaryWriter(customMetadata); foreach (NamespaceScope namespaceScope in methodBody.NamespaceScopes) { usingCounts.Add((ushort)namespaceScope.UsedNamespaces.Length); } // ACASEY: This originally wrote (uint)12, (ushort)1, (ushort)0 in the // case where usingCounts was empty, but I'm not sure why. if (usingCounts.Count > 0) { uint streamLength = 0; cmw.WriteByte(4); // version cmw.WriteByte(0); // kind: UsingInfo cmw.Align(4); cmw.WriteUint(streamLength = PeWriter.Aligned((uint)usingCounts.Count * 2 + 10, 4)); cmw.WriteUshort((ushort)usingCounts.Count); foreach (ushort uc in usingCounts) { cmw.WriteUshort(uc); } cmw.Align(4); Debug.Assert(streamLength == customMetadata.Length); customDebugInfo.Add(customMetadata); } if (this.methodBodyWithModuleInfo != null && !ReferenceEquals(this.methodBodyWithModuleInfo, methodBody)) { SerializeReferenceToMethodWithModuleInfo(customDebugInfo); } }