Ejemplo n.º 1
0
 public CustomAttributeOptions(CustomAttribute ca)
 {
     this.RawData = ca.RawData;
     this.Constructor = ca.Constructor;
     this.ConstructorArguments.AddRange(ca.ConstructorArguments.Select(a => a.Clone()));
     this.NamedArguments.AddRange(ca.NamedArguments.Select(a => a.Clone()));
 }
Ejemplo n.º 2
0
        CustomAttribute Read(ICustomAttributeType ctor)
        {
            var methodSig = ctor == null ? null : ctor.MethodSig;

            if (methodSig == null)
            {
                throw new CABlobParserException("ctor is null or not a method");
            }

            var mrCtor = ctor as MemberRef;

            if (mrCtor != null)
            {
                var owner = mrCtor.Class as TypeSpec;
                if (owner != null)
                {
                    var gis = owner.TypeSig as GenericInstSig;
                    if (gis != null)
                    {
                        genericArguments = new GenericArguments();
                        genericArguments.PushTypeArgs(gis.GenericArguments);
                    }
                }
            }

            bool isEmpty = methodSig.Params.Count == 0 && reader.Position == reader.Length;

            if (!isEmpty && reader.ReadUInt16() != 1)
            {
                throw new CABlobParserException("Invalid CA blob prolog");
            }

            var ctorArgs = new List <CAArgument>(methodSig.Params.Count);

            foreach (var arg in methodSig.Params.GetSafeEnumerable())
            {
                ctorArgs.Add(ReadFixedArg(FixTypeSig(arg)));
            }

            // Some tools don't write the next ushort if there are no named arguments.
            int numNamedArgs = reader.Position == reader.Length ? 0 : reader.ReadUInt16();
            var namedArgs    = ReadNamedArguments(numNamedArgs);

            // verifyReadAllBytes will be set when we guess the underlying type of an enum.
            // To make sure we guessed right, verify that we read all bytes.
            if (verifyReadAllBytes && reader.Position != reader.Length)
            {
                throw new CABlobParserException("Not all CA blob bytes were read");
            }

            return(new CustomAttribute(ctor, ctorArgs, namedArgs, CloneBlobReader(reader)));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Reads a custom attribute
 /// </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="ctor">Custom attribute constructor</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance or <c>null</c> if one of the
 /// args is <c>null</c> or if we failed to parse the CA blob</returns>
 public static CustomAttribute Read(ModuleDef module, IBinaryReader stream, ICustomAttributeType ctor, GenericParamContext gpContext)
 {
     if (stream == null || ctor == null)
     {
         return(null);
     }
     try {
         using (var reader = new CustomAttributeReader(module, stream, gpContext))
             return(reader.Read(ctor));
     }
     catch (CABlobParserException) {
         return(null);
     }
     catch (IOException) {
         return(null);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Reads a custom attribute
 /// </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="ctor">Custom attribute constructor</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance or <c>null</c> if one of the
 /// args is <c>null</c> or if we failed to parse the CA blob</returns>
 public static CustomAttribute Read(ModuleDef module, IImageStream stream, ICustomAttributeType ctor)
 {
     if (stream == null || ctor == null)
     {
         return(null);
     }
     try {
         using (var reader = new CustomAttributeReader(module, stream, ctor))
             return(reader.Read());
     }
     catch (CABlobParserException) {
         return(null);
     }
     catch (IOException) {
         return(null);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Reads a custom attribute
 /// </summary>
 /// <param name="readerModule">Reader module</param>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="offset">Offset of custom attribute in the #Blob stream</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance</returns>
 public static CustomAttribute Read(ModuleDefMD readerModule, ICustomAttributeType ctor, uint offset)
 {
     if (ctor == null)
     {
         return(CreateEmpty(ctor));
     }
     using (var reader = new CustomAttributeReader(readerModule, ctor, offset)) {
         try {
             return(reader.Read());
         }
         catch (CABlobParserException) {
             return(new CustomAttribute(ctor, reader.GetRawBlob()));
         }
         catch (IOException) {
             return(new CustomAttribute(ctor, reader.GetRawBlob()));
         }
     }
 }
        static MethodSig GetMethodSig(ICustomAttributeType ctor)
        {
            var mrCtor = ctor as MemberRef;

            if (mrCtor != null)
            {
                return(mrCtor.MethodSig);
            }

            var mdCtor = ctor as MethodDef;

            if (mdCtor != null)
            {
                return(mdCtor.MethodSig);
            }

            return(null);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Reads a custom attribute
 /// </summary>
 /// <param name="readerModule">Reader module</param>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="offset">Offset of custom attribute in the #Blob stream</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance</returns>
 public static CustomAttribute Read(ModuleDefMD readerModule, ICustomAttributeType ctor, uint offset, GenericParamContext gpContext)
 {
     using (var reader = new CustomAttributeReader(readerModule, offset, gpContext)) {
         try {
             if (ctor == null)
             {
                 return(reader.CreateRaw(ctor));
             }
             return(reader.Read(ctor));
         }
         catch (CABlobParserException) {
             return(reader.CreateRaw(ctor));
         }
         catch (IOException) {
             return(reader.CreateRaw(ctor));
         }
     }
 }
Ejemplo n.º 8
0
        private uint AddCustomAttributeType(ICustomAttributeType constructor)
        {
            if (constructor is null || !AssertIsImported(constructor))
            {
                return(0);
            }

            var token = constructor.MetadataToken.Table switch
            {
                TableIndex.Method => GetMethodDefinitionToken(constructor as MethodDefinition),
                TableIndex.MemberRef => GetMemberReferenceToken(constructor as MemberReference),
                _ => throw new ArgumentOutOfRangeException(nameof(constructor))
            };

            return(Metadata.TablesStream
                   .GetIndexEncoder(CodedIndex.CustomAttributeType)
                   .EncodeToken(token));
        }
Ejemplo n.º 9
0
 static CustomAttribute CreateEmpty(ICustomAttributeType ctor)
 {
     return new CustomAttribute(ctor, new byte[0]);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Creates a new custom attribute.
 /// </summary>
 /// <param name="constructor">The constructor of the attribute to call.</param>
 /// <param name="signature">The signature containing the arguments to the constructor.</param>
 public CustomAttribute(ICustomAttributeType constructor, CustomAttributeSignature signature)
     : this(new MetadataToken(TableIndex.CustomAttribute, 0))
 {
     Constructor = constructor;
     Signature   = signature;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Reads a custom attribute
 /// </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="ctor">Custom attribute constructor</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance</returns>
 public static CustomAttribute Read(ModuleDef module, IBinaryReader stream, ICustomAttributeType ctor)
 {
     return(Read(module, stream, ctor, new GenericParamContext()));
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="arguments">Constructor arguments or <c>null</c> if none</param>
 public CustomAttribute(ICustomAttributeType ctor, ThreadSafe.IEnumerable <CAArgument> arguments)
     : this(ctor, arguments, null)
 {
 }
        /// <summary>
        /// Reads a single custom attribute signature from the input stream.
        /// </summary>
        /// <param name="parentModule">The module that contains the attribute signature.</param>
        /// <param name="ctor">The constructor that was called.</param>
        /// <param name="reader">The input stream.</param>
        /// <returns>The signature.</returns>
        /// <exception cref="FormatException">Occurs when the input stream does not point to a valid signature.</exception>
        public static CustomAttributeSignature FromReader(ModuleDefinition parentModule, ICustomAttributeType ctor, IBinaryStreamReader reader)
        {
            ushort prologue = reader.ReadUInt16();

            if (prologue != CustomAttributeSignaturePrologue)
            {
                throw new FormatException("Input stream does not point to a valid custom attribute signature.");
            }

            var result = new CustomAttributeSignature();

            // Read fixed arguments.
            var parameterTypes = ctor.Signature.ParameterTypes;

            for (int i = 0; i < parameterTypes.Count; i++)
            {
                var argument = CustomAttributeArgument.FromReader(parentModule, parameterTypes[i], reader);
                result.FixedArguments.Add(argument);
            }

            // Read named arguments.
            ushort namedArgumentCount = reader.ReadUInt16();

            for (int i = 0; i < namedArgumentCount; i++)
            {
                var argument = CustomAttributeNamedArgument.FromReader(parentModule, reader);
                result.NamedArguments.Add(argument);
            }

            return(result);
        }
		CustomAttributeReader(ModuleDef module, IImageStream reader, ICustomAttributeType ctor) {
			this.module = module;
			this.reader = reader;
			this.ownReader = false;
			this.ctor = ctor;
			this.genericArguments = null;
			this.recursionCounter = new RecursionCounter();
			this.verifyReadAllBytes = false;
		}
Ejemplo n.º 15
0
 static MethodSig GetMethodSig(ICustomAttributeType ctor)
 {
     return(ctor == null ? null : ctor.MethodSig);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="arguments">Constructor arguments or <c>null</c> if none</param>
 /// <param name="namedArguments">Named arguments or <c>null</c> if none</param>
 /// <param name="blobReader">A reader that returns the original custom attribute blob data</param>
 public CustomAttribute(ICustomAttributeType ctor, IEnumerable<CAArgument> arguments, IEnumerable<CANamedArgument> namedArguments, IBinaryReader blobReader)
 {
     this.ctor = ctor;
     this.arguments = arguments == null ? ThreadSafeListCreator.Create<CAArgument>() : ThreadSafeListCreator.Create<CAArgument>(arguments);
     this.namedArguments = namedArguments == null ? ThreadSafeListCreator.Create<CANamedArgument>() : ThreadSafeListCreator.Create<CANamedArgument>(namedArguments);
     this.blobReader = blobReader;
 }
 static MethodSig GetMethodSig(ICustomAttributeType ctor) => ctor?.MethodSig;
Ejemplo n.º 18
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="arguments">Constructor arguments. The list is now owned by this instance.</param>
 /// <param name="namedArguments">Named arguments. The list is now owned by this instance.</param>
 internal CustomAttribute(ICustomAttributeType ctor, List <CAArgument> arguments, List <CANamedArgument> namedArguments)
 {
     this.ctor           = ctor;
     this.arguments      = arguments == null ? new List <CAArgument>() : arguments;
     this.namedArguments = namedArguments == null ? new List <CANamedArgument>() : namedArguments;
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="arguments">Constructor arguments or <c>null</c> if none</param>
 /// <param name="namedArguments">Named arguments or <c>null</c> if none</param>
 public CustomAttribute(ICustomAttributeType ctor, IEnumerable <CAArgument> arguments, IEnumerable <CANamedArgument> namedArguments)
 {
     this.ctor           = ctor;
     this.arguments      = arguments == null ? new List <CAArgument>() : new List <CAArgument>(arguments);
     this.namedArguments = namedArguments == null ? new List <CANamedArgument>() : new List <CANamedArgument>(namedArguments);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Reads a custom attribute
 /// </summary>
 /// <param name="readerModule">Reader module</param>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="offset">Offset of custom attribute in the #Blob stream</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance</returns>
 public static CustomAttribute Read(ModuleDefMD readerModule, ICustomAttributeType ctor, uint offset)
 {
     if (ctor == null)
         return CreateEmpty(ctor);
     using (var reader = new CustomAttributeReader(readerModule, offset)) {
         try {
             return reader.Read(ctor);
         }
         catch (CABlobParserException) {
             return new CustomAttribute(ctor, reader.GetRawBlob());
         }
         catch (IOException) {
             return new CustomAttribute(ctor, reader.GetRawBlob());
         }
     }
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ctor">Custom attribute constructor</param>
 public CustomAttribute(ICustomAttributeType ctor)
     : this(ctor, null, null, null)
 {
 }
Ejemplo n.º 22
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="ctor">Custom attribute constructor</param>
		/// <param name="arguments">Constructor arguments. The list is now owned by this instance.</param>
		/// <param name="namedArguments">Named arguments. The list is now owned by this instance.</param>
		internal CustomAttribute(ICustomAttributeType ctor, List<CAArgument> arguments, List<CANamedArgument> namedArguments) {
			this.ctor = ctor;
			this.arguments = arguments == null ? new List<CAArgument>() : arguments;
			this.namedArguments = namedArguments == null ? new List<CANamedArgument>() : namedArguments;
		}
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="namedArguments">Named arguments or <c>null</c> if none</param>
 public CustomAttribute(ICustomAttributeType ctor, ThreadSafe.IEnumerable <CANamedArgument> namedArguments)
     : this(ctor, null, namedArguments)
 {
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="arguments">Constructor arguments. The list is now owned by this instance.</param>
 /// <param name="namedArguments">Named arguments. The list is now owned by this instance.</param>
 /// <param name="blobReader">A reader that returns the original custom attribute blob data</param>
 internal CustomAttribute(ICustomAttributeType ctor, List<CAArgument> arguments, List<CANamedArgument> namedArguments, IBinaryReader blobReader)
 {
     this.ctor = ctor;
     this.arguments = arguments == null ? ThreadSafeListCreator.Create<CAArgument>() : ThreadSafeListCreator.MakeThreadSafe(arguments);
     this.namedArguments = namedArguments == null ? ThreadSafeListCreator.Create<CANamedArgument>() : ThreadSafeListCreator.MakeThreadSafe(namedArguments);
     this.blobReader = blobReader;
 }
Ejemplo n.º 25
0
 static CustomAttribute CreateEmpty(ICustomAttributeType ctor)
 {
     return(new CustomAttribute(ctor, new byte[0]));
 }
		CustomAttributeReader(ModuleDefMD readerModule, ICustomAttributeType ctor, uint offset) {
			this.module = readerModule;
			this.reader = readerModule.BlobStream.CreateStream(offset);
			this.ownReader = true;
			this.ctor = ctor;
			this.genericArguments = null;
			this.recursionCounter = new RecursionCounter();
			this.verifyReadAllBytes = false;
		}
Ejemplo n.º 27
0
		/// <summary>
		/// Reads a custom attribute
		/// </summary>
		/// <param name="readerModule">Reader module</param>
		/// <param name="ctor">Custom attribute constructor</param>
		/// <param name="offset">Offset of custom attribute in the #Blob stream</param>
		/// <param name="gpContext">Generic parameter context</param>
		/// <returns>A new <see cref="CustomAttribute"/> instance</returns>
		public static CustomAttribute Read(ModuleDefMD readerModule, ICustomAttributeType ctor, uint offset, GenericParamContext gpContext) {
			using (var reader = new CustomAttributeReader(readerModule, offset, gpContext)) {
				try {
					if (ctor == null)
						return reader.CreateRaw(ctor);
					return reader.Read(ctor);
				}
				catch (CABlobParserException) {
					return reader.CreateRaw(ctor);
				}
				catch (IOException) {
					return reader.CreateRaw(ctor);
				}
			}
		}
Ejemplo n.º 28
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="rawData">Raw custom attribute blob</param>
 public CustomAttribute(ICustomAttributeType ctor, byte[] rawData)
     : this(ctor, null, null, null)
 {
     this.rawData = rawData;
 }
Ejemplo n.º 29
0
		CustomAttribute CreateRaw(ICustomAttributeType ctor) {
			return new CustomAttribute(ctor, GetRawBlob());
		}
Ejemplo n.º 30
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="arguments">Constructor arguments or <c>null</c> if none</param>
 /// <param name="namedArguments">Named arguments or <c>null</c> if none</param>
 public CustomAttribute(ICustomAttributeType ctor, IEnumerable <CAArgument> arguments, IEnumerable <CANamedArgument> namedArguments)
     : this(ctor, arguments, namedArguments, null)
 {
 }
Ejemplo n.º 31
0
		/// <summary>
		/// Reads a custom attribute
		/// </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="ctor">Custom attribute constructor</param>
		/// <returns>A new <see cref="CustomAttribute"/> instance</returns>
		public static CustomAttribute Read(ModuleDef module, IBinaryReader stream, ICustomAttributeType ctor) {
			return Read(module, stream, ctor, new GenericParamContext());
		}
		static MethodSig GetMethodSig(ICustomAttributeType ctor) {
			return ctor == null ? null : ctor.MethodSig;
		}
Ejemplo n.º 33
0
		/// <summary>
		/// Reads a custom attribute
		/// </summary>
		/// <param name="module">Owner module</param>
		/// <param name="caBlob">CA blob</param>
		/// <param name="ctor">Custom attribute constructor</param>
		/// <param name="gpContext">Generic parameter context</param>
		/// <returns>A new <see cref="CustomAttribute"/> instance</returns>
		public static CustomAttribute Read(ModuleDef module, byte[] caBlob, ICustomAttributeType ctor, GenericParamContext gpContext) {
			return Read(module, MemoryImageStream.Create(caBlob), ctor, gpContext);
		}
Ejemplo n.º 34
0
 /// <summary>
 /// Reads a custom attribute
 /// </summary>
 /// <param name="readerModule">Reader module</param>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="offset">Offset of custom attribute in the #Blob stream</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance</returns>
 public static CustomAttribute Read(ModuleDefMD readerModule, ICustomAttributeType ctor, uint offset)
 {
     return(Read(readerModule, ctor, offset, new GenericParamContext()));
 }
Ejemplo n.º 35
0
		/// <summary>
		/// Reads a custom attribute
		/// </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="ctor">Custom attribute constructor</param>
		/// <param name="gpContext">Generic parameter context</param>
		/// <returns>A new <see cref="CustomAttribute"/> instance</returns>
		public static CustomAttribute Read(ModuleDef module, IBinaryReader stream, ICustomAttributeType ctor, GenericParamContext gpContext) {
			using (var reader = new CustomAttributeReader(module, stream, gpContext)) {
				try {
					if (stream == null || ctor == null)
						return reader.CreateRaw(ctor);
					return reader.Read(ctor);
				}
				catch (CABlobParserException) {
					return reader.CreateRaw(ctor);
				}
				catch (IOException) {
					return reader.CreateRaw(ctor);
				}
			}
		}
Ejemplo n.º 36
0
 CustomAttribute CreateRaw(ICustomAttributeType ctor)
 {
     return(new CustomAttribute(ctor, GetRawBlob()));
 }
Ejemplo n.º 37
0
		/// <summary>
		/// Reads a custom attribute
		/// </summary>
		/// <param name="readerModule">Reader module</param>
		/// <param name="ctor">Custom attribute constructor</param>
		/// <param name="offset">Offset of custom attribute in the #Blob stream</param>
		/// <returns>A new <see cref="CustomAttribute"/> instance</returns>
		public static CustomAttribute Read(ModuleDefMD readerModule, ICustomAttributeType ctor, uint offset) {
			return Read(readerModule, ctor, offset, new GenericParamContext());
		}
Ejemplo n.º 38
0
 /// <summary>
 /// Reads a custom attribute
 /// </summary>
 /// <param name="module">Owner module</param>
 /// <param name="caBlob">CA blob</param>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance</returns>
 public static CustomAttribute Read(ModuleDef module, byte[] caBlob, ICustomAttributeType ctor, GenericParamContext gpContext)
 {
     return(Read(module, MemoryImageStream.Create(caBlob), ctor, gpContext));
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="rawData">Raw custom attribute blob</param>
 public CustomAttribute(ICustomAttributeType ctor, byte[] rawData)
     : this(ctor, null, null, null)
 {
     this.rawData = rawData;
 }
Ejemplo n.º 40
0
 /// <summary>
 /// Reads a custom attribute
 /// </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="ctor">Custom attribute constructor</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance or <c>null</c> if one of the
 /// args is <c>null</c> or if we failed to parse the CA blob</returns>
 public static CustomAttribute Read(ModuleDef module, IBinaryReader stream, ICustomAttributeType ctor)
 {
     if (stream == null || ctor == null)
         return null;
     try {
         using (var reader = new CustomAttributeReader(module, stream))
             return reader.Read(ctor);
     }
     catch (CABlobParserException) {
         return null;
     }
     catch (IOException) {
         return null;
     }
 }
Ejemplo n.º 41
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ctor">Custom attribute constructor</param>
 public CustomAttribute(ICustomAttributeType ctor)
     : this(ctor, null, null, null)
 {
 }
Ejemplo n.º 42
0
        CustomAttribute Read(ICustomAttributeType ctor)
        {
            var methodSig = ctor == null ? null : ((IMethodDefOrRef)ctor).MethodSig;
            if (methodSig == null)
                throw new CABlobParserException("ctor is null or not a method");

            var mrCtor = ctor as MemberRef;
            if (mrCtor != null) {
                var owner = mrCtor.Class as TypeSpec;
                if (owner != null) {
                    var gis = owner.TypeSig as GenericInstSig;
                    if (gis != null) {
                        genericArguments = new GenericArguments();
                        genericArguments.PushTypeArgs(gis.GenericArguments);
                    }
                }
            }

            bool isEmpty = methodSig.Params.Count == 0 && reader.Position == reader.Length;
            if (!isEmpty && reader.ReadUInt16() != 1)
                throw new CABlobParserException("Invalid CA blob prolog");

            var ctorArgs = new List<CAArgument>(methodSig.Params.Count);
            foreach (var arg in methodSig.Params.GetSafeEnumerable())
                ctorArgs.Add(ReadFixedArg(FixTypeSig(arg)));

            // Some tools don't write the next ushort if there are no named arguments.
            int numNamedArgs = reader.Position == reader.Length ? 0 : reader.ReadUInt16();
            var namedArgs = ReadNamedArguments(numNamedArgs);

            // verifyReadAllBytes will be set when we guess the underlying type of an enum.
            // To make sure we guessed right, verify that we read all bytes.
            if (verifyReadAllBytes && reader.Position != reader.Length)
                throw new CABlobParserException("Not all CA blob bytes were read");

            return new CustomAttribute(ctor, ctorArgs, namedArgs);
        }
Ejemplo n.º 43
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="arguments">Constructor arguments or <c>null</c> if none</param>
 /// <param name="namedArguments">Named arguments or <c>null</c> if none</param>
 public CustomAttribute(ICustomAttributeType ctor, IEnumerable<CAArgument> arguments, IEnumerable<CANamedArgument> namedArguments)
     : this(ctor, arguments, namedArguments, null)
 {
 }
		static MethodSig GetMethodSig(ICustomAttributeType ctor) {
			var mrCtor = ctor as MemberRef;
			if (mrCtor != null)
				return mrCtor.MethodSig;

			var mdCtor = ctor as MethodDef;
			if (mdCtor != null)
				return mdCtor.MethodSig;

			return null;
		}
Ejemplo n.º 45
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="ctor">Custom attribute constructor</param>
		/// <param name="arguments">Constructor arguments or <c>null</c> if none</param>
		/// <param name="namedArguments">Named arguments or <c>null</c> if none</param>
		public CustomAttribute(ICustomAttributeType ctor, IEnumerable<CAArgument> arguments, IEnumerable<CANamedArgument> namedArguments) {
			this.ctor = ctor;
			this.arguments = arguments == null ? new List<CAArgument>() : new List<CAArgument>(arguments);
			this.namedArguments = namedArguments == null ? new List<CANamedArgument>() : new List<CANamedArgument>(namedArguments);
		}