Exemplo n.º 1
0
 public static void Register(ErasureMethod method, object[] parameters)
 {
     ConstructorInfo ctor = null;
        if (parameters == null || parameters.Length == 0)
     ctor = method.GetType().GetConstructor(Type.EmptyTypes);
        else
        {
     Type[] parameterTypes = new Type[parameters.Length];
     for (int i = 0; i < parameters.Length; ++i)
      parameterTypes[i] = parameters[i].GetType();
     ctor = method.GetType().GetConstructor(parameterTypes);
        }
        if (ctor == null)
     throw new ArgumentException(S._("Registered erasure methods must contain " +
      "a parameterless constructor that is called whenever clients request " +
      "for an instance of the method. If a constructor requires parameters, " +
      "specify it in the parameters parameter."));
        lock (ManagerLibrary.Instance.ErasureMethodManager.methods)
        {
     MethodConstructorInfo info = new MethodConstructorInfo();
     info.Constructor = ctor;
     info.Parameters = parameters == null || parameters.Length == 0 ? null : parameters;
     ManagerLibrary.Instance.ErasureMethodManager.methods.Add(method.Guid, info);
        }
        OnMethodRegistered(new ErasureMethodRegistrationEventArgs(method.Guid));
 }