Пример #1
0
 /// <summary>
 /// Reads custom attribute named arguments
 /// </summary>
 /// <param name="module">Owner module</param>
 /// <param name="stream">A stream positioned at the the first byte of the CA blob</param>
 /// <param name="numNamedArgs">Number of named arguments to read from <paramref name="stream"/></param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A list of <see cref="CANamedArgument"/>s or <c>null</c> if some error
 /// occurred.</returns>
 internal static List <CANamedArgument> ReadNamedArguments(ModuleDef module, IBinaryReader stream, int numNamedArgs, GenericParamContext gpContext)
 {
     try {
         using (var reader = new CustomAttributeReader(module, stream, false, gpContext))
             return(reader.ReadNamedArguments(numNamedArgs));
     }
     catch (CABlobParserException) {
         return(null);
     }
     catch (IOException) {
         return(null);
     }
 }
        /// <summary>
        ///     Reads the new (.NET 2.0+) DeclSecurity blob format
        /// </summary>
        /// <returns></returns>
        private ThreadSafe.IList <SecurityAttribute> ReadBinaryFormat()
        {
            var numAttrs = (int)reader.ReadCompressedUInt32();
            var list     = ThreadSafeListCreator.Create <SecurityAttribute>(numAttrs);

            for (var i = 0; i < numAttrs; i++)
            {
                var name = ReadUTF8String();
                // Use CA search rules. Some tools don't write the fully qualified name.
                var attrRef      = TypeNameParser.ParseReflection(module, UTF8String.ToSystemStringOrEmpty(name), new CAAssemblyRefFinder(module), gpContext);
                var blobLength   = (int)reader.ReadCompressedUInt32();
                var numNamedArgs = (int)reader.ReadCompressedUInt32();
                var namedArgs    = CustomAttributeReader.ReadNamedArguments(module, reader, numNamedArgs, gpContext);
                if (namedArgs == null)
                {
                    throw new ApplicationException("Could not read named arguments");
                }
                list.Add(new SecurityAttribute(attrRef, namedArgs));
            }

            return(list);
        }
Пример #3
0
 /// <summary>
 /// Reads custom attribute named arguments
 /// </summary>
 /// <param name="module">Owner module</param>
 /// <param name="stream">A stream positioned at the the first byte of the CA blob</param>
 /// <param name="numNamedArgs">Number of named arguments to read from <paramref name="stream"/></param>
 /// <returns>A list of <see cref="CANamedArgument"/>s or <c>null</c> if some error
 /// occurred.</returns>
 internal static List<CANamedArgument> ReadNamedArguments(ModuleDef module, IBinaryReader stream, int numNamedArgs)
 {
     try {
         using (var reader = new CustomAttributeReader(module, stream, false))
             return reader.ReadNamedArguments(numNamedArgs);
     }
     catch (CABlobParserException) {
         return null;
     }
     catch (IOException) {
         return null;
     }
 }