Exemplo n.º 1
0
 /// <summary>
 /// Prepares proxy subclasses for given types, all in one new assembly. (Normally,
 /// when doing one by one, each gets its own assembly.) If any of the types is
 /// not suitable, you will get an <see cref="InvalidOperationException"/>.
 /// </summary>
 public static void PrepareTypes(Type[] types)
 {
     ProxyGen.Prepare(types);
     foreach (var t in types.Where(typ => !_activators.ContainsKey(typ)))
     {
         var shT = ShieldedType(t);
         _activators.TryAdd(shT, CreateActivator(shT));
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs a new instance of the subtype of T generated by
 /// <see cref="ShieldedType"/>. It implements backing storage
 /// for all virtual properties (with virtual getters and setters) in one
 /// Shielded struct container. Base setters will be called before any change,
 /// and may use the getter to obtain the old value.
 /// If the class has a virtual method Commute(Action), this will be overriden
 /// and the override will perform the action as a commute.
 /// If the class has a protected method OnChanged(string), this will be called
 /// after every property change, with the property name as argument.
 /// The subtype is generated once per type, and cached for future calls.
 /// </summary>
 public static T NewShielded <T>() where T : class, new()
 {
     return((T)_activators.GetOrAdd(ProxyGen.GetFor(typeof(T)), CreateActivator)());
 }
Exemplo n.º 3
0
 /// <summary>
 /// Returns true if the type is a shielded proxy type.
 /// </summary>
 public static bool IsProxy(Type t)
 {
     return(ProxyGen.IsProxy(t));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Returns the proxy subtype for a given type. If arg already is a proxy type,
 /// then it just returns it directly. The proxy type implements backing storage
 /// for all virtual properties (with virtual getters and setters) in one
 /// Shielded struct container. Base setters will be called before any change,
 /// and may use the getter to obtain the old value.
 /// If the class has a virtual method Commute(Action), this will be overriden
 /// and the override will perform the action as a commute.
 /// If the class has a protected method OnChanged(string), this will be called
 /// after every property change, with the property name as argument.
 /// The subtype is generated once per type, and cached for future calls.
 /// </summary>
 public static Type ShieldedType(Type t)
 {
     return(ProxyGen.GetFor(t));
 }