Latest news for viagra best price in europe

Average Rating: 4.6 out of 5 based on 300 user reviews.

Another "tip/trick" style post, but thought it may prove useful to someone (or so I can find it again later!). . .

Sometimes I find myself needing to map instances/values of one type to another. Viagra best price in europe   for example, on my current project we have an enumeration in our communications layer, and a very similar one in the domain layer.   The reason for this is so we don't have to be referencing the communications layer version all over in the domain code.   So, there is naturally a one to one mapping between these enumerations.

Consider the following enumerations:

enum Polygons
{
    Triangle, 
    Rectangle, 
    Pentagon, 
    Other
}

enum NumSides
{
    Three, 
    Four, 
    Five, 
    More
}

This is the code I usually write to solve this problem:

private Polygons MapShapes( NumSides sides )
{
    switch( sides )
    {
        case NumSides. Three:
            return Polygons. Triangle;
        case NumSides. Four:
  viagra best price in europe           return Polygons. Rectangle;
        case NumSides. Five:
            return Polygons. Pentagon;
        case NumSides. More:
            return Polygons. Other;
        default:
            throw new NotSupportedException(
                string. Format( "Mapping to Polygons from NumSides value {0}
                    is not supported" viagra best price in europe,  sides. ToString() ) );
    }
}

private NumSides MapShapes( Polygons polygon )
{
    switch( polygon )
    {
        case Polygons. Triangle:
            return NumSides. Three;
        case Polygons. Rectangle:
            return NumSides. Four;
        case Polygons. Pentagon:
            return NumSides. Five;
        case Polygons. Other:
            return NumSides. More;
        default:
            throw new NotSupportedException(
                string. Format( "Mapping to NumSides from Polygons value {0}
                    is not supported",  polygon. ToString() ) );
    }
}

It turns out we had 3 said enumerations.   So picture the above, copied 3 times.   This thing was just begging for abstraction!

I came up with a Generic (proper) Map class that you can add mappings to and retrieve the corresponding mapped value of the other type. . . both directions.   Here is the implementation:

public class Map<Type1,  Type2>
{
    private Dictionary<Type1,  Type2> _oneToTwo;
    private Dictionary<Type2,  Type1> _twoToOne;

    public Map()
   [viagra best price in europe]  {
        _oneToTwo = new Dictionary<Type1,  Type2>();
        _twoToOne = new Dictionary<Type2,  Type1>();
    }

    public Map<Type1,  Type2> Add( Type1 value1,  Type2 value2 )
    {
        _oneToTwo. Add( value1,  value2 );
        _twoToOne. Add( value2,  value1 );
        return this;
    }

    public Type1 this[Type2 value]
    {
        get
        {
            if( !_twoToOne. ContainsKey( value ) )
            {
                throw new NotSupportedException(
                    string. Format( "Mapping from type {0} to type {1} with
                                    value {2} is not defined", 
                        typeof( Type2 ). Name, 
                        typeof( Type1 ). Name, 
                        value. ToString() ) );
            }
            return _twoToOne[value];
        }
    }

    public Type2 this[Type1 value]
    {
        get
        {
            if( !_oneToTwo. ContainsKey( value ) )
            {
                throw new NotSupportedException(
                    string. Format( "Mapping from type {0} to type {1} with
                                    value {2} is not defined", 
                        typeof( Type1 ). Name, 
                        typeof( Type2 ). Name, 
                        value. ToString() ) );
            }
            return _oneToTwo[value];
        }
    }
}

And, here it is in action:

Map<NumSides,  Polygons> shapeMap = new Map<NumSides,  Polygons>()
                                    . Add( NumSides. Three,  Polygons. Triangle )
                                    . Add( NumSides. Four,  Polygons. Rectangle )
                                    . Add( NumSides. Five,  Polygons. Pentagon )
                                    . Add( NumSides. More,  Polygons. Other );

// shape1 value is Polygons. Rectangle
Polygons shape1 = shapeMap[NumSides. Four]; 

// shape2 value is NumSides. Three
NumSides shape2 = shapeMap[Polygons. Triangle];

This not only works with enumerations, but any type.   I see an extension to this possibly allowing for a default mapping, and possibly constraining Type1 and Type2 to be IComparable or something like that as well, so you can have more control over your matching than whatever the default matching behavior that the Dictionary uses is.

That's it. . . enjoy!


?? 2008-2016 Legit Express Chemist.