Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested generic parameters don't work correctly in the generator #10

Closed
R2D221 opened this issue Dec 9, 2021 · 3 comments
Closed

Nested generic parameters don't work correctly in the generator #10

R2D221 opened this issue Dec 9, 2021 · 3 comments
Assignees

Comments

@R2D221
Copy link

R2D221 commented Dec 9, 2021

I have the following mixin. My end goal is to simplify some collection types, but here I'm just beginning with this:

internal abstract class MyMixin<T> : IReadOnlyCollection<T>, ICollection
{
	protected abstract int MyMixin_Count();

	public int Count => MyMixin_Count();

	int IReadOnlyCollection<T>.Count => MyMixin_Count();

	int ICollection.Count => MyMixin_Count();

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => null!;

	void ICollection.CopyTo(Array array, int index)
	{
		throw new NotImplementedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		throw new System.NotImplementedException();
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		throw new System.NotImplementedException();
	}
}

As you can see there's a type parameter T. But what happens if T itself is generic?

[Mixin(typeof(MyMixin<KeyValuePair<string, string>>))]
public partial class TestObject
{
	protected partial int MyMixin_Count() => 5;
}

The generator should get IReadOnlyCollection<KeyValuePair<string, string>>, but I get this other result:

public partial class TestObject : global::System.Collections.Generic.IReadOnlyCollection<global::System.Collections.Generic.KeyValuePair ` 2>, global::System.Collections.ICollection
{
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Mixin Task", "1.0.52.0")]
    protected partial int MyMixin_Count();
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Mixin Task", "1.0.52.0")]
    public int Count => MyMixin_Count();
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Mixin Task", "1.0.52.0")]
    int global::System.Collections.Generic.IReadOnlyCollection<global::System.Collections.Generic.KeyValuePair ` 2>.Count => MyMixin_Count();
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Mixin Task", "1.0.52.0")]
    int global::System.Collections.ICollection.Count => MyMixin_Count();
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Mixin Task", "1.0.52.0")]
    bool global::System.Collections.ICollection.IsSynchronized => false;
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Mixin Task", "1.0.52.0")]
    object global::System.Collections.ICollection.SyncRoot => null !;
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Mixin Task", "1.0.52.0")]
    void global::System.Collections.ICollection.CopyTo(global::System.Array array, int index)
    {
        throw new global::System.NotImplementedException();
    }

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Mixin Task", "1.0.52.0")]
    global::System.Collections.Generic.IEnumerator<global::System.Collections.Generic.KeyValuePair ` 2> global::System.Collections.Generic.IEnumerable<global::System.Collections.Generic.KeyValuePair ` 2>.GetEnumerator()
    {
        throw new global::System.NotImplementedException();
    }

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Mixin Task", "1.0.52.0")]
    global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
    {
        throw new global::System.NotImplementedException();
    }
}

I get global::System.Collections.Generic.KeyValuePair ` 2 instead of global::System.Collections.Generic.KeyValuePair<global::System.String, global::System.String>

@LokiMidgard LokiMidgard self-assigned this Dec 10, 2021
@LokiMidgard
Copy link
Owner

Sorry I wasn't able to look at this yet. I hope I'll can look at it on the following weekend (no guaranty).

But it seems like I need to build the generic types recursivly....

@R2D221 If you need it soon and have time, you may want to look into it yourself and make a pull request. I think Generics need to be handled in follwoing method:

internal static string GetFullQualifiedName(ISymbol typeSymbol)
{
if (typeSymbol is IArrayTypeSymbol)
{
var arraySymbol = typeSymbol as IArrayTypeSymbol;
return $"{GetFullQualifiedName(arraySymbol.ElementType)}[]";
}
var ns = GetNsName(typeSymbol.ContainingNamespace);
if (!string.IsNullOrWhiteSpace(ns))
return $"{ns}.{typeSymbol.MetadataName}";
return typeSymbol.MetadataName;
}

@LokiMidgard
Copy link
Owner

Sorry it took some time, but it should be fixed now...

@R2D221
Copy link
Author

R2D221 commented Jan 17, 2022

Thanks, I'll give it a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants