Problems finding property usages in EPi7 WebForms

In EPiServer 7 Web Forms project I wanted to find all usages of a regular property.

public virtual ContentArea RightContentArea { get; set; }

But I failed – „Usages of ‚RightContentArea ‚ were not found.”. (I am using Resharper for that.)
It is very clear that when you reference PropertyName by string you are screwed when you want to find it this way. Renamings are not possible as well. Very bad thing.

<EPiServer:Property runat="server" PropertyName="RightContentArea"></EPiServer:Property> 

There is workaround for this. You have to put below code in a base TemplateView for all your page templates. I am not up to date with conventions in Web Forms so I will just put the code. Yes, the method name is just underscore. Why it’s underscore is out the topic of this post. Give it other name when you like.

protected string _(Expression<Func<T, object>> propertyExpression)
    return CurrentPage.GetPropertyName(propertyExpression);


<EPiServer:Property runat="server" PropertyName="<%#_(m => m.RightContentArea) %>"></EPiServer:Property>

The same is for blocks

public abstract class SiteBlockControlBase<TBlock> : BlockControlBase<TBlock> where TBlock : SiteBlockData
    protected string _(Expression<Func<TBlock, object>> propertyExpression)
        return CurrentBlock.GetPropertyName(propertyExpression);

Credits to Maciej Grzyb.

Ten wpis został opublikowany w kategorii EpiServer i oznaczony tagami , , , . Dodaj zakładkę do bezpośredniego odnośnika.

2 odpowiedzi na „Problems finding property usages in EPi7 WebForms

  1. Daniel Ovaska pisze:

    I share your concern about not being able to refactor it easily.
    I normally solve it in a webforms project by projecting the strongly typed properties => page specific viewmodel with automapper (or linq projections sometimes). Then the viewmodel object for the page has everything in a prepared presentation form including css classes and similar. Writing the result in the aspx is then normally something like:

    The only logic I allow in aspx or view is loops and if statements to check if a property is true/false. It has both pros and cons as well of course…
    The pro is mainly that you get an extra chance to prepare all information that will actually be presented so you get rid of all nasty logic in aspx with ternary operators and similar. You can unit test the transformations if you have a separate objekt responsible for creating the view. I normally don’t though 🙂
    The con being mainly that you need to transform you domain objects / EPi properties => viewmodel. With automapper I feel that the pros outweigh the cons normally…especially if you have multiple datasources and not just regular page properties.

    MVC and Razor makes this much prettier…

  2. Daniel Ovaska pisze:

    something like:
    Code above got censured…just use the standard response.write shortcut for aspx to output standard properties. Use : to html.encode if you got .NET 4.0.

Możliwość komentowania jest wyłączona.