How To Make Your Own Viagra

4Jun/103

Muscle Relaxants > Requip 0.25mg Pills (Generic) > 360 Pills > $566.00

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 This week I ran into wanting to use C# 4.0 optional parameters, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 but wanted StructureMap (my IoC tool of choice) to respect the default value specified for those optional parameters.

The Problem

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 In this example, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 we’ll be pulling a command out of the container.  The important part is the optional constructor parameter (level), muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 and it’s default value (Level.Info).

public class LogCommand

{

    IDestination _destination;

    Level _level;

 

    public LogCommand(

        IDestination destination, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 Level level = Level.Info)

    {

        _destination = destination;

        _level = level;

    }

 

    /* logging code here */

}

 

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 Here is your basic usage, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 but doesn’t work since StructureMap doesn’t know how to take advantage of the optional parameters with default values.

var container = new Container(config =>

{

    config.Scan(scanner =>

    {

        scanner.TheCallingAssembly();

        scanner.AddAllTypesOf<IDestination>();

        scanner.WithDefaultConventions();

    });

});

 

var logCommand = container.GetInstance<LogCommand>();

 

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 The last line results in an exception because StructureMap doesn’t know how to fill in the level parameter.

The Solution

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 We can solve this by adding a new convention.  One that adds information about default constructor arguments.  Here is the implementation of the convention:

public class DefaultCtorParameterConvention : IRegistrationConvention

{

    public void Process(Type type, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 Registry registry)

    {

        if(type.IsAbstract || type.IsEnum)

            return;

 

        var ctor = type.GetGreediestCtor();

 

        if(!ctor.HasOptionalParameters())

            return;

 

        var inst = registry.For(type).Use(type);

 

        foreach(var param in ctor.GetOptionalParameters())

            inst.Child(param.Name).Is(param.DefaultValue);

    }

}

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 Note: GetGreediestCtor, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 HasOptionalParameters, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 and GetOptionalParameters are extension methods.  We’ll see their implementation shortly.

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 The convention inherits from the IRegistrationConvention, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 which is how you implement new conventions in StructureMap.  It has only one method: Process.  We filter out types that are abstract, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 are enums, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 or have constructors that don’t have optional parameters.  Once we realize we have a constructor we want to deal with, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 we use the Child method, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 that sets either a property or a constructor argument (for our case, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 it’ll always be a constructor argument), muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 and then we set it’s value to the parameter’s default value, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 as provided by the ParameterInfo object, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 for each optional parameter.

Minor Details

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 Curious about the implementation of GetGreediestCtor or the *OptionalParameters methods?  If not, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 skip this section.

public static bool HasOptionalParameters(

    this ConstructorInfo ctor)

{

    return ctor.GetOptionalParameters().Any();

}

 

public static IEnumerable<ParameterInfo> GetOptionalParameters(this ConstructorInfo ctor)

{

    return ctor.GetParameters().Where(

        param => param.Attributes

            .HasFlag(ParameterAttributes.Optional));

}

 

public static ConstructorInfo GetGreediestCtor(

    this Type target)

{

    return target.GetConstructors()

        .WithMax(ctor => ctor.GetParameters().Length);

}

 

public static T WithMax<T>(

    this IEnumerable<T> target, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 Func<T, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 int> selector)

{

    int max = -1;

    T currentMax = default(T);

 

    foreach(var item in target)

    {

        var current = selector(item);

        if(current <= max)

            continue;

 

        max = current;

        currentMax = item;

    }

 

    return currentMax;

}

 

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00  

The Usage

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 Here’s how to use your new convention.

var container = new Container(config =>

{

   config.Scan(scanner =>

   {

       scanner.TheCallingAssembly();

       scanner.AddAllTypesOf<IDestination>();

       scanner.WithDefaultConventions();

       scanner.Convention<DefaultCtorParameterConvention>();

   });

});

 

var logCommand = container.GetInstance<LogCommand>();

 

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 Now, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 when we pull the LogCommand out of the container, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 the level parameter gets defaulted to Level.Info, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 just like we specified in the constructor.  Sweet!

Conclusion

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 This implementation is somewhat limiting, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 but the version I have in my github repo is a little more open and configurable.  It allows you to customize the instance key/name you use when registering your type, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 and also allows you to do additional, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 non-standard registrations if you need to.

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 Also, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 this doesn’t work if you’ve selected a constructor using the SelectConstructor config API from StructureMap, muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 I’m not sure how to tap into that facility to look for that constructor rather than the greediest.

Muscle relaxants > requip 0.25mg pills (generic) > 360 pills > $566.00 Am I missing something?  Did something not make sense?  Leave me a note!

Average Rating: 4.4 out of 5 based on 261 user reviews.

23Sep/091

Antibiotics > Zithromax 250mg Pills (Generic) > 90 Pills > $97.00

Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 The first time I saw autotest (presented by Anthony), antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 the idea of Continuous Testing captured me.

Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 I live in a .NET world most of the time, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 and I know of no similar solution for .NET.  It’s been awhile since that first time, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 and I’ve tinkered here and there trying to get something comparable, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 but usually come up short.  That is until I found watchr.

Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 Watchr gave me the file change detection capabilities I needed, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 and the extensibility to do whatever I want when a file has been detected as changed.  This made it incredibly easy to hook up some autotest goodness in my .NET world.

Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 You'll have to have ruby installed, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 and gems.  Then, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 the very first thing you'll have to do is

Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 gem install watchr --source=http://gemcutter.org

Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 Here is my watchr script:

require 'autotest.rb'

watch( '^.*UnitTest.*.cs$' ) do |match|
  run_test(match.to_s)
end

Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 This is basically just a regex that says to watch any *.cs files that also contain the string “UnitTest”, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 and when it finds a change in a file matching that description, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 call run_test with the matched file name.

Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 So all the magic is in autotest.rb… lets check it out:

require 'rexml/document'

def build(test_project)
  `msbuild /nologo #{test_project}`
end

def mstest(test_container, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 test_results_file, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 tests_to_run)
  tests_to_run = ([""] << tests_to_run).flatten

  File.delete(test_results_file) if File.exists?(test_results_file)
  `mstest /nologo /resultsfile:#{test_results_file} /testcontainer:#{test_container} #{tests_to_run.join(" /test:")}`
  test_results = process_mstest_results(test_results_file)
  File.delete(test_results_file) if File.exists?(test_results_file)

  return test_results
end

def process_mstest_results(results_file)
  results = {}
  File.open(results_file) do |file|
    xml = REXML::Document.new(file)

    results[:num_tests] = xml.get_elements("//UnitTestResult").length
    failures = []
    xml.elements.each("//UnitTestResult[@outcome='Failed']") do |e|
      failure = {}
      failure[:message] = e.elements["Output/ErrorInfo/Message"].get_text

      stack = e.elements["Output/ErrorInfo/StackTrace"].get_text.value
      stack_match = /^.*at (.*) in(.*):line (\d+)$/.match(stack)

      failure[:stack] = stack_match[1] if stack_match
      failure[:location] = stack_match[2] if stack_match
      failure[:line] = stack_match[3] if stack_match

      failure[:stack] = stack if !stack_match

      failures << failure
    end
    results[:failures] = failures
  end

  return results
end

def show_results(results)
  puts "#{results[:num_tests]} tests run (#{results[:failures].length} failures)"
  results[:failures].each do |failure|
      puts "---------------------------------------"
      puts "Message: #{failure[:message]}"
      puts "Location: #{failure[:location]}"
      puts "Line: #{failure[:line]}"
      puts "Stack Trace: #{failure[:stack]}"
  end
end

def run_test(file_name)
  test_container = ""
  test_results_file = "result.trx"
  test_project = ""

  system("cls")
  system("echo Detected change in:")
  system("echo   #{file_name}")
  system("echo Building and Testing")

  test_namespace = ''
  test_class = ''
  test_names = []

  File.open(file_name, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 "r") do |f|
    f.each do |line|
      ns_match = /^namespace (.*)$/.match(line)
      test_namespace = ns_match[1] if ns_match

      class_match = /^\s*public class (.\w*).*$/.match(line)
      test_class = class_match[1] if class_match

      test_name_match = /^\s*public void (\w*).*$/.match(line)
      test_names << test_name_match[1] if test_name_match
    end
  end

  test_names = test_names.map { |n| "#{test_namespace}.#{test_class}.#{n}" }

  build(test_project)
  results = mstest(test_container, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 test_results_file, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 test_names)
  show_results(results)
end

Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 The key parts (I think) are the fact that I’m using MSTest to run my tests (this can easily be modified to run your framework of choice… note MSTest is not my choice ;) ).  The result parsing is also specific to the MSTest output format, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 but should be simple enough for any framework that can output XML. Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 Also, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 I'm making some assumptions based on my project... Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 we've got one unit test project, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 so I know I can run tests in a single DLL, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 and rebuilding only that project, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 I don't have to worry about choosing the correct project and output dll to build and run tests in.

Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 To get the thing up and running, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 just run

Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 watchr <path to watchr script>

Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 Please, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 use/adapt/give feedback/whatever at will.

Antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 Go forth and autotest, antibiotics > zithromax 250mg pills (generic) > 90 pills > $97.00 .NET comrades!

Average Rating: 5 out of 5 based on 197 user reviews.

25Feb/091

Asthma Relief & Management > Serevent 25mcg Inhaler (Generic) > 5 > $127.00

Asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 I've felt the pain of having the using statement not being able to return a value before, asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 and just chalked it up to a limitation of the language.

Asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 I never considered trying to find a better way, asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 and usually ended up with something like:

void DoSomething()
{
    XmlDocument xml = new XmlDocument();
    using(var reader = new StreamReader(@"c:\somexmlfile.xml"))
    {
        xml.Load(reader);
    }

    // do something useful with xml
}

Asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 or

void DoSomething2()
{
    XmlDocument xml = new XmlDocument();
    using( var reader = new StreamReader( @"c:\somexmlfile.xml" ) )
    {
        xml.Load( reader );
        // do something useful with xml
    }
}

Asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 Neither of which particularly suited me. Asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 Because

  • First example: Declaring the variable outside the scope of the block feels weird
  • Second example: Performing whatever operation inside the using block, asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 means the file (or other resource) doesn't get released until the operation has completed.

Asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 After Shawn mentioned something about this at his Indy Alt.Net Clojure talk, asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 I started thinking about it a little bit, asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 and then I had a real need for it (again), asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 and decided to come up with something better.  Turns out what I wanted was blatantly simple.

TResult UsingReturn serevent 25mcg inhaler (generic) > 5 > $127.00 TResult>(TDisposable toUse, asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 Func serevent 25mcg inhaler (generic) > 5 > $127.00 TResult> func)
    where TDisposable : IDisposable
{
    using (toUse)
    {
        return func(toUse);
    }
}

Asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 Now the above example turns into:

void DoSomething3()
{
    var xml = UsingReturn( new StreamReader( @"c:\cdf.xml" ), asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 reader =>
                {
                    var doc = new XmlDocument();
                    doc.Load( reader );
                    return doc;
                });
}

Asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 I'm not sure where this thing should live (e.g. Asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 some static utility class, asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 extension method on IDisposable), asthma relief & management > serevent 25mcg inhaler (generic) > 5 > $127.00 or even what it should be called.  Any ideas?

Average Rating: 4.9 out of 5 based on 244 user reviews.

11Dec/089

Digestive Health & Nausea > Diarex 30 Tablet Bottle > 7 > $281.00

Digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 Another bit of magic with static reflection. Digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 Refer to my last post for a little more explanation of static reflection, digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 and a sweet implementation (IMO) of INotifyPropertyChanged using static reflection.

Digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 In the past several years, digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 on several projects, digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 I've seen many lines of code at the beginning of public interface methods that look like:

    public class WebServer
    {
        public void BootstrapServer(int port, digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 string rootDirectory, digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 string serverName)
        {
            if( rootDirectory == null )
            {
                throw new ArgumentNullException( "rootDirectory" );
            }
            if( serverName == null )
            {
                throw new ArgumentNullException( "serverName" );
            }

            // Bootstrap the server
        }
    }

Digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 I realize the need, digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 since we don't have real DbC in .NET (yet), digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 but I REALLY dislike this and feel it to be a pretty bad smell.  It feels unDRY, digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 obscures essence, digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 and I just plain don't like it. Digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 ;)

Digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 So, digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 here is an implementation that makes it tolerable, digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 if not enjoyable (because of the coolness of using static reflection), digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 because I think it actually adds to the essence and overall readability of a given method.

Digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 This is what the above code can now look like:

    public class WebServer
    {
        public void BootstrapServer( int port, digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 string rootDirectory, digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 string serverName )
        {
            Guard.IsNotNull( () => rootDirectory );
            Guard.IsNotNull( () => serverName );

            // Bootstrap the server
        }
    }

Digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 And here is the implementation:

    public static class Guard
    {
        public static void IsNotNull<T>(Expression<Func<T>> expr)
        {
            // expression value != default of T
            if (!expr.Compile()().Equals(default(T)))
                return;

            var param = (MemberExpression) expr.Body;
            throw new ArgumentNullException(param.Member.Name);
        }
    }

Digestive health & nausea > diarex 30 tablet bottle > 7 > $281.00 Lovin it!  Hope you do too.

Average Rating: 5 out of 5 based on 267 user reviews.

8Dec/087

Allergy Relief > Allegra 30mg Pills (Generic) > 60 Pills > $71.00

Allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 I'm not going to delve into the definition of static reflection here, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 but you'll see how it's implemented, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 and how I found it can help me with implementing INotifyPropertyChanged.

Allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 Now, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 I've never been a fan of INotifyPropertyChanged myself, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 mostly because it feels wet (read: not DRY).  I'm working on a WPF app at the moment, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 and have come to realize, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 if I embrace INotifyPropertyChanged, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 I get to take full advantage of the excellent WPF databinding story.

Allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 Here is what a normal use of INotifyPropertyChanged looks like:

    public class Person : INotifyPropertyChanged
    {
        private string _firstName;
        private string _lastName;

        public event PropertyChangedEventHandler PropertyChanged;

        public string FirstName
        {
            get { return _firstName; }
            set
            {
                if (_firstName != value)
                {
                    _firstName = value;
                    FirePropertyChanged("FirstName");
                }
            }
        }

        public string LastName
        {
            get { return _lastName; }
            set
            {
                if (_lastName != value)
                {
                    _lastName = value;
                    FirePropertyChanged("LastName");
                }
            }
        }

        private void FirePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 new PropertyChangedEventArgs(propertyName));
            }
        }
    }

Allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 Here is what the static reflection use of INotifyPropertyChanged looks like:

    public class PersonStaticReflection : NotifyPropertyChanged
    {
        private string _firstName;
        private string _lastName;

        public string FirstName
        {
            get { return _firstName; }
            set { SetProperty(()=> FirstName, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 ()=> _firstName, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 value); }
        }

        public string LastName
        {
            get { return _lastName; }
            set
            {
                SetProperty( () => LastName, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 () => _lastName, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 value, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 () =>
                   {
                       // do something useful here
                   });
            }
        }
    }

Allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 Doesn't that just feel DRYer?  It does to me!

Allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 There are several important pieces to note:

  • Inheriting from NotifyPropertyChanged, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 this is the class that holds the SetProperty method, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 and hides the static reflection magic.
  • We're calling SetProperty with three arguments in the FirstName property
    • first: a LINQ Expression pointing to the property we're changing
    • second: a LINQ Expression pointing to the field to backing the property
    • third: the new, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 incoming value
  • We're calling SetProperty with a fourth argument in the LastName property
    • fourth: an action that will get executed only if the values were different
  • Allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 The SetProperty method, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 is going to look at the current value of the field, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 and the incoming value.  If the two are different, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 it will assign the new value to the field, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 and then fire the NotifyPropertyChanged event, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 with the name of the property given via the first argument.  I ended up pulling this into its own class so I could use it as the layer supertype in my View Model layer. Allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 Here is the implementation:

    public class NotifyPropertyChanged : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void SetProperty < T>( Expression < Func> propExpr, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 Expression> fieldExpr, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 T value )
        {
            SetProperty(propExpr, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 fieldExpr, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 value, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 ()=> { });
        }

        protected void SetProperty < T>( Expression < Func> propExpr, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 Expression < Func < T>> fieldExpr, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 T value, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 Action doIfChanged )
        {
            var prop = (PropertyInfo)((MemberExpression)propExpr.Body).Member;
            var field = (FieldInfo)((MemberExpression)fieldExpr.Body).Member;

            var currVal = prop.GetValue( this, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 null );

            if( currVal == null && value == null )
                return;
            if( currVal == null || !currVal.Equals( value ) )
            {
                field.SetValue( this, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 value );
                doIfChanged();

                if( PropertyChanged != null )
                    PropertyChanged( this, allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 new PropertyChangedEventArgs( prop.Name ) );
            }
        }
    }

Allergy relief > allegra 30mg pills (generic) > 60 pills > $71.00 Questions/comments/likes/dislikes? Let me know.

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

17Sep/081

Skin Care & Dermatology > Retin-A 0.05% Cream In 20g Tube (Generic) > 8 > $101.00

Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Another "tip/trick" style post, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 but thought it may prove useful to someone (or so I can find it again later!)...

Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Sometimes I find myself needing to map instances/values of one type to another.  For example, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 on my current project we have an enumeration in our communications layer, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 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, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 there is naturally a one to one mapping between these enumerations.

Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Consider the following enumerations:

Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00

enum Polygons
{
    Triangle, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00
    Rectangle, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00
    Pentagon, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00
    Other
}

enum NumSides
{
    Three, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00
    Four, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00
    Five, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00
    More
}

Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 This is the code I usually write to solve this problem:

Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00

private Polygons MapShapes( NumSides sides )
{
    switch( sides )
    {
        case NumSides.Three:
            return Polygons.Triangle;
        case NumSides.Four:
            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", skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 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", skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 polygon.ToString() ) );
    }
}

Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 It turns out we had 3 said enumerations.  So picture the above, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 copied 3 times.  This thing was just begging for abstraction!

Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 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... Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 both directions.  Here is the implementation:

Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00

public class Map retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Type2>
{
    private Dictionary retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Type2> _oneToTwo;
    private Dictionary retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Type1> _twoToOne;

    public Map()
    {
        _oneToTwo = new Dictionary retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Type2>();
        _twoToOne = new Dictionary retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Type1>();
    }

    public Map retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Type2> Add( Type1 value1, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Type2 value2 )
    {
        _oneToTwo.Add( value1, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 value2 );
        _twoToOne.Add( value2, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 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", skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00
                        typeof( Type2 ).Name, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00
                        typeof( Type1 ).Name, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00
                        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", skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00
                        typeof( Type1 ).Name, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00
                        typeof( Type2 ).Name, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00
                        value.ToString() ) );
            }
            return _oneToTwo[value];
        }
    }
}

Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 And, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 here it is in action:

Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00

Map<NumSides, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Polygons> shapeMap = new Map<NumSides, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Polygons>()
                                    .Add( NumSides.Three, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Polygons.Triangle )
                                    .Add( NumSides.Four, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Polygons.Rectangle )
                                    .Add( NumSides.Five, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Polygons.Pentagon )
                                    .Add( NumSides.More, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 Polygons.Other );

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

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

Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 This not only works with enumerations, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 but any type.  I see an extension to this possibly allowing for a default mapping, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 and possibly constraining Type1 and Type2 to be IComparable or something like that as well, skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 so you can have more control over your matching than whatever the default matching behavior that the Dictionary uses is.

Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 That's it... Skin care & dermatology > retin-a 0.05% cream in 20g tube (generic) > 8 > $101.00 enjoy!

Average Rating: 4.7 out of 5 based on 198 user reviews.

Tagged as: , 1 Comment
4Sep/084

Antidepressants > Cipralex 5mg Pills (Generic) > 180 Pills > $225.00

Antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 I find myself sometimes wishing I had a better switch/case construct in C#.

Antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 My requirements of "better" are:

  • Case statements are automatically scoped
  • I can switch on more than simple types
  • I can have custom logic for my matching criteria

But why not just use if/else if/else...?

Antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 Good question, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 I'm glad you asked! However, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 I don't have an excellent answer other than personal preference. Antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 if/else if/else is okay sometimes, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 but other times I have a deterministic set of conditions, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 and a switch type construct feels more symmetrical to me. Antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 I loves me some symmetric feeling code, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 it just feels cleaner somehow.

Antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 So I'll present a somewhat contrived example just so you can see what the usage looks like, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 then we'll see the code.

Usage


public void DoSomething()
{
	object foo = new object();
	object bar = new object();
	object baz = new object();

	Switch<object>.On(baz)
		.Case(x => x.Equals(foo), antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 () =>
		{
			Console.WriteLine("came into foo case");
		})
		.Case(x => x.Equals(bar), antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 () =>
		{
			Console.WriteLine("came into bar case");
		})
		.Default( () =>
		{
			Console.WriteLine("came into default case");
		})
		.Go();
}

Antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 The output from the above, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 is as you'd expect, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 the default case, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 since baz wasn't equal to foo or bar.

Implementation


public class Switch<T>
{
	private T _target;
	private List<KeyValuePair<Predicate<T>, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 Action>> _cases;
	private Action _default;

	public static Switch<T> On(T target)
	{
		return new Switch<T>(target);
	}

	public Switch(T target)
	{
		_target = target;
		_cases = new List<KeyValuePair<Predicate<T>, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 Action>>();
	}

	public Switch<T> Case(Predicate<T> @case, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 Action action)
	{
		_cases.Add(new KeyValuePair<Predicate<T>, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 Action>(@case, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 action));
		return this;
	}

	public Switch<T> Default(Action action)
	{
		_default = action;
		return this;
	}

	public void Go()
	{
		foreach(var @case in _cases)
			if (@case.Key(_target))
			{
				@case.Value();
				return;
			}
		if (_default != null)
			_default();
	}
}

Antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 The only part I don't really like is having to kick it off with the Go() at the end. Antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 Any ideas for a better way to kick it off, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 or at least a better name for it (instead of Go).

Antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 Feedback? Ideas?

Update

Antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 Paul had a great idea a couple great ideas (see comments) on how to get rid of the Go() at the end, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 and to force Default to only appear at the end. Antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 Here is the new implementation. Antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 Usage is the same, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 just remove the Go().


public class Switch<T>
{
	private T _target;
	private bool _alreadyMatched;

	public static Switch<T> On(T target)
	{
		return new Switch<T>(target);
	}

	public Switch(T target)
	{
		_target = target;
		_alreadyMatched = false;
	}

	public Switch<T> Case(Predicate<T> @case, antidepressants > cipralex 5mg pills (generic) > 180 pills > $225.00 Action action)
	{
		if (!_alreadyMatched && @case(_target))
		{
			_alreadyMatched = true;
			action();
		}
		return this;
	}

	public void Default(Action action)
	{
		if (!_alreadyMatched)
		{
			_alreadyMatched = true;
			action();
		}
		return this;
	}
}

Average Rating: 4.4 out of 5 based on 240 user reviews.

Tagged as: , 4 Comments
26Aug/080

ADHD > Atomoxetine 40mg Pills > 30 Pills > $98.00

Adhd > atomoxetine 40mg pills > 30 pills > $98.00 Starting my new project in a new role, adhd > atomoxetine 40mg pills > 30 pills > $98.00 as project lead, adhd > atomoxetine 40mg pills > 30 pills > $98.00 I need to be managing things in TFS.  The UI for batching these things up is nonexistent, adhd > atomoxetine 40mg pills > 30 pills > $98.00 but there is Excel integration so you can do it all in Excel, adhd > atomoxetine 40mg pills > 30 pills > $98.00 hit save, adhd > atomoxetine 40mg pills > 30 pills > $98.00 and it all goes back to the TFS server... Adhd > atomoxetine 40mg pills > 30 pills > $98.00 pretty slick I must say (I was actually in the midst of writing such a tool when I realized this functionality already existed OOB).

Adhd > atomoxetine 40mg pills > 30 pills > $98.00 However, adhd > atomoxetine 40mg pills > 30 pills > $98.00 the first time I tried to use this functionality... Adhd > atomoxetine 40mg pills > 30 pills > $98.00 BLAM, adhd > atomoxetine 40mg pills > 30 pills > $98.00 I get smacked with this:

Adhd > atomoxetine 40mg pills > 30 pills > $98.00 TF80042: The document cannot be opened because you do not have Microsoft Excel 2003 or later, adhd > atomoxetine 40mg pills > 30 pills > $98.00 or one of its components installed. Adhd > atomoxetine 40mg pills > 30 pills > $98.00 For more information, adhd > atomoxetine 40mg pills > 30 pills > $98.00 see the Team Foundation Installation Guide.

Adhd > atomoxetine 40mg pills > 30 pills > $98.00 Isn't that teh suck?

Adhd > atomoxetine 40mg pills > 30 pills > $98.00 Anyways, adhd > atomoxetine 40mg pills > 30 pills > $98.00 there is a sweet write-up on how to fix it here: http://blogs.microsoft.co.il/blogs/srlteam/archive/2007/07/17/Error-when-trying-to-export-queries-to-Excel.aspx.

Adhd > atomoxetine 40mg pills > 30 pills > $98.00 Thanks Elad!

Average Rating: 4.7 out of 5 based on 203 user reviews.

Tagged as: , , No Comments
22Aug/081

Men's Sexual Health > Avanafil 100mg Pills > 8 > $51.00

Men's sexual health > avanafil 100mg pills > 8 > $51.00 So last night I gave a talk at Indy ALT.NET on Castle MonoRail.  It was really just a sort of intro to MonoRail type of deal, men's sexual health > avanafil 100mg pills > 8 > $51.00 but the cool part was that we held a Dojo after I got done jabbering.

Men's sexual health > avanafil 100mg pills > 8 > $51.00 We ended up building a Poll Generator for our dojo activity.  We almost got done in the 45 minutes or so that we dojo'd.  It was a pretty fun activity, men's sexual health > avanafil 100mg pills > 8 > $51.00 and I'd like to do it again sometime soon.

Men's sexual health > avanafil 100mg pills > 8 > $51.00 Also, men's sexual health > avanafil 100mg pills > 8 > $51.00 this was really my first public speaking engagement to our technical community, men's sexual health > avanafil 100mg pills > 8 > $51.00 and let me say it was a blast.  Everyone had great things to say, men's sexual health > avanafil 100mg pills > 8 > $51.00 and many great questions were asked too.

Men's sexual health > avanafil 100mg pills > 8 > $51.00 I set up a google code repository so you can grab my slidedeck and grab the source for our dojo activity and my demo app.

Men's sexual health > avanafil 100mg pills > 8 > $51.00 Maybe next time I'll post before the talk, men's sexual health > avanafil 100mg pills > 8 > $51.00 so I can let people know about it.

Men's sexual health > avanafil 100mg pills > 8 > $51.00 Thanks guys for all the great feedback, men's sexual health > avanafil 100mg pills > 8 > $51.00 and thanks to my wife for understanding why I wasn't spending any of my evenings with her this week!

Average Rating: 4.4 out of 5 based on 239 user reviews.

22Aug/080

Men's Sexual Health > Viagra 100mg With Duloxetine 30mg Pills (Generic) > 120 Pills > $191.00

Men's sexual health > viagra 100mg with duloxetine 30mg pills (generic) > 120 pills > $191.00 Wowza!  So I've begun reading LosTechies (tons of great content, men's sexual health > viagra 100mg with duloxetine 30mg pills (generic) > 120 pills > $191.00 highly recommended!), men's sexual health > viagra 100mg with duloxetine 30mg pills (generic) > 120 pills > $191.00 and came across a passage today from Jimmy Bogard, men's sexual health > viagra 100mg with duloxetine 30mg pills (generic) > 120 pills > $191.00 who says what I feel, men's sexual health > viagra 100mg with duloxetine 30mg pills (generic) > 120 pills > $191.00 but what I couldn't get out of my head:

Men's sexual health > viagra 100mg with duloxetine 30mg pills (generic) > 120 pills > $191.00 On a sidenote, men's sexual health > viagra 100mg with duloxetine 30mg pills (generic) > 120 pills > $191.00 it always bothered me when people say that an interface with one implementation is a design smell.  No, men's sexual health > viagra 100mg with duloxetine 30mg pills (generic) > 120 pills > $191.00 an interface is used to expose a contract.  Interfaces communicate design intent, men's sexual health > viagra 100mg with duloxetine 30mg pills (generic) > 120 pills > $191.00 far better than a class might.

Men's sexual health > viagra 100mg with duloxetine 30mg pills (generic) > 120 pills > $191.00 Exactly!

Average Rating: 5 out of 5 based on 190 user reviews.

Tagged as: , No Comments