1

I am using a T4 template to create DTO's for each of my Data Entities, however it is falling over on using IList.

http://pastebin.com/QxtsDJdt

Func<PropertyInfo, bool> scalarProperties = p => !p.PropertyType.GetInterfaces().Any(t => t == typeof(System.Collections.IList) || t == typeof(System.Collections.ICollection));
Func<PropertyInfo, bool> collectionProperties = p => !scalarProperties.Invoke(p);

and

private bool ExportProperty(PropertyInfo p)
{
    return true;
}

I think the section it is falling over on is this, even though IList is an ICollection, the following is not being evaluated to true:

if (ExportProperty(property) && collectionProperties(property))

I am not sure how to debug .tt (T4) files in VS 2010.

The class being generated when a property is an IList is:

public System.Collections.Generic.IList`1[[Namespace.Inspection, Entities, Version=1.0.4168.906, Culture=neutral, PublicKeyToken=null]] Inspections
{
    get; set;
}

When it should be:

    public System.Collections.Generic.IList<Namespace.Inspection> Inspections
    {
        get; set;
    }
Darbio
  • 11,286
  • 12
  • 60
  • 100

1 Answers1

1

The link to PastBin is broken, but what I understand from the question; the problem is similar to the following question "How can I get the correct text definition of a generic type using reflection?". But if you are using Entity Framework, then you can maybe better use POCO or self tracking entities generated from the model, instead of making a translation towards DTOs.

For debugging T4 I just start with coding my logic in a separate class, which I move to the T4 file or call from it. I also installed the free T4 toolbox extension, and at first sight it is helpful, but I just started learning/using code generation. So maybe better solutions or practices exist.

Community
  • 1
  • 1