本文整理汇总了C#中MetadataBuilder.AddModule方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataBuilder.AddModule方法的具体用法?C# MetadataBuilder.AddModule怎么用?C# MetadataBuilder.AddModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MetadataBuilder
的用法示例。
在下文中一共展示了MetadataBuilder.AddModule方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public void Add()
{
var builder = new MetadataBuilder();
builder.AddModule(default(Int32), default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Module]);
builder.AddAssembly(default(StringHandle), default(Version), default(StringHandle), default(BlobHandle), default(AssemblyFlags), default(AssemblyHashAlgorithm));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Assembly]);
var assemblyReference = builder.AddAssemblyReference(default(StringHandle), default(Version), default(StringHandle), default(BlobHandle), default(AssemblyFlags), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.AssemblyRef]);
Assert.Equal(1, MetadataTokens.GetRowNumber(assemblyReference));
var typeDefinition = builder.AddTypeDefinition(default(TypeAttributes), default(StringHandle), default(StringHandle), default(EntityHandle), default(FieldDefinitionHandle), default(MethodDefinitionHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.TypeDef]);
Assert.Equal(1, MetadataTokens.GetRowNumber(typeDefinition));
builder.AddTypeLayout(default(TypeDefinitionHandle), default(UInt16), default(UInt32));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.ClassLayout]);
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeDefinitionHandle(1));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.InterfaceImpl]);
builder.AddNestedType(default(TypeDefinitionHandle), default(TypeDefinitionHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.NestedClass]);
var typeReference = builder.AddTypeReference(EntityHandle.ModuleDefinition, default(StringHandle), default(StringHandle));
Assert.Equal(1, MetadataTokens.GetRowNumber(typeReference));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.TypeRef]);
builder.AddTypeSpecification(default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.TypeSpec]);
builder.AddStandaloneSignature(default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.StandAloneSig]);
builder.AddProperty(default(PropertyAttributes), default(StringHandle), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Property]);
builder.AddPropertyMap(default(TypeDefinitionHandle), default(PropertyDefinitionHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.PropertyMap]);
builder.AddEvent(default(EventAttributes), default(StringHandle), MetadataTokens.TypeDefinitionHandle(1));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Event]);
builder.AddEventMap(default(TypeDefinitionHandle), default(EventDefinitionHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.EventMap]);
builder.AddConstant(MetadataTokens.FieldDefinitionHandle(1), default(Object));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Constant]);
builder.AddMethodSemantics(MetadataTokens.EventDefinitionHandle(1), default(UInt16), default(MethodDefinitionHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.MethodSemantics]);
builder.AddCustomAttribute(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.MethodDefinitionHandle(1), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.CustomAttribute]);
builder.AddMethodSpecification(MetadataTokens.MethodDefinitionHandle(1), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.MethodSpec]);
builder.AddModuleReference(default(StringHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.ModuleRef]);
builder.AddParameter(default(ParameterAttributes), default(StringHandle), default(Int32));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Param]);
var genericParameter = builder.AddGenericParameter(MetadataTokens.MethodDefinitionHandle(1), default(GenericParameterAttributes), default(StringHandle), default(Int32));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.GenericParam]);
Assert.Equal(1, MetadataTokens.GetRowNumber(genericParameter));
builder.AddGenericParameterConstraint(default(GenericParameterHandle), MetadataTokens.TypeDefinitionHandle(1));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.GenericParamConstraint]);
builder.AddFieldDefinition(default(FieldAttributes), default(StringHandle), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.Field]);
builder.AddFieldLayout(default(FieldDefinitionHandle), default(Int32));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.FieldLayout]);
builder.AddMarshallingDescriptor(MetadataTokens.FieldDefinitionHandle(1), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.FieldMarshal]);
builder.AddFieldRelativeVirtualAddress(default(FieldDefinitionHandle), default(Int32));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.FieldRva]);
var methodDefinition = builder.AddMethodDefinition(default(MethodAttributes), default(MethodImplAttributes), default(StringHandle), default(BlobHandle), default(Int32), default(ParameterHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.MethodDef]);
Assert.Equal(1, MetadataTokens.GetRowNumber(methodDefinition));
builder.AddMethodImport(MetadataTokens.MethodDefinitionHandle(1), default(MethodImportAttributes), default(StringHandle), default(ModuleReferenceHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.ImplMap]);
builder.AddMethodImplementation(default(TypeDefinitionHandle), MetadataTokens.MethodDefinitionHandle(1), MetadataTokens.MethodDefinitionHandle(1));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.MethodImpl]);
var memberReference = builder.AddMemberReference(MetadataTokens.TypeDefinitionHandle(1), default(StringHandle), default(BlobHandle));
Assert.Equal(1, builder.GetRowCounts()[(int)TableIndex.MemberRef]);
Assert.Equal(1, MetadataTokens.GetRowNumber(memberReference));
//.........这里部分代码省略.........
示例2: Add
public void Add()
{
var builder = new MetadataBuilder();
builder.AddModule(default(int), default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.Module));
builder.AddAssembly(default(StringHandle), new Version(0, 0, 0, 0), default(StringHandle), default(BlobHandle), default(AssemblyFlags), default(AssemblyHashAlgorithm));
Assert.Equal(1, builder.GetRowCount(TableIndex.Assembly));
var assemblyReference = builder.AddAssemblyReference(default(StringHandle), new Version(0, 0, 0, 0), default(StringHandle), default(BlobHandle), default(AssemblyFlags), default(BlobHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.AssemblyRef));
Assert.Equal(1, MetadataTokens.GetRowNumber(assemblyReference));
var typeDefinition = builder.AddTypeDefinition(default(TypeAttributes), default(StringHandle), default(StringHandle), default(EntityHandle), default(FieldDefinitionHandle), default(MethodDefinitionHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.TypeDef));
Assert.Equal(1, MetadataTokens.GetRowNumber(typeDefinition));
builder.AddTypeLayout(default(TypeDefinitionHandle), default(ushort), default(uint));
Assert.Equal(1, builder.GetRowCount(TableIndex.ClassLayout));
builder.AddInterfaceImplementation(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.TypeDefinitionHandle(1));
Assert.Equal(1, builder.GetRowCount(TableIndex.InterfaceImpl));
builder.AddNestedType(default(TypeDefinitionHandle), default(TypeDefinitionHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.NestedClass));
var typeReference = builder.AddTypeReference(EntityHandle.ModuleDefinition, default(StringHandle), default(StringHandle));
Assert.Equal(1, MetadataTokens.GetRowNumber(typeReference));
Assert.Equal(1, builder.GetRowCount(TableIndex.TypeRef));
builder.AddTypeSpecification(default(BlobHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.TypeSpec));
builder.AddStandaloneSignature(default(BlobHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.StandAloneSig));
builder.AddProperty(default(PropertyAttributes), default(StringHandle), default(BlobHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.Property));
builder.AddPropertyMap(default(TypeDefinitionHandle), default(PropertyDefinitionHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.PropertyMap));
builder.AddEvent(default(EventAttributes), default(StringHandle), MetadataTokens.TypeDefinitionHandle(1));
Assert.Equal(1, builder.GetRowCount(TableIndex.Event));
builder.AddEventMap(default(TypeDefinitionHandle), default(EventDefinitionHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.EventMap));
builder.AddConstant(MetadataTokens.FieldDefinitionHandle(1), default(object));
Assert.Equal(1, builder.GetRowCount(TableIndex.Constant));
builder.AddMethodSemantics(MetadataTokens.EventDefinitionHandle(1), default(ushort), default(MethodDefinitionHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.MethodSemantics));
builder.AddCustomAttribute(MetadataTokens.TypeDefinitionHandle(1), MetadataTokens.MethodDefinitionHandle(1), default(BlobHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.CustomAttribute));
builder.AddMethodSpecification(MetadataTokens.MethodDefinitionHandle(1), default(BlobHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.MethodSpec));
builder.AddModuleReference(default(StringHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.ModuleRef));
builder.AddParameter(default(ParameterAttributes), default(StringHandle), default(int));
Assert.Equal(1, builder.GetRowCount(TableIndex.Param));
var genericParameter = builder.AddGenericParameter(MetadataTokens.MethodDefinitionHandle(1), default(GenericParameterAttributes), default(StringHandle), default(int));
Assert.Equal(1, builder.GetRowCount(TableIndex.GenericParam));
Assert.Equal(1, MetadataTokens.GetRowNumber(genericParameter));
builder.AddGenericParameterConstraint(default(GenericParameterHandle), MetadataTokens.TypeDefinitionHandle(1));
Assert.Equal(1, builder.GetRowCount(TableIndex.GenericParamConstraint));
builder.AddFieldDefinition(default(FieldAttributes), default(StringHandle), default(BlobHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.Field));
builder.AddFieldLayout(default(FieldDefinitionHandle), default(int));
Assert.Equal(1, builder.GetRowCount(TableIndex.FieldLayout));
builder.AddMarshallingDescriptor(MetadataTokens.FieldDefinitionHandle(1), default(BlobHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.FieldMarshal));
builder.AddFieldRelativeVirtualAddress(default(FieldDefinitionHandle), default(int));
Assert.Equal(1, builder.GetRowCount(TableIndex.FieldRva));
var methodDefinition = builder.AddMethodDefinition(default(MethodAttributes), default(MethodImplAttributes), default(StringHandle), default(BlobHandle), default(int), default(ParameterHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.MethodDef));
Assert.Equal(1, MetadataTokens.GetRowNumber(methodDefinition));
builder.AddMethodImport(MetadataTokens.MethodDefinitionHandle(1), default(MethodImportAttributes), default(StringHandle), default(ModuleReferenceHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.ImplMap));
builder.AddMethodImplementation(default(TypeDefinitionHandle), MetadataTokens.MethodDefinitionHandle(1), MetadataTokens.MethodDefinitionHandle(1));
Assert.Equal(1, builder.GetRowCount(TableIndex.MethodImpl));
var memberReference = builder.AddMemberReference(MetadataTokens.TypeDefinitionHandle(1), default(StringHandle), default(BlobHandle));
Assert.Equal(1, builder.GetRowCount(TableIndex.MemberRef));
Assert.Equal(1, MetadataTokens.GetRowNumber(memberReference));
//.........这里部分代码省略.........
示例3: GetOrAddDocumentName2
public void GetOrAddDocumentName2()
{
var mdBuilder = new MetadataBuilder();
mdBuilder.AddModule(0, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle));
var n1 = mdBuilder.GetOrAddDocumentName("");
var n2 = mdBuilder.GetOrAddDocumentName("/a/b/c");
var n3 = mdBuilder.GetOrAddDocumentName(@"\a\b\cc");
var n4 = mdBuilder.GetOrAddDocumentName(@"/a/b\c");
var n5 = mdBuilder.GetOrAddDocumentName(@"/\a/\b\\//c");
var n6 = mdBuilder.GetOrAddDocumentName(@"a/");
var n7 = mdBuilder.GetOrAddDocumentName(@"/");
var n8 = mdBuilder.GetOrAddDocumentName(@"\\");
var n9 = mdBuilder.GetOrAddDocumentName("\ud800"); // unpaired surrogate
var n10 = mdBuilder.GetOrAddDocumentName("\0");
var root = new MetadataRootBuilder(mdBuilder);
var rootBuilder = new BlobBuilder();
root.Serialize(rootBuilder, 0, 0);
var mdImage = rootBuilder.ToImmutableArray();
using (var provider = MetadataReaderProvider.FromMetadataImage(mdImage))
{
var mdReader = provider.GetMetadataReader();
Assert.Equal("", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n1))));
Assert.Equal("/a/b/c", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n2))));
Assert.Equal(@"\a\b\cc", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n3))));
Assert.Equal(@"/a/b\c", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n4))));
Assert.Equal(@"/\a/\b\\//c", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n5))));
Assert.Equal(@"a/", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n6))));
Assert.Equal(@"/", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n7))));
Assert.Equal(@"\\", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n8))));
Assert.Equal("\uFFFd\uFFFd", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n9))));
Assert.Equal("\0", mdReader.GetString(MetadataTokens.DocumentNameBlobHandle(MetadataTokens.GetHeapOffset(n10))));
}
}
示例4: Add_ArgumentErrors
public void Add_ArgumentErrors()
{
var builder = new MetadataBuilder();
var badHandleKind = CustomAttributeHandle.FromRowId(1);
Assert.Throws<ArgumentNullException>(() => builder.AddAssembly(default(StringHandle), null, default(StringHandle), default(BlobHandle), 0, 0));
Assert.Throws<ArgumentNullException>(() => builder.AddAssemblyReference(default(StringHandle), null, default(StringHandle), default(BlobHandle), 0, default(BlobHandle)));
Assert.Throws<ArgumentException>(() => builder.AddTypeDefinition(0, default(StringHandle), default(StringHandle), badHandleKind, default(FieldDefinitionHandle), default(MethodDefinitionHandle)));
Assert.Throws<ArgumentException>(() => builder.AddInterfaceImplementation(default(TypeDefinitionHandle), badHandleKind));
Assert.Throws<ArgumentException>(() => builder.AddTypeReference(badHandleKind, default(StringHandle), default(StringHandle)));
Assert.Throws<ArgumentException>(() => builder.AddEvent(0, default(StringHandle), badHandleKind));
Assert.Throws<ArgumentException>(() => builder.AddConstant(badHandleKind, 0));
Assert.Throws<ArgumentException>(() => builder.AddMethodSemantics(badHandleKind, 0, default(MethodDefinitionHandle)));
Assert.Throws<ArgumentException>(() => builder.AddCustomAttribute(badHandleKind, default(MethodDefinitionHandle), default(BlobHandle)));
Assert.Throws<ArgumentException>(() => builder.AddCustomAttribute(default(TypeDefinitionHandle), badHandleKind, default(BlobHandle)));
Assert.Throws<ArgumentException>(() => builder.AddMethodSpecification(badHandleKind, default(BlobHandle)));
Assert.Throws<ArgumentException>(() => builder.AddGenericParameter(badHandleKind, 0, default(StringHandle), 0));
Assert.Throws<ArgumentException>(() => builder.AddGenericParameterConstraint(default(GenericParameterHandle), badHandleKind));
Assert.Throws<ArgumentException>(() => builder.AddMarshallingDescriptor(badHandleKind, default(BlobHandle)));
Assert.Throws<ArgumentException>(() => builder.AddMethodImplementation(default(TypeDefinitionHandle), badHandleKind, default(MethodDefinitionHandle)));
Assert.Throws<ArgumentException>(() => builder.AddMethodImplementation(default(TypeDefinitionHandle), default(MethodDefinitionHandle), badHandleKind));
Assert.Throws<ArgumentException>(() => builder.AddMemberReference(badHandleKind, default(StringHandle), default(BlobHandle)));
Assert.Throws<ArgumentException>(() => builder.AddManifestResource(0, default(StringHandle), badHandleKind, 0));
Assert.Throws<ArgumentException>(() => builder.AddExportedType(0, default(StringHandle), default(StringHandle), badHandleKind, 0));
Assert.Throws<ArgumentException>(() => builder.AddDeclarativeSecurityAttribute(badHandleKind, 0, default(BlobHandle)));
Assert.Throws<ArgumentException>(() => builder.AddCustomDebugInformation(badHandleKind, default(GuidHandle), default(BlobHandle)));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.AddModule(-1, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle)));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.AddModule(ushort.MaxValue + 1, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle)));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.AddParameter(0, default(StringHandle), -1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.AddGenericParameter(default(TypeDefinitionHandle), 0, default(StringHandle), -1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.AddFieldRelativeVirtualAddress(default(FieldDefinitionHandle), -1));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.AddMethodDefinition(0, 0, default(StringHandle), default(BlobHandle), -2, default(ParameterHandle)));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.AddLocalVariable(0, -1, default(StringHandle)));
}
示例5: MultipleModuleAssemblyEntries
public void MultipleModuleAssemblyEntries()
{
var builder = new MetadataBuilder();
builder.AddAssembly(default(StringHandle), new Version(0, 0, 0, 0), default(StringHandle), default(BlobHandle), 0, 0);
builder.AddModule(0, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle));
Assert.Throws<InvalidOperationException>(() => builder.AddAssembly(default(StringHandle), new Version(0, 0, 0, 0), default(StringHandle), default(BlobHandle), 0, 0));
Assert.Throws<InvalidOperationException>(() => builder.AddModule(0, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle)));
}
示例6: MetadataVersion
public void MetadataVersion()
{
var version = "\u1234\ud800";
var mdBuilder = new MetadataBuilder();
mdBuilder.AddModule(0, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle));
var rootBuilder = new MetadataRootBuilder(mdBuilder, version);
var builder = new BlobBuilder();
rootBuilder.Serialize(builder, 0, 0);
AssertEx.Equal(new byte[]
{
// padded version length:
0x08, 0x00, 0x00, 0x00,
// padded version:
0xE1, 0x88, 0xB4, 0xED, 0xA0, 0x80, 0x00, 0x00,
}, builder.Slice(12, -132));
// the default decoder replaces bad byte sequences by U+FFFD
Assert.Equal("\u1234\ufffd\ufffd", ReadVersion(builder));
}
示例7: MetadataVersion_MaxLength
public void MetadataVersion_MaxLength()
{
var version = new string('x', 254);
var mdBuilder = new MetadataBuilder();
mdBuilder.AddModule(0, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle));
var rootBuilder = new MetadataRootBuilder(mdBuilder, version);
var builder = new BlobBuilder();
rootBuilder.Serialize(builder, 0, 0);
AssertEx.Equal(new byte[]
{
// padded version length:
0x00, 0x01, 0x00, 0x00,
// padded version:
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x00, 0x00
}, builder.Slice(12, -132));
Assert.Equal(version, ReadVersion(builder));
}
示例8: MetadataVersion_Default
public void MetadataVersion_Default()
{
var mdBuilder = new MetadataBuilder();
mdBuilder.AddModule(0, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle));
var rootBuilder = new MetadataRootBuilder(mdBuilder);
var builder = new BlobBuilder();
rootBuilder.Serialize(builder, 0, 0);
AssertEx.Equal(new byte[]
{
// padded version length:
0x0C, 0x00, 0x00, 0x00,
// padded version:
(byte)'v', (byte)'4', (byte)'.', (byte)'0', (byte)'.', (byte)'3', (byte)'0', (byte)'3', (byte)'1', (byte)'9', 0x00, 0x00,
}, builder.Slice(12, -132));
Assert.Equal(rootBuilder.MetadataVersion, ReadVersion(builder));
}
示例9: BasicValidationEmit
private static MethodDefinitionHandle BasicValidationEmit(MetadataBuilder metadata, BlobBuilder ilBuilder)
{
metadata.AddModule(
0,
metadata.GetOrAddString("ConsoleApplication.exe"),
metadata.GetOrAddGuid(Guid.NewGuid()),
default(GuidHandle),
default(GuidHandle));
metadata.AddAssembly(
metadata.GetOrAddString("ConsoleApplication"),
version: new Version(0, 0, 0, 0),
culture: default(StringHandle),
publicKey: default(BlobHandle),
flags: default(AssemblyFlags),
hashAlgorithm: AssemblyHashAlgorithm.Sha1);
var mscorlibAssemblyRef = metadata.AddAssemblyReference(
name: metadata.GetOrAddString("mscorlib"),
version: new Version(4, 0, 0, 0),
culture: default(StringHandle),
publicKeyOrToken: metadata.GetOrAddBlob(ImmutableArray.Create<byte>(0xB7, 0x7A, 0x5C, 0x56, 0x19, 0x34, 0xE0, 0x89)),
flags: default(AssemblyFlags),
hashValue: default(BlobHandle));
var systemObjectTypeRef = metadata.AddTypeReference(
mscorlibAssemblyRef,
metadata.GetOrAddString("System"),
metadata.GetOrAddString("Object"));
var systemConsoleTypeRefHandle = metadata.AddTypeReference(
mscorlibAssemblyRef,
metadata.GetOrAddString("System"),
metadata.GetOrAddString("Console"));
var consoleWriteLineSignature = new BlobBuilder();
new BlobEncoder(consoleWriteLineSignature).
MethodSignature().
Parameters(1,
returnType => returnType.Void(),
parameters =>
{
parameters.AddParameter().Type().String();
parameters.EndParameters();
});
var consoleWriteLineMemberRef = metadata.AddMemberReference(
systemConsoleTypeRefHandle,
metadata.GetOrAddString("WriteLine"),
metadata.GetOrAddBlob(consoleWriteLineSignature));
var parameterlessCtorSignature = new BlobBuilder();
new BlobEncoder(parameterlessCtorSignature).
MethodSignature(isInstanceMethod: true).
Parameters(0, returnType => returnType.Void(), parameters => parameters.EndParameters());
var parameterlessCtorBlobIndex = metadata.GetOrAddBlob(parameterlessCtorSignature);
var objectCtorMemberRef = metadata.AddMemberReference(
systemObjectTypeRef,
metadata.GetOrAddString(".ctor"),
parameterlessCtorBlobIndex);
var mainSignature = new BlobBuilder();
new BlobEncoder(mainSignature).
MethodSignature().
Parameters(0, returnType => returnType.Void(), parameters => parameters.EndParameters());
var methodBodies = new MethodBodiesEncoder(ilBuilder);
var codeBuilder = new BlobBuilder();
var branchBuilder = new BranchBuilder();
InstructionEncoder il;
//
// Program::.ctor
//
int ctorBodyOffset;
il = new InstructionEncoder(codeBuilder);
// ldarg.0
il.LoadArgument(0);
// call instance void [mscorlib]System.Object::.ctor()
il.Call(objectCtorMemberRef);
// ret
il.OpCode(ILOpCode.Ret);
methodBodies.AddMethodBody().WriteInstructions(codeBuilder, out ctorBodyOffset);
codeBuilder.Clear();
//
// Program::Main
//
int mainBodyOffset;
il = new InstructionEncoder(codeBuilder, branchBuilder);
//.........这里部分代码省略.........
示例10: ComplexEmit
private static MethodDefinitionHandle ComplexEmit(MetadataBuilder metadata, BlobBuilder ilBuilder)
{
metadata.AddModule(
0,
metadata.GetOrAddString("ConsoleApplication.exe"),
metadata.GetOrAddGuid(Guid.NewGuid()),
default(GuidHandle),
default(GuidHandle));
metadata.AddAssembly(
metadata.GetOrAddString("ConsoleApplication"),
version: new Version(0, 0, 0, 0),
culture: default(StringHandle),
publicKey: default(BlobHandle),
flags: default(AssemblyFlags),
hashAlgorithm: AssemblyHashAlgorithm.Sha1);
var mscorlibAssemblyRef = metadata.AddAssemblyReference(
name: metadata.GetOrAddString("mscorlib"),
version: new Version(4, 0, 0, 0),
culture: default(StringHandle),
publicKeyOrToken: metadata.GetOrAddBlob(ImmutableArray.Create<byte>(0xB7, 0x7A, 0x5C, 0x56, 0x19, 0x34, 0xE0, 0x89)),
flags: default(AssemblyFlags),
hashValue: default(BlobHandle));
// TypeRefs:
var systemObjectTypeRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System"), metadata.GetOrAddString("Object"));
var dictionaryTypeRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System.Collections.Generic"), metadata.GetOrAddString("Dictionary`2"));
var strignBuilderTypeRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System.Text"), metadata.GetOrAddString("StringBuilder"));
var typeTypeRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System"), metadata.GetOrAddString("Type"));
var int32TypeRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System"), metadata.GetOrAddString("Int32"));
var runtimeTypeHandleRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System"), metadata.GetOrAddString("RuntimeTypeHandle"));
var invalidOperationExceptionTypeRef = metadata.AddTypeReference(mscorlibAssemblyRef, metadata.GetOrAddString("System"), metadata.GetOrAddString("InvalidOperationException"));
// TypeDefs:
metadata.AddTypeDefinition(
default(TypeAttributes),
default(StringHandle),
metadata.GetOrAddString("<Module>"),
baseType: default(EntityHandle),
fieldList: MetadataTokens.FieldDefinitionHandle(1),
methodList: MetadataTokens.MethodDefinitionHandle(1));
var baseClassTypeDef = metadata.AddTypeDefinition(
TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.AutoLayout | TypeAttributes.BeforeFieldInit | TypeAttributes.Abstract,
metadata.GetOrAddString("Lib"),
metadata.GetOrAddString("BaseClass"),
systemObjectTypeRef,
fieldList: MetadataTokens.FieldDefinitionHandle(1),
methodList: MetadataTokens.MethodDefinitionHandle(1));
var derivedClassTypeDef = metadata.AddTypeDefinition(
TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.AutoLayout | TypeAttributes.BeforeFieldInit,
metadata.GetOrAddString("Lib"),
metadata.GetOrAddString("DerivedClass"),
baseClassTypeDef,
fieldList: MetadataTokens.FieldDefinitionHandle(4),
methodList: MetadataTokens.MethodDefinitionHandle(1));
// FieldDefs:
// Field1
var baseClassNumberFieldDef = metadata.AddFieldDefinition(
FieldAttributes.Private,
metadata.GetOrAddString("_number"),
metadata.GetOrAddBlob(BuildSignature(e => e.FieldSignature().Int32())));
// Field2
var baseClassNegativeFieldDef = metadata.AddFieldDefinition(
FieldAttributes.Assembly,
metadata.GetOrAddString("negative"),
metadata.GetOrAddBlob(BuildSignature(e => e.FieldSignature().Boolean())));
// Field3
var derivedClassSumCacheFieldDef = metadata.AddFieldDefinition(
FieldAttributes.Assembly,
metadata.GetOrAddString("_sumCache"),
metadata.GetOrAddBlob(BuildSignature(e =>
{
var inst = e.FieldSignature().GenericInstantiation(isValueType: false, typeRefDefSpec: dictionaryTypeRef, genericArgumentCount: 2);
inst.AddArgument().Int32();
inst.AddArgument().Object();
})));
// Field4
var derivedClassCountFieldDef = metadata.AddFieldDefinition(
FieldAttributes.Assembly,
metadata.GetOrAddString("_count"),
metadata.GetOrAddBlob(BuildSignature(e => e.FieldSignature().SZArray().Int32())));
// Field5
var derivedClassBCFieldDef = metadata.AddFieldDefinition(
FieldAttributes.Assembly,
metadata.GetOrAddString("_bc"),
metadata.GetOrAddBlob(BuildSignature(e => e.FieldSignature().TypeDefOrRefOrSpec(isValueType: false, typeRefDefSpec: baseClassTypeDef))));
var methodBodies = new MethodBodiesEncoder(ilBuilder);
//.........这里部分代码省略.........