Esempio n. 1
0
 /// <summary>
 /// Add an ability of instantiating an instance of a class that has no default constructer.
 /// </summary>
 /// <typeparam name="T">Type of the object that is activated by this <paramref name="activator"/>.</typeparam>
 /// <param name="activator">A delegate that creates an instance of <typeparamref name="T"/>.</param>
 /// <example>
 /// <code>
 /// var serializer= new Serializer);
 ///
 /// var yaml =
 ///   @"%YAML 1.2
 ///   ---
 ///   !System.Drawing.SolidBrush
 ///   Color: Red
 ///   ...
 ///   ";
 ///
 /// SolidBrush b = null;
 /// try {
 ///   b = (SolidBrush)serializer.Deserialize(yaml)[0];
 /// } catch(MissingMethodException) {
 ///   // SolidBrush has no default constructor!
 /// }
 ///
 /// YamlNode.DefaultConfig.AddActivator&lt;SolidBrush&gt;(() => new SolidBrush(Color.Black));
 ///
 /// // Now the serializer knows how to activate an instance of SolidBrush.
 /// b = (SolidBrush)serializer.Deserialize(yaml)[0];
 ///
 /// Assert.AreEqual(b.Color, Color.Red);
 /// </code>
 /// </example>
 public void AddActivator <T>(Func <object> activator)
     where T : class
 {
     Activator.Add <T>(activator);
 }