コード例 #1
0
 /// <summary>
 /// Writes custom attribute named arguments
 /// </summary>
 /// <param name="helper">Helper class</param>
 /// <param name="namedArgs">Named arguments</param>
 /// <returns>The named args blob</returns>
 internal static byte[] Write(ICustomAttributeWriterHelper helper, IList <CANamedArgument> namedArgs)
 {
     using (var writer = new CustomAttributeWriter(helper))
     {
         writer.Write(namedArgs);
         return(writer.GetResult());
     }
 }
コード例 #2
0
 /// <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());
     }
 }
コード例 #3
0
        private byte[] WriteFormat2(IList <SecurityAttribute> secAttrs)
        {
            using (var stream = new MemoryStream())
                using (var writer = new BinaryWriter(stream))
                {
                    writer.Write((byte)'.');
                    WriteCompressedUInt32(writer, (uint)secAttrs.Count);

                    foreach (var sa in secAttrs)
                    {
                        if (sa == 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 == null)
                        {
                            helper.Error("SecurityAttribute attribute type is null");
                            fqn = string.Empty;
                        }
                        else
                        {
                            fqn = attrType.AssemblyQualifiedName;
                        }
                        Write(writer, fqn);

                        var namedArgsBlob = CustomAttributeWriter.Write(this, sa.NamedArguments);
                        if (namedArgsBlob.Length > 0x1FFFFFFF)
                        {
                            helper.Error("Named arguments blob size doesn't fit in 29 bits");
                            namedArgsBlob = new byte[0];
                        }
                        WriteCompressedUInt32(writer, (uint)namedArgsBlob.Length);
                        writer.Write(namedArgsBlob);
                    }

                    return(stream.ToArray());
                }
        }