@@ -70,6 +70,7 @@ public class ZptMetadata
7070		#region fields
7171
7272		private  Type  documentClass ; 
73+     private  static   Type  defaultDocumentClass ; 
7374
7475		#endregion
7576
@@ -95,21 +96,28 @@ public ZptDocumentType DocumentType
9596		public  Type  DocumentClass 
9697		{ 
9798			get  { 
98- 				return  documentClass ; 
99+         Type  output  =  documentClass ; 
100+         
101+         if ( output  ==  null ) 
102+         { 
103+           output  =  DefaultDocumentClass ; 
104+         } 
105+         
106+ 				return  output ; 
99107			} 
100108			set  { 
109+         /* If we are passed a null reference then fall back to the default type. 
110+          * If we are passed a concrete type then try using that (if it implements the required interface) 
111+          * Otherwise throw an exception. 
112+          */ 
101113				if ( value  ==  null ) 
102114				{ 
103- 					throw  new  ArgumentNullException ( "value" ) ; 
104- 				} 
105- 				
106- 				bool  implementsIZptDocument  =  ImplementsRequiredInterface ( value ) ; 
107- 				
108- 				// If we found a type that implements IZptDocument then we use it, otherwise throw an exception 
109- 				if ( implementsIZptDocument ) 
110- 				{ 
111- 					documentClass  =  value ; 
115+ 					documentClass  =  DefaultDocumentClass ; 
112116				} 
117+         else  if ( ImplementsRequiredInterface ( value ) ) 
118+         { 
119+           documentClass  =  value ; 
120+         } 
113121				else 
114122				{ 
115123					throw  new  ArgumentOutOfRangeException ( "value" , 
@@ -161,6 +169,35 @@ public string DocumentFilePath
161169			get ; 
162170			set ; 
163171		} 
172+     
173+     /// <summary> 
174+     /// <para>Gets and sets a default value for <see cref="DocumentClass"/>.</para> 
175+     /// </summary> 
176+     public  static   Type  DefaultDocumentClass 
177+     { 
178+       get  { 
179+         return  defaultDocumentClass ; 
180+       } 
181+       set  { 
182+         /* If we are passed a null reference then throw an exception (this property may not be null). 
183+          * If we are passed a concrete type then try using that (if it implements the required interface) 
184+          * Otherwise throw an exception. 
185+          */ 
186+         if ( value  ==  null ) 
187+         { 
188+           throw  new  ArgumentNullException ( "value" ) ; 
189+         } 
190+         else  if ( ImplementsRequiredInterface ( value ) ) 
191+         { 
192+           defaultDocumentClass  =  value ; 
193+         } 
194+         else 
195+         { 
196+           throw  new  ArgumentOutOfRangeException ( "value" , 
197+                                                 "The type passed to this property does not implement IZptDocument." ) ; 
198+         } 
199+       } 
200+     } 
164201
165202		/// <summary> 
166203		/// <para> 
@@ -303,8 +340,8 @@ private void WriteToXml(TextWriter writer)
303340		public  ZptMetadata ( ) 
304341		{ 
305342			this . DocumentType  =  ZptDocumentType . Metal ; 
306- 			this . DocumentClass  =  typeof ( ZptDocument ) ; 
307343			this . DocumentFilePath  =  null ; 
344+       this . DocumentClass  =  null ; 
308345		} 
309346
310347		/// <summary> 
@@ -313,6 +350,7 @@ public ZptMetadata()
313350		static   ZptMetadata ( ) 
314351		{ 
315352			ForeignDocumentClasses  =  new  Dictionary < string ,  Type > ( ) ; 
353+       DefaultDocumentClass  =  typeof ( ZptDocument ) ; 
316354		} 
317355
318356		#endregion
@@ -491,6 +529,41 @@ public static void RegisterDocumentClass(Type typeToRegister)
491529
492530      ForeignDocumentClasses . Add ( typeToRegister . FullName ,  typeToRegister ) ; 
493531		} 
532+     
533+     /// <summary> 
534+     /// <para> 
535+     /// Registers all of the compatible types within an <see cref="Assembly"/> using 
536+     /// <see cref="RegisterDocumentClass"/>. 
537+     /// </para> 
538+     /// </summary> 
539+     /// <remarks> 
540+     /// <para> 
541+     /// This method is a shortcut to separately calling <see cref="RegisterDocumentClass"/> on each type within an 
542+     /// <see cref="Assembly"/>.  Instead this method scans the assembly for every compatible type and registers them. 
543+     /// </para> 
544+     /// </remarks> 
545+     /// <param name="fromAssembly"> 
546+     /// A <see cref="Assembly"/> 
547+     /// </param> 
548+     public  static   void  RegisterDocumentClasses ( Assembly  fromAssembly ) 
549+     { 
550+       Type [ ]  allTypes ; 
551+       
552+       if ( fromAssembly  ==  null ) 
553+       { 
554+         throw  new  ArgumentNullException ( "fromAssembly" ) ; 
555+       } 
556+       
557+       allTypes  =  fromAssembly . GetExportedTypes ( ) ; 
558+       
559+       foreach ( Type  type  in  allTypes ) 
560+       { 
561+         if ( ImplementsRequiredInterface ( type ) ) 
562+         { 
563+           RegisterDocumentClass ( type ) ; 
564+         } 
565+       } 
566+     } 
494567
495568		/// <summary> 
496569		/// <para> 
0 commit comments