Skip to content

Conditionally applying aspect #30

Answered by gfraiteur
lukedays asked this question in Q&A
Discussion options

You must be logged in to vote

This code (open in online sandbox) works for me:

    public override dynamic? OverrideMethod()
    {
        // Builds the caching string.
        var cacheKey = GetCachingKeyFormattingString().ToValue();

        var cacheParameter = meta.Target.Parameters.SingleOrDefault( p => p.Name == "skipCache" );

        if ( cacheParameter != null )
        {
            if ( (bool) cacheParameter.Value )
            {
                return meta.Proceed();
            }
        }

        // Cache lookup.
        if ( SampleCache.Cache.TryGetValue( cacheKey, out object value ) )
        {
            // Cache hit.
            return value;
        }
        else
        {
            // Cache mi…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@lukedays
Comment options

@gfraiteur
Comment options

Answer selected by gfraiteur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants