Пример #1
0
 internal static byte[] Write(ICustomAttributeWriterHelper helper, CustomAttribute ca, DataWriterContext context)
 {
     using (var writer = new CustomAttributeWriter(helper, context)) {
         writer.Write(ca);
         return(writer.GetResult());
     }
 }
Пример #2
0
 internal static byte[] Write(ICustomAttributeWriterHelper helper, IList <CANamedArgument> namedArgs, DataWriterContext context)
 {
     using (var writer = new CustomAttributeWriter(helper, context)) {
         writer.Write(namedArgs);
         return(writer.GetResult());
     }
 }
Пример #3
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());
     }
 }
Пример #4
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();
     }
 }
Пример #5
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();
     }
 }
Пример #6
0
        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());
        }
Пример #7
0
        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 = context == 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 = new byte[0];
                        }
                        WriteCompressedUInt32(writer, (uint)namedArgsBlob.Length);
                        writer.Write(namedArgsBlob);
                    }

                    return(stream.ToArray());
                }
        }
Пример #8
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());
 }