Structural Search to find ViewState assignment

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


    private List<string> UnitsOfMeasure
            if (ViewState["uom"] == null) ViewState["uom"] = new List<string>();
            return (List<string>)ViewState["uom"];
            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?


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.


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


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.


Please sign in to leave a comment.