Ejemplo n.º 1
0
        public static void TypedConstant(this LiteralEncoder encoder, TypedConstant constant)
        {
            switch (constant.Kind)
            {
            case TypedConstantKind.Primitive:
                encoder.Scalar().Constant(constant.Value);
                break;

            case TypedConstantKind.Enum:
                encoder.Scalar().Constant(constant.Value);
                break;

            // This looks more correct, but the code above matches what the C# compiler produces
            //  encoder.TaggedScalar(
            //      type => type.Enum(constant.Type.ToString()),
            //      scalar => scalar.Constant(constant.Value)
            //);

            case TypedConstantKind.Type:
                encoder.Scalar().SystemType(constant.Type.ToString());
                break;

            case TypedConstantKind.Array:
            {
                LiteralsEncoder arrayEncoder = encoder.Vector().Count(constant.Values.Length);
                foreach (var arrayConstant in constant.Values)
                {
                    arrayEncoder.AddLiteral().TypedConstant(arrayConstant);
                }
                break;
            }
            }
        }
Ejemplo n.º 2
0
 static void EncodeLiteral(LiteralEncoder litEnc, CustomAttributeTypedArgument arg)
 {
     if (arg.Value is Type type)
     {
         // Type reference
         litEnc.Scalar().SystemType(type.FullName);
     }
     else if (arg.Value is ReadOnlyCollection <CustomAttributeTypedArgument> array)
     {
         // Array of values
         var subLitEnc = litEnc.Vector().Count(array.Count);
         foreach (var el in array)
         {
             EncodeLiteral(subLitEnc.AddLiteral(), el);
         }
     }
     else if (arg.Value is null)
     {
         if (arg.ArgumentType.IsArray)
         {
             litEnc.Scalar().NullArray();
         }
         else
         {
             litEnc.Scalar().Constant(null);
         }
     }
     else
     {
         // Check argument type supported (ie: simple scalar values)
         PrimitiveTypeCodeFromSystemTypeCode(arg.Value.GetType());
         litEnc.Scalar().Constant(arg.Value);
     }
 }
Ejemplo n.º 3
0
        public void LiteralEncoder_Vector()
        {
            var b = new BlobBuilder();
            var e = new LiteralEncoder(b);

            Assert.Same(b, e.Builder);

            var s = e.Vector();

            AssertEx.Equal(new byte[0], b.ToArray());
            Assert.Same(b, s.Builder);
        }
Ejemplo n.º 4
0
        public void LiteralEncoder_Vector()
        {
            var b = new BlobBuilder();
            var e = new LiteralEncoder(b);
            Assert.Same(b, e.Builder);

            var s = e.Vector();
            AssertEx.Equal(new byte[0], b.ToArray());
            Assert.Same(b, s.Builder);
        }