Jump to content

Recommended Posts

Posted

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

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...