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?

3 comments

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.

0

Unfortunately I want it to find those that are NOT value types, and there does not appear to be a System.ReferenceType

0

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.

0

Please sign in to leave a comment.