winmd 7.0.0
winmd: ^7.0.0 copied to clipboard
Inspect and generate Windows Metadata (.winmd) files based on the ECMA-335 standard.
A Dart package for parsing, analyzing, and producing Windows Metadata (.winmd) files, based on the ECMA-335 standard.
This package offers both low-level primitives and high-level abstractions for
inspecting and generating Windows Metadata (.winmd
) files.
It is a vital component of Dart-based Windows interop tooling — powering
packages like win32.
Key Features #
- Parse
.winmd
files into rich, strongly-typed Dart object models - Query type definitions, methods, fields, and more across multiple metadata sources
- Perform fast, namespace-agnostic symbol resolution
- Merge multiple
.winmd
files into a single, unified file - Generate your own
.winmd
files programmatically - Works on Windows, Linux, and macOS
Usage #
A basic example demonstrating how to load and inspect WinRT metadata from a
.winmd
file:
import 'dart:io' as io;
import 'package:winmd/winmd.dart';
void main() {
// Load WinRT metadata from a local .winmd file.
const winmdPath = r'C:\WINDOWS\System32\WinMetadata\Windows.Storage.winmd';
final bytes = io.File(winmdPath).readAsBytesSync();
final reader = MetadataReader.read(bytes);
final index = MetadataIndex.fromReader(reader);
// Optional: Use MetadataLookup for efficient type resolution by name.
// This is especially helpful when the namespace of the target type is
// unknown.
final metadata = MetadataLookup(index);
// Lookup a WinRT class (e.g., StorageFile) and list its public methods.
final storageFile = metadata.findSingleTypeByName('StorageFile');
print('WinRT class "${storageFile.name}" has the following methods:');
for (final method in storageFile.methods) {
print(' ${method.name}');
}
print('');
// Lookup a WinRT enum (e.g., FileAttributes) and display its members.
final enumType = metadata.findSingleTypeByName('FileAttributes');
print('WinRT enum "${enumType.name}" has the following fields:');
// The first field represents the underlying integral type (e.g., Int32).
final underlyingType = enumType.fields.first;
print(' ${underlyingType.name} = ${underlyingType.signature.type}');
// Subsequent fields are named values within the enum.
for (final field in enumType.fields.skip(1)) {
print(' ${field.name} = ${field.constant?.value}');
}
}
More examples can be found in the example subdirectory.
Feature requests and bugs #
Please file feature requests and bugs at the issue tracker.