So I'm new to generics. What I'm doing below is:

1) User creates a struct (or class...this example will only use struct)
Example:

C# Code:
  1. struct UserInfo
  2.     {
  3.         public string FirstName;
  4.         public string LastName;
  5.         public string Department;
  6.     }//end struct

2) User instantiates class (not important)
3) User calls method:

C# Code:
  1. UserInfo user = profile.GetInfo<UserInfo>();

4) Method takes the struct and, based on the names of the members of the struct, fills the struct with data from the object (in this particular instance UserProfile [Microsoft.Office.Server.UserProfiles])

C# Code:
  1. /// <summary>
  2. /// Fills the class or stuct with information from the users profile.
  3. /// </summary>
  4. ///<exception cref="ArgumentException">Thrown if the struct or object datamember names are invalid.</exception>
  5. public T GetInfo<T>() where T : new()
  6. {
  7.     object returnValue = new T();
  8.     Type type = typeof(T);
  9.  
  10.     try
  11.     {
  12.         FieldInfo[] fields = type.GetFields();
  13.         PropertyInfo[] properties = type.GetProperties();
  14.  
  15.         if (fields.Length > 0)
  16.         {
  17.             foreach (FieldInfo field in fields)
  18.             {
  19.                 field.SetValue(returnValue, this.Profile[field.Name].Value);
  20.             }//end foreach
  21.         }
  22.         else if (properties.Length > 0)
  23.         {
  24.             foreach (PropertyInfo property in properties)
  25.             {
  26.                 property.SetValue(returnValue, this.Profile[property.Name].Value, null);
  27.             }//end foreach
  28.         }//end if
  29.     }
  30.     catch (Microsoft.Office.Server.UserProfiles.PropertyNotDefinedException)
  31.     {
  32.         throw new System.ArgumentException("Struct or Class member names do not match the options available. Run ListPossibleMembers() to get a list of members");
  33.     }
  34.     catch (Exception)
  35.     {
  36.        throw;
  37.     }//end try/catch
  38.     return (T)returnValue;
  39. }//end GetInfo

Unknown members in code shown (class-level variables):
1. "profile" -- UserProfile that gets instantiated in the constructor

I built this because I've found myself constantly querying information about users in SharePoint. With this, all I need to do is create a struct or class with the datamembers, and then call the function.

Since this is my first foray into generics, I was hoping someone could take a look at the code and let me know if they see anything horribly wrong with this, or if they could give suggestions on a different way to accomplish it.