December 2005 - Posts

Partial To Partial Classes

I am trying to figure out how I did it without them! Partial classes make it so easy to clean up defined objects or classes taking advantage of VS2005 intellisense. Now for most, I think we enjoy keeping all of our classes intact, however partial classes help class designers keep their defined class members together. So what do I mean? Let's say you have designed classes that contain many properties, and for whatever reason these properties cannot be inherited from other class objects. Now let's say this dilemma not only applies to properties, but functions and methods too. Partial classes remedy this by allowing classes to be broken up into different physical files, and then at compile time, the .Net Framework compiles all of the partial classes as ONE. Let's look at some code so we can better understand what is happening here.

I have three class files…

1. PersonFunctions.cs

   public partial class Person
   {
       public string PersonFeels()
       {
          string strFeeling = PersonsName+" is "+PersonsAge.ToString()+" and feels ";
          if (PersonsAge >= 80)
             strFeeling += "Old!";
          else if (PersonsAge < 80 && PersonsAge > 50) 
             strFeeling += "tired of technology changing!";
          else
             strFeeling += "just wonderful!";

          return strFeeling;
       }
   }
     
2. PersonMethods.cs

   public partial class Person
   {
       public void Birthday()
       {
          _Age+=1;
       }
   }
 
3. PersonProperties.cs

   public partial class Person 
   {
      int _Age = 0;
      string _Name = "";
 
      public int PersonsAge
      {
         get
         {
            return _Age;
         }
         set
         {
            _Age = value;
         } 
      }

      public string PersonsName
      {
          get
          { 
             return _Name; 
          }
          set
         { 
            _Name = value;
         }
      }

      public Person()
      {

      }

      public Person(string Name, int Age)
      {
          PersonsAge = Age;
          PersonsName = Name;
      }
   }

As you can see, there are three different files being used to build a Person object. Try putting this code in your ASP.net page to for a demo!

protected void Page_Load(object sender, EventArgs e)

{

Person SiteUser = new Person("Bayer",55);

SiteUser.Birthday();

Response.Write(SiteUser.PersonFeels());

}

Partial classes will allow your class files to be cleaner and easier to understand, because these files can be broken out into multiple files, simply by separating like object members. This also increases productivity by utilizing more than one developer to work on the partial class files.

WSS, SP2 and ASP.Net 2.0 Web Parts

Trying to run ASP.Net 2.0 Web Parts within WSS Web zones, using SP2?

Big slap in the face if you think you can run ASP.Net 2.0 Web Parts like standard WSS Web Parts with just SP2. I thought the word on the street said that you could however not so true! You can run ASP.Net Web Parts in pages within WSS running SP2, but if you want to use ASP.Net 2.0 Web Parts, within WSS Web zones you need to wrap them with the Smart Part Framework first. Check out this White Paper. There are two many steps and limitations that have to be configured within the 2.0 framework that has me asking why I need to get ASP.Net 2.0 web parts to play like standard web parts. Until Office 12, I would recommend using standard 1.1 web part development!

Merry CHRISTmas