You might want to declare an internal constructor with your three parameters. If your CustomerRepository does not live in the same assembly as your Customer class, you can make your internal visible using the following attribute:
[assembly: InternalsVisibleTo ("CustomerAssembly, PublicKey=...")]
in the Customer assembly.
Edit: By the way, I would not recommend using reflection if you need to create many objects, because it will be an order of magnitude slower than direct calls to designers. If you really need to go this route, I would recommend adding a static factory method that you can call through reflection to get an efficient allocator.
For instance:
class Customer { private Customer(...) { ... } private static ICustomerFactory GetCustomerFactory() { return new CustomerFactory(); } private class CustomerFactory : ICustomerFactory { Customer CreateCustomer(...) { return new Customer(...); } } } public interface ICustomerFactory { Customer CreateCustomer(...); }
Use reflection to call Customer.GetCustomerFactory , and from now on you will have a quick and efficient way to create Customer s.
source share