- Admin
- #1
So I've got a set of classes that I want only created in a given Factory class. To annoy me intensely the factory class is in a different assembly to the classes I want the factory to create.
So I thought "I know, I'll hide the constructors as internal, and make the other assembly with the factory class a Friend Assembly." and that would sort things out.
Except the factory class uses a bit of generics, and now I get messages all over about not having a blank constructor for all the types which have their constructors made internal.
In short:
---- Assembly One ---
[assembly: InternalsVisibleTo("Assembly Two")]
class Bob
{
***//This'll fox people who may arbitrarily create my class
***internal Bob(){}
}
---------------------------
--- Assembly Two ----
class BobFactory
{
***T Maker() where T :*new()
***{
******...
***}
***SomeMethod()
***{
******//This causes an error due to Bob*not having a*public default constructor
******Bob thing = Maker()
***}
}
--------------------------
Any ideas?
Perhaps I should abandon this idea and just trust my implementers (ha!).
[edit: hang fire on being helpful people, I may have been targetting the wrong assembly doh!]
More...
View All Our Microsoft Related Feeds
So I thought "I know, I'll hide the constructors as internal, and make the other assembly with the factory class a Friend Assembly." and that would sort things out.
Except the factory class uses a bit of generics, and now I get messages all over about not having a blank constructor for all the types which have their constructors made internal.
In short:
---- Assembly One ---
[assembly: InternalsVisibleTo("Assembly Two")]
class Bob
{
***//This'll fox people who may arbitrarily create my class
***internal Bob(){}
}
---------------------------
--- Assembly Two ----
class BobFactory
{
***T Maker() where T :*new()
***{
******...
***}
***SomeMethod()
***{
******//This causes an error due to Bob*not having a*public default constructor
******Bob thing = Maker()
***}
}
--------------------------
Any ideas?
Perhaps I should abandon this idea and just trust my implementers (ha!).
[edit: hang fire on being helpful people, I may have been targetting the wrong assembly doh!]
More...
View All Our Microsoft Related Feeds