Ejemplo n.º 1
0
        public void CustomAttributeNamedArgumentsEncoder_Count()
        {
            var b = new BlobBuilder();
            var e = new CustomAttributeNamedArgumentsEncoder(b);

            Assert.Same(b, e.Builder);

            e.Count(0);
            AssertEx.Equal(new byte[] { 0x00, 0x00 }, b.ToArray());
            b.Clear();

            e.Count(ushort.MaxValue);
            AssertEx.Equal(new byte[] { 0xff, 0xff }, b.ToArray());
            b.Clear();

            Assert.Throws <ArgumentOutOfRangeException>(() => e.Count(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => e.Count(ushort.MaxValue + 1));
        }
Ejemplo n.º 2
0
        static void EncodeNamedAttributes(CustomAttributeNamedArgumentsEncoder na, CustomAttributeData attr)
        {
            var args = attr.NamedArguments;
            var enc  = na.Count(args.Count);

            foreach (var a in args)
            {
                // Encode it
                enc.AddArgument(a.IsField, out var typeEnc, out var nameEnc, out var litEnc);
                EncodeType(typeEnc, a.TypedValue.ArgumentType);
                nameEnc.Name(a.MemberName);
                EncodeLiteral(litEnc, a.TypedValue);
            }
        }
Ejemplo n.º 3
0
        public static void NamedArguments(
            this CustomAttributeNamedArgumentsEncoder argumentsEncoder,
            INamedTypeSymbol attributeType,
            IList <KeyValuePair <string, TypedConstant> > namedArguments)
        {
            var encoder = argumentsEncoder.Count(namedArguments.Count);

            foreach (var argument in namedArguments)
            {
                encoder.AddArgument(
                    true,
                    type => type.NamedArgumentType(attributeType, argument.Key),
                    name => name.Name(argument.Key),
                    literal => literal.TypedConstant(argument.Value)
                    );
            }
        }
Ejemplo n.º 4
0
        static void EncodeNamedAttributes(CustomAttributeNamedArgumentsEncoder na, CustomAttributeData attr)
        {
            var args = attr.NamedArguments;
            var enc  = na.Count(args.Count);

            foreach (var a in args)
            {
                // Work out the primitive type code
                var primTypeCode = PrimitiveTypeCodeFromSystemTypeCode(a.TypedValue.ArgumentType);

                // Encode it
                enc.AddArgument(a.IsField, out var typeEnc, out var nameEnc, out var litEnc);
                typeEnc.ScalarType().PrimitiveType(primTypeCode);
                nameEnc.Name(a.MemberName);
                litEnc.Scalar().Constant(a.TypedValue.Value);
            }
        }
Ejemplo n.º 5
0
        public void CustomAttributeNamedArgumentsEncoder_Count()
        {
            var b = new BlobBuilder();
            var e = new CustomAttributeNamedArgumentsEncoder(b);
            Assert.Same(b, e.Builder);

            e.Count(0);
            AssertEx.Equal(new byte[] { 0x00, 0x00 }, b.ToArray());
            b.Clear();

            e.Count(ushort.MaxValue);
            AssertEx.Equal(new byte[] { 0xff, 0xff }, b.ToArray());
            b.Clear();

            Assert.Throws<ArgumentOutOfRangeException>(() => e.Count(-1));
            Assert.Throws<ArgumentOutOfRangeException>(() => e.Count(ushort.MaxValue + 1));
        }