1use crate::file::*;
2use crate::row::Row;
3use crate::tables::*;
4use crate::TypeReader;
5
6use winrt_gen_macros::type_code;
7
8pub trait Decode {
9 fn decode(code: u32, file: u16) -> Self;
10}
11
12#[type_code(2)]
13pub enum TypeDefOrRef {
14 TypeDef,
15 TypeRef,
16 TypeSpec,
17}
18
19#[type_code(1)]
20pub enum TypeOrMethodDef {
21 TypeDef,
22 MethodDef,
23}
24
25#[type_code(5)]
26pub enum HasAttribute {
27 MethodDef,
28 Field,
29 TypeRef,
30 TypeDef,
31 Param,
32 InterfaceImpl,
33 MemberRef,
34 TypeSpec = 13,
35 GenericParam = 19,
36}
37
38#[type_code(3)]
39pub enum MemberRefParent {
40 TypeDef,
41 TypeRef,
42 MethodDef = 3,
43 TypeSpec,
44}
45
46#[type_code(2)]
47pub enum HasConstant {
48 Field,
49 Param,
50}
51
52#[type_code(3)]
53pub enum AttributeType {
54 MethodDef = 2,
55 MemberRef,
56}
57
58impl TypeDefOrRef {
59 pub fn name<'a>(&self, reader: &'a TypeReader) -> (&'a str, &'a str) {
60 match self {
61 TypeDefOrRef::TypeDef(value) => value.name(reader),
62 TypeDefOrRef::TypeRef(value) => value.name(reader),
63 TypeDefOrRef::TypeSpec(_) => panic!("Expected a TypeDef or TypeRef"),
64 }
65 }
66
67 pub fn resolve(&self, reader: &TypeReader) -> TypeDef {
68 match self {
69 Self::TypeDef(value) => *value,
70 Self::TypeRef(value) => value.resolve(reader),
71 Self::TypeSpec(_) => panic!("Expected a TypeDef or TypeRef"),
72 }
73 }
74}