Example #1
0
        void AddInternalsVisibleToAttribute()
        {
            bool b = GetCorLibToken(out var corlibToken);

            Debug.Assert(b, "No corlib assembly found");
            if (!b)
            {
                return;
            }
            b = CodedToken.ResolutionScope.Encode(corlibToken, out uint corlibEncodedToken);
            Debug.Assert(b);
            if (!b)
            {
                return;
            }

            uint ivtTypeRefRid = mdEditor.TablesHeap.TypeRefTable.Create();
            var  ivtTypeRefRow = new RawTypeRefRow(corlibEncodedToken, mdEditor.StringsHeap.Create("InternalsVisibleToAttribute"), mdEditor.StringsHeap.Create("System.Runtime.CompilerServices"));

            mdEditor.TablesHeap.TypeRefTable.Set(ivtTypeRefRid, ref ivtTypeRefRow);

            uint ivtCtorRid = mdEditor.TablesHeap.MemberRefTable.Create();
            var  ivtCtorRow = new RawMemberRefRow(CodedToken.MemberRefParent.Encode(new MDToken(Table.TypeRef, ivtTypeRefRid)),
                                                  mdEditor.StringsHeap.Create(".ctor"), mdEditor.BlobHeap.Create(ivtCtorSigBlob));

            mdEditor.TablesHeap.MemberRefTable.Set(ivtCtorRid, ref ivtCtorRow);

            uint ivtCARid = mdEditor.TablesHeap.CustomAttributeTable.Create();
            var  ivtCARow = new RawCustomAttributeRow(CodedToken.HasCustomAttribute.Encode(new MDToken(Table.Assembly, 1)),
                                                      CodedToken.CustomAttributeType.Encode(new MDToken(Table.MemberRef, ivtCtorRid)),
                                                      mdEditor.BlobHeap.Create(MDPatcherUtils.CreateIVTBlob(tempAssembly)));

            mdEditor.TablesHeap.CustomAttributeTable.Set(ivtCARid, ref ivtCARow);
        }