3 Replies Last post: Nov 25, 2013 8:23 PM by Matt Ellis  
David Roberts Newbie 37 posts since
Jan 26, 2011
Currently Being Moderated

Oct 30, 2013 7:26 PM

Structural Search to find ViewState assignment

I'd like to create a structural search to find where non-value types are assigned to ViewState,

 

eg

    private List<string> UnitsOfMeasure
    {
        get
        {
            if (ViewState["uom"] == null) ViewState["uom"] = new List<string>();
            return (List<string>)ViewState["uom"];
        }
        set
        {
            ViewState["uom"] = value;
        }
    }

 

The following finds it

ViewState[$key$] = $value$

 

but also finds lots where the type being assigned is a string or other value type.

I want to identify these so that I can check they are serialisable.

 

I have $value$ as an identifier, but if I could have it as an expression of type "[^String|Guid|int|etc]"

or some such syntax?

 

Perhaps I need to investigate writing a plugin for this?

Matt Ellis Novice 305 posts since
Jul 5, 2009
Currently Being Moderated
Nov 4, 2013 5:51 PM in response to: David Roberts
Re: Structural Search to find ViewState assignment

You can make the value argument an expression which is of type System.ValueType or derived, and it will find value types such as int, enums, etc.

Matt Ellis Novice 305 posts since
Jul 5, 2009
Currently Being Moderated
Nov 25, 2013 8:23 PM in response to: David Roberts
Re: Structural Search to find ViewState assignment

Ah, missed the "not", sorry!

 

Unfortunately, you can't do this with SSR as it stands. I also haven't looked into whether or not it's possible to extend the SSR subsystem to allow custom placeholders. You could start by looking at adding an editor to the dialog, by implementing IPlaceholderEditor and decorating it with [PlaceholderEditor(typeof(CSharpLanguage))], and then implementing a couple of classes to implement IPlaceholderEditorForm and something like C#'s TypePlaceholder. I think the fun happens either in ITypeMatcher or IPlaceholderMatcher.

More Like This

  • Retrieving data ...