예제 #1
0
 /// <summary>
 /// Initialises a DynamicType object using details from a ITypeDescriptorCollection object.
 /// </summary>
 /// <param name="node">A DynamicType object to initialise.</param>
 /// <param name="entityFields">A ITypeDescriptorCollection object containing the details of the fields.</param>
 public static void Initialise(this DynamicType node, ITypeDescriptorCollection entityFields)
 {
     // Add an entry for each field in entityFields and initialise its value to an appropriate default.
     foreach (ITypeDescriptor fieldDefinition in entityFields)
     {
         Type   fieldType = Type.GetType(fieldDefinition.TypeName, true, true);
         object fieldValue;
         if (fieldType == typeof(string))
         {
             fieldValue = string.Empty;
         }
         else if (fieldType == typeof(DateTime))
         {
             fieldValue = new DateTime(1970, 1, 1);
         }
         else
         {
             fieldValue = Activator.CreateInstance(fieldType);
         }
         node.Add(fieldDefinition.Name, fieldValue);
     }
 }