public MetadataToken ReadCodedToken(CodedTokenType tokenType) { var value = ReadBySize(IsLargeToken(tokenType)); var codedToken = new CodedToken(value); return(CodedTokenSchema.GetMetadataToken(codedToken, tokenType)); }
public static bool IsLargeToken(CodedTokenType type, TableHeap heap) { MetadataTokenType[] types; if (!_schema.TryGetValue(type, out types)) { throw new UndefinedCodedTokenSchemaException("Schema for coded token: {0} is undefined", type); } int bits = _sizes[type]; int max = 0; for (int i = 0; i < types.Length; i++) { IMetadataTable table; int size = heap.TryGetTable(types[i], out table) ? table.Length : 0; max = Math.Max(size, max); } return(max >= (1 << (16 - bits))); }
public static MetadataToken GetMetadataToken(CodedToken token, CodedTokenType type) { MetadataTokenType[] types; if (!_schema.TryGetValue(type, out types)) { throw new UndefinedCodedTokenSchemaException("Schema for coded token: {0} is undefined", type); } int bits = _sizes[type]; uint index = 0u; uint value = token.Value; for (int i = 0; i < bits; i++) { index |= value & (1u << i); } MetadataTokenType tokenType = types[index]; uint rid = (value >> bits); return(new MetadataToken(tokenType, rid)); }
public static CodedToken GetCodedToken(MetadataToken token, CodedTokenType type) { if (token.RID == 0) { return(new CodedToken()); } MetadataTokenType[] types; if (!_schema.TryGetValue(type, out types)) { throw new UndefinedCodedTokenSchemaException("Schema for coded token: {0} is undefined", type); } int index = Array.IndexOf(types, token.Type); if (index == -1) { throw new UndefinedCodedTokenSchemaException("Schema for coded token: {0} and metadata token: {1} is undefined", type, token.Type); } uint value = token.RID << _sizes[type]; return(new CodedToken(value | (uint)index)); }
private bool IsLargeToken(CodedTokenType tokenType) { return(_isLargeToken(tokenType)); }
public void WriteCodedToken(MetadataToken token, CodedTokenType tokenType) { var codedToken = CodedTokenSchema.GetCodedToken(token, tokenType); WriteBySize(codedToken.Value, IsLargeToken(tokenType)); }