سؤال

Given the following class:

public class Post
{
    public Post()
    {
        Tags = new List<Tag>();
    }

    public int Id { get; set; }

    // ...more properties...

    public virtual ICollection<Tag> Tags { get; set; }
}

and my ps1 entry code:

$model = Get-ProjectType $EntityName -Project $Project

Add-ProjectItemViaTemplate $controllerName -Template ControllerTemplate `
    -Model @{ Namespace = $namespace; T = [MarshalByRefObject]$model; } `
    -SuccessMessage "Added ControllerTemplate output at {0}" `
    -TemplateFolders $TemplateFolders -Project $Project -CodeLanguage $CodeLanguage -Force:$Force

where $model is the Post class.

how would i gain access to "Tag" object properties?

I have "Tags" ICollection as a EnvDTE.CodeTypeRef.

I noticed that most of the mvcscaffolding is using Get-RelatedEntities to unwrap the generics - is this the only way to access the Tag properties?

هل كانت مفيدة؟

المحلول

Look at the first part of this video. It will show you how to collect properties from classes in Visual Studio.

EDIT:

If you do not have the time to view the video... Just use this snippet in the package manager console.

(Get-ProjectType Tag).Children | Where-Object{$.Kind -eq 4} | ForEach{$}

I think it is easier to find all properties with powershell and then send it into the T4, it´s hard work to use C# in the T4 to collect information.

T4Scaffolding in Visual Studio

Regards Uffe

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top