private void PostMethodBodyRepack()

in ILRepack/IKVMLineIndexer.cs [99:144]


        private void PostMethodBodyRepack(MethodDefinition parent, LineNumberWriter lineNumberWriter)
        {
            if (lineNumberWriter.Count > 0)
            {
                CustomAttribute ca;
                if (lineNumberWriter.Count == 1)
                {
                    ca =
                        new CustomAttribute(lineNumberTableAttributeConstructor1)
                        {
                            ConstructorArguments = { new CustomAttributeArgument(TargetAssemblyMainModule.TypeSystem.UInt16, (ushort)lineNumberWriter.LineNo) }
                        };
                }
                else
                {
                    ca =
                        new CustomAttribute(lineNumberTableAttributeConstructor2)
                        {
                            ConstructorArguments = { new CustomAttributeArgument(new ArrayType(TargetAssemblyMainModule.TypeSystem.Byte), lineNumberWriter.ToArray().Select(b => new CustomAttributeArgument(TargetAssemblyMainModule.TypeSystem.Byte, b)).ToArray()) }
                        };
                }
                parent.CustomAttributes.Add(ca);
                if (fileName != null)
                {
                    var type = parent.DeclaringType;
                    var exist = type.CustomAttributes.FirstOrDefault(x => x.Constructor.DeclaringType.Name == "SourceFileAttribute");
                    if (exist == null)
                    {
                        // put the filename on the type first
                        type.CustomAttributes.Add(new CustomAttribute(sourceFileAttributeConstructor)
                        {
                            ConstructorArguments = { new CustomAttributeArgument(TargetAssemblyMainModule.TypeSystem.String, fileName) }
                        });
                    }
                    else if (fileName != (string)exist.ConstructorArguments[0].Value)
                    {
                        // if already specified on the type, but different (e.g. for partial classes), put the attribute on the method.
                        // Note: attribute isn't allowed for Methods, but that restriction doesn't apply to IL generation (or runtime use)
                        parent.CustomAttributes.Add(new CustomAttribute(sourceFileAttributeConstructor)
                        {
                            ConstructorArguments = { new CustomAttributeArgument(TargetAssemblyMainModule.TypeSystem.String, fileName) }
                        });
                    }
                }
            }
        }