internal static byte[] Write(ICustomAttributeWriterHelper helper, CustomAttribute ca, DataWriterContext context)
 {
     using (var writer = new CustomAttributeWriter(helper, context)) {
         writer.Write(ca);
         return(writer.GetResult());
     }
 }
 internal static byte[] Write(ICustomAttributeWriterHelper helper, IList <CANamedArgument> namedArgs, DataWriterContext context)
 {
     using (var writer = new CustomAttributeWriter(helper, context)) {
         writer.Write(namedArgs);
         return(writer.GetResult());
     }
 }
 /// <summary>
 /// Writes a custom attribute
 /// </summary>
 /// <param name="helper">Helper class</param>
 /// <param name="ca">The custom attribute</param>
 /// <returns>Custom attribute blob</returns>
 public static byte[] Write(ICustomAttributeWriterHelper helper, CustomAttribute ca)
 {
     using (var writer = new CustomAttributeWriter(helper)) {
         writer.Write(ca);
         return(writer.GetResult());
     }
 }
        byte[] WriteFormat2(IList <SecurityAttribute> secAttrs)
        {
            var stream = new MemoryStream();
            var writer = new DataWriter(stream);

            writer.WriteByte((byte)'.');
            WriteCompressedUInt32(writer, (uint)secAttrs.Count);

            int count = secAttrs.Count;

            for (int i = 0; i < count; i++)
            {
                var sa = secAttrs[i];
                if (sa is null)
                {
                    helper.Error("SecurityAttribute is null");
                    Write(writer, UTF8String.Empty);
                    WriteCompressedUInt32(writer, 1);
                    WriteCompressedUInt32(writer, 0);
                    continue;
                }
                var    attrType = sa.AttributeType;
                string fqn;
                if (attrType is null)
                {
                    helper.Error("SecurityAttribute attribute type is null");
                    fqn = string.Empty;
                }
                else
                {
                    fqn = attrType.AssemblyQualifiedName;
                }
                Write(writer, fqn);

                var namedArgsBlob = context is null?
                                    CustomAttributeWriter.Write(this, sa.NamedArguments) :
                                        CustomAttributeWriter.Write(this, sa.NamedArguments, context);

                if (namedArgsBlob.Length > 0x1FFFFFFF)
                {
                    helper.Error("Named arguments blob size doesn't fit in 29 bits");
                    namedArgsBlob = Array2.Empty <byte>();
                }
                WriteCompressedUInt32(writer, (uint)namedArgsBlob.Length);
                writer.WriteBytes(namedArgsBlob);
            }

            return(stream.ToArray());
        }