public void EncodeAndDecode() { var encoded = CustomTypeInfo.Encode(null, null); Assert.Null(encoded); var bytes = GetBytesInRange(0, 256); encoded = CustomTypeInfo.Encode(bytes, null); Assert.Null(encoded); bytes = GetBytesInRange(0, 255); encoded = CustomTypeInfo.Encode(bytes, null); Assert.Equal(256, encoded.Count); Assert.Equal(255, encoded[0]); ReadOnlyCollection <byte> dynamicFlags; ReadOnlyCollection <string> tupleElementNames; CustomTypeInfo.Decode(CustomTypeInfo.PayloadTypeId, encoded, out dynamicFlags, out tupleElementNames); Assert.Equal(bytes, dynamicFlags); Assert.Null(tupleElementNames); var names = new ReadOnlyCollection <string>(new[] { null, "A", null, "B" }); encoded = CustomTypeInfo.Encode(bytes, names); Assert.Equal(255, encoded[0]); CustomTypeInfo.Decode(CustomTypeInfo.PayloadTypeId, encoded, out dynamicFlags, out tupleElementNames); Assert.Equal(bytes, dynamicFlags); Assert.Equal(names, tupleElementNames); encoded = CustomTypeInfo.Encode(null, names); CustomTypeInfo.Decode(CustomTypeInfo.PayloadTypeId, encoded, out dynamicFlags, out tupleElementNames); Assert.Null(dynamicFlags); Assert.Equal(names, tupleElementNames); }
internal static ReadOnlyCollection <byte> GetCustomTypeInfoPayload( this CSharpCompilation compilation, TypeSymbol type, int customModifiersCount, RefKind refKind) { return(CustomTypeInfo.Encode( GetDynamicTransforms(compilation, type, customModifiersCount, refKind), GetTupleElementNames(compilation, type))); }
internal static ReadOnlyCollection <byte> ToBytes(this ImmutableArray <bool> dynamicFlags) { Debug.Assert(!dynamicFlags.IsDefaultOrEmpty); var builder = ArrayBuilder <bool> .GetInstance(dynamicFlags.Length); builder.AddRange(dynamicFlags); var bytes = DynamicFlagsCustomTypeInfo.ToBytes(builder); builder.Free(); return(CustomTypeInfo.Encode(bytes, null)); }
public void AliasElement() { var source = @"class C { static (int, int) F; static void M() { } }"; var comp = CreateCompilationWithMscorlib40(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugDll); WithRuntimeInstance(comp, new[] { ValueTupleRef, SystemRuntimeFacadeRef, MscorlibRef }, runtime => { var context = CreateMethodContext( runtime, "C.M"); // (int A, (int, int D) B)[] t; var aliasElementNames = new ReadOnlyCollection <string>(new[] { "A", "B", null, "D" }); var alias = new Alias( DkmClrAliasKind.Variable, "t", "t", "System.ValueTuple`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.ValueTuple`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51]][], System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51", CustomTypeInfo.PayloadTypeId, CustomTypeInfo.Encode(null, aliasElementNames)); var locals = ArrayBuilder <LocalAndMethod> .GetInstance(); string typeName; var diagnostics = DiagnosticBag.GetInstance(); var testData = new CompilationTestData(); var assembly = context.CompileGetLocals( locals, argumentsOnly: false, aliases: ImmutableArray.Create(alias), diagnostics: diagnostics, typeName: out typeName, testData: testData); diagnostics.Verify(); diagnostics.Free(); Assert.Equal(1, locals.Count); ReadOnlyCollection <byte> customTypeInfo; var customTypeInfoId = locals[0].GetCustomTypeInfo(out customTypeInfo); ReadOnlyCollection <byte> dynamicFlags; ReadOnlyCollection <string> tupleElementNames; CustomTypeInfo.Decode(customTypeInfoId, customTypeInfo, out dynamicFlags, out tupleElementNames); Assert.Equal(aliasElementNames, tupleElementNames); var method = (MethodSymbol)testData.GetExplicitlyDeclaredMethods().Single().Value.Method; CheckAttribute(assembly, method, AttributeDescription.TupleElementNamesAttribute, expected: true); var returnType = (TypeSymbol)method.ReturnType; Assert.False(returnType.IsTupleType); Assert.True(((ArrayTypeSymbol)returnType).ElementType.IsTupleType); VerifyLocal(testData, typeName, locals[0], "<>m0", "t", expectedILOpt: @"{ // Code size 16 (0x10) .maxstack 1 IL_0000: ldstr ""t"" IL_0005: call ""object Microsoft.VisualStudio.Debugger.Clr.IntrinsicMethods.GetObjectByAlias(string)"" IL_000a: castclass ""System.ValueTuple<int, System.ValueTuple<int, int>>[]"" IL_000f: ret }"); locals.Free(); }); }
public void EncodeAndDecode() { var encoded = CustomTypeInfo.Encode(null, null); Assert.Null(encoded); ReadOnlyCollection <byte> bytes; ReadOnlyCollection <string> names; // Exceed max bytes. bytes = GetBytesInRange(0, 256); encoded = CustomTypeInfo.Encode(bytes, null); Assert.Null(encoded); // Max bytes. bytes = GetBytesInRange(0, 255); encoded = CustomTypeInfo.Encode(bytes, null); Assert.Equal(256, encoded.Count); Assert.Equal(255, encoded[0]); ReadOnlyCollection <byte> dynamicFlags; ReadOnlyCollection <string> tupleElementNames; CustomTypeInfo.Decode( CustomTypeInfo.PayloadTypeId, encoded, out dynamicFlags, out tupleElementNames ); Assert.Equal(bytes, dynamicFlags); Assert.Null(tupleElementNames); // Empty dynamic flags collection bytes = new ReadOnlyCollection <byte>(new byte[0]); // ... with names. names = new ReadOnlyCollection <string>(new[] { "A" }); encoded = CustomTypeInfo.Encode(bytes, names); CustomTypeInfo.Decode( CustomTypeInfo.PayloadTypeId, encoded, out dynamicFlags, out tupleElementNames ); Assert.Null(dynamicFlags); Assert.Equal(names, tupleElementNames); // ... without names. encoded = CustomTypeInfo.Encode(bytes, null); CustomTypeInfo.Decode( CustomTypeInfo.PayloadTypeId, encoded, out dynamicFlags, out tupleElementNames ); Assert.Null(dynamicFlags); Assert.Null(tupleElementNames); // Empty names collection names = new ReadOnlyCollection <string>(new string[0]); // ... with dynamic flags. bytes = GetBytesInRange(0, 255); encoded = CustomTypeInfo.Encode(bytes, names); CustomTypeInfo.Decode( CustomTypeInfo.PayloadTypeId, encoded, out dynamicFlags, out tupleElementNames ); Assert.Equal(bytes, dynamicFlags); Assert.Null(tupleElementNames); // ... without dynamic flags. encoded = CustomTypeInfo.Encode(null, names); CustomTypeInfo.Decode( CustomTypeInfo.PayloadTypeId, encoded, out dynamicFlags, out tupleElementNames ); Assert.Null(dynamicFlags); Assert.Null(tupleElementNames); // Single null name names = new ReadOnlyCollection <string>(new string[] { null }); // ... with dynamic flags. bytes = GetBytesInRange(0, 255); encoded = CustomTypeInfo.Encode(bytes, names); Assert.Equal(255, encoded[0]); CustomTypeInfo.Decode( CustomTypeInfo.PayloadTypeId, encoded, out dynamicFlags, out tupleElementNames ); Assert.Equal(bytes, dynamicFlags); Assert.Equal(names, tupleElementNames); // ... without dynamic flags. encoded = CustomTypeInfo.Encode(null, names); CustomTypeInfo.Decode( CustomTypeInfo.PayloadTypeId, encoded, out dynamicFlags, out tupleElementNames ); Assert.Null(dynamicFlags); Assert.Equal(names, tupleElementNames); // Multiple names names = new ReadOnlyCollection <string>(new[] { null, "A", null, "B" }); // ... with dynamic flags. bytes = GetBytesInRange(0, 255); encoded = CustomTypeInfo.Encode(bytes, names); Assert.Equal(255, encoded[0]); CustomTypeInfo.Decode( CustomTypeInfo.PayloadTypeId, encoded, out dynamicFlags, out tupleElementNames ); Assert.Equal(bytes, dynamicFlags); Assert.Equal(names, tupleElementNames); // ... without dynamic flags. encoded = CustomTypeInfo.Encode(null, names); CustomTypeInfo.Decode( CustomTypeInfo.PayloadTypeId, encoded, out dynamicFlags, out tupleElementNames ); Assert.Null(dynamicFlags); Assert.Equal(names, tupleElementNames); }