Reflection in .Net with a C# example Monday, Jul 18 2011 

Reflection is the ability of the .NET framework to gather information (metadata) about assemblies, modules and types at runtime. It allows you also to dynamically create instances of types, invoke methods and access fields, properties and attributes.

Reflection is an important capability of the .NET framework and enables you to get information about objects at runtime. In this article, we will iterate through all properties for a class named Person using reflection.

using System;
using System.Reflection;

class Program
{
static void Main(string[] args)
{
Person person = new Person();
person.Age = 27;
person.Name = “Fernando Vezzali”;

Type type = typeof(Person);
PropertyInfo[] properties = type.GetProperties();
foreach (PropertyInfo property in properties)
{
Console.WriteLine(“{0} = {1}”, property.Name, property.GetValue(person, null));
}

Console.Read();
}
}

The Person class extends System.Object and does not implement any interface. It is a simple class used to store information about a person:

class Person
{
private int age;
private string name;

public int Age
{
get { return age; }
set { age = value; }
}

public string Name
{
get { return name; }
set { name = value; }
}
}

 

Advertisements

Wednesday, Aug 11 2010 

free counters

Top 13 Funny Software Development Quotes Thursday, May 13 2010 

Over the years, I’ve collected some of the smartest-yet-funny software development quotes I have read. Here’s the current short list in no particular order. Oddly enough, there are thirteen of them and they all address the woes of programming.

Feel free to add any like quotes in the comment section!

  1. “The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill
  2. “In order to understand recursion, one must first understand recursion.” – Author Unknown
  3. “I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone.” – Bjarne Stroustrup
  4. “A computer lets you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila.” – Mitch Ratcliffe
  5. “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -C.A.R. Hoare
  6. “The gap between theory and practice is not as wide in theory as it is in practice.” – Author Unknown
  7. “If builders built buildings the way programmers wrote programs, then the first woodpecker that came along would destroy civilization.” – Gerald Weinberg
  8. “If debugging is the process of removing software bugs, then programming must be the process of putting them in.” – Edsger Dijkstra
  9. “Measuring programming progress by lines of code is like measuring aircraft building progress by weight.” – Bill Gates
  10. “Nine people can’t make a baby in a month.” – Fred Brooks
  11. “Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” – Rich Cook
  12. “There are two major products that come out of Berkeley: LSD and UNIX. We don’t believe this to be a coincidence.” – Jeremy S. Anderson
  13. “Before software can be reusable it first has to be usable.” – Ralph Johnson