TypeDefinition.FullName is incompatible with Type.FullName on nested classes. #150

Closed
opened 2014-01-03 15:17:13 -06:00 by RobertZenz · 4 comments
RobertZenz commented 2014-01-03 15:17:13 -06:00 (Migrated from github.com)

Nested classes are represented with a "+" by Type.FullName but TypeDefinition.FullName uses "/". Is that an intended difference?

First of all, consider the following code:

using System;
using Mono.Cecil;

namespace CecilTest
{
    class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Type.FullName:");
            Console.WriteLine("\tParent: " + typeof(Parent).FullName);
            Console.WriteLine("\tParent.Child: " + typeof(Parent.Child).FullName);

            Console.WriteLine("Cecil:");
            // Load this very assembly.
            AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(System.Reflection.Assembly.GetExecutingAssembly().Location);
            foreach(TypeDefinition type in assembly.MainModule.GetTypes())
            {
                Console.WriteLine("\t" + type.FullName);
            }
        }
    }

    // These are our reference classes.
    public class Parent
    {
        public class Child
        {
        }
    }
}

The output of shown program:

Type.FullName:
    Parent: CecilTest.Parent
    Parent.Child: CecilTest.Parent+Child
Cecil:
    <Module>
    CecilTest.Program
    CecilTest.Parent
    CecilTest.Parent/Child

So, is that by design? Should those match?

My usecase was that I use Mono.Linker which uses a configuration file which looks like this:

<linker>
    <type fullname="name" />
</linker>

I generate these on the fly via attributes...turned out the Mono.Linker, using Cecil, expected the Cecil variant of Type.FullName. That the documentation failed to mention is of course a problem on the end of Mono.Linker, but the difference stroke me as odd.

Nested classes are represented with a "+" by `Type.FullName` but `TypeDefinition.FullName` uses "/". Is that an intended difference? First of all, consider the following code: ``` using System; using Mono.Cecil; namespace CecilTest { class Program { public static void Main(string[] args) { Console.WriteLine("Type.FullName:"); Console.WriteLine("\tParent: " + typeof(Parent).FullName); Console.WriteLine("\tParent.Child: " + typeof(Parent.Child).FullName); Console.WriteLine("Cecil:"); // Load this very assembly. AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(System.Reflection.Assembly.GetExecutingAssembly().Location); foreach(TypeDefinition type in assembly.MainModule.GetTypes()) { Console.WriteLine("\t" + type.FullName); } } } // These are our reference classes. public class Parent { public class Child { } } } ``` The output of shown program: ``` Type.FullName: Parent: CecilTest.Parent Parent.Child: CecilTest.Parent+Child Cecil: <Module> CecilTest.Program CecilTest.Parent CecilTest.Parent/Child ``` So, is that by design? Should those match? My usecase was that I use Mono.Linker which uses a configuration file which looks like this: ``` <linker> <type fullname="name" /> </linker> ``` I generate these on the fly via attributes...turned out the Mono.Linker, using Cecil, expected the Cecil variant of `Type.FullName`. That the documentation failed to mention is of course a problem on the end of Mono.Linker, but the difference stroke me as odd.
jbevain commented 2014-01-03 15:26:32 -06:00 (Migrated from github.com)

Yes that's intended. Cecil uses the ECMA-335 naming for types.

Yes that's intended. Cecil uses the ECMA-335 naming for types.
marko-vasic commented 2017-02-11 11:34:29 -06:00 (Migrated from github.com)

Is there some API for converting
name from TypeDefinition.FullName
to one matching Type.FullName,
or vice versa?
How would you go with making those two match?

Is there some API for converting name from TypeDefinition.FullName to one matching Type.FullName, or vice versa? How would you go with making those two match?
Ziflin commented 2017-03-04 22:22:41 -06:00 (Migrated from github.com)

Just ran into this as well. Might be nice to have it documented. Is the + to / the only difference?

Just ran into this as well. Might be nice to have it documented. Is the + to / the only difference?
jbevain commented 2017-03-06 12:56:53 -06:00 (Migrated from github.com)

@marko-vasic I don't think we have an API for that. We have an internal API to convert a Type FullName to a TypeReference (TypeParser) but that's about it.

@Ziflin basically the ECMA-335 is the (somewhat large) documentation that was used here. I agree it would be nice to sum it up in a wiki page.

@marko-vasic I don't think we have an API for that. We have an internal API to convert a Type FullName to a TypeReference (TypeParser) but that's about it. @Ziflin basically the ECMA-335 is the (somewhat large) documentation that was used here. I agree it would be nice to sum it up in a wiki page.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil#150
No description provided.