Пример #1
0
 public static void Set(Type t, string PropertyName, object Value)
 {
     Cache.SetProperty(t, null, t.GetProperty(PropertyName), Value);
 }
Пример #2
0
 /// <summary>
 /// Latebound object parameterised constructor, where the unknown object's constructor
 /// requires parameters.
 /// </summary>
 /// <param name="t">The type of object the caller requires an instance of</param>
 /// <param name="Params">Parameters reuired for type t's constructor</param>
 /// <remarks>
 /// This constructor will generate and call the IL required to create an instance of an
 /// object of Type t, passing the supplied parameters to the appropriate constructor.
 /// This call is considerably faster than using reflection to perform the same job,
 /// particularly as the generated IL is cached to reuse whenever another
 /// instance of the object is required.
 /// <para>
 /// Note that the types of the parameters passed into this constructor must match exactly
 /// the signature of required object's constructor parameters, otherwise the call will fail.
 /// </para>
 /// <para>
 /// This type of constructor is particularly useful when it is known that a type that
 /// implements a known interface takes a parameterised constructor. The follwing example
 /// constructs an object that implements IMyPlugin where the Type has been retrieved from
 /// an attribute on the class. It has been agreed that the plugins will be able to accept
 /// a configuration file's path as a constructor parameter, in order to initialise its
 /// custom properties.
 /// <example>
 /// <code>
 /// Attribute attr = Attribute.GetCustomAttribute(MyPluginAssembly, typeof(PluginImplementationAttribute));
 /// Type t = attr.PluginImplentationType;
 /// String path = MySettingsPath;
 ///
 /// Latebound MyPluginInstance = new Latebound(t, path);
 /// IMyPlugin iPlugin = (IMyPlugin)MyPluginInstance.Instance;
 /// </code>
 /// </example>
 /// </para>
 /// </remarks>
 public Latebound(Type t, params object[] Params)
 {
     _type     = t;
     _instance = Cache.Construct(t, Params);
 }
Пример #3
0
 public static object Get(Type t, string PropertyName)
 {
     return(Cache.GetProperty(t, null, t.GetProperty(PropertyName)));
 }
Пример #4
0
 /// <summary>
 /// Latebound object constructor, when only the type of the object required is known.
 /// </summary>
 /// <param name="t">The type of object the caller requires an new instance of.</param>
 /// <remarks>
 /// This constructor will generate and call the IL required to create an instance of an
 /// object of Type t. This call is considerably faster than using reflection to perform
 /// the same job, particularly as the generated IL is cached to reuse whenever another
 /// instance of the object is required.
 /// <example>
 /// <code>
 /// Type t;
 ///
 /// t = SomeType;
 /// Latebound someType = new Latebound(t);
 /// </code>
 /// </example>
 /// </remarks>
 public Latebound(Type t)
 {
     _type     = t;
     _instance = Cache.Construct(t);
 }