Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How should i make an instance of PlainTextContentControl? like:
C#
PlainTextContentControl p = new PlainTextContentControl( ...);


I do not want to use:
C#
plainTextControl p= 
Globals.ThisDocument.Controls.AddPlainTextContentControl("ControlName");

I need to make a new instance.

Thanks.
Hamid Noahdi
Posted
Comments
Hamid Noahdi 12-Oct-11 8:17am    
I don't know what to write for the constructors.
Sergey Alexandrovich Kryukov 13-Oct-11 1:30am    
You don't know? Good! This is a first step in right direction -- you don't need it. I explain it in my solution.
--SA

1 solution

The problem is simple. Its constructors are available but are marked "infrastructure" by Microsoft. This is a case of some less than perfect Microsoft design trick they use from time to time as they failed to hide access to those constructors in an elegant way and left them public.

From the practical standpoint, you should consider those constructors private or internal even though technically they are not.

A class does not have to have public constructors as it can be constructed in some non-constructor method and the instance returned by this method. Such factory method can be in the same class or some other class. There are many examples of such design in .NET libraries.

This is what happened in case of PlainTextContentControl: its instances can be constructed and returned by the method AddPlainTextContentControl, as shown in the code samples here:
http://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.plaintextcontentcontrol%28v=vs.90%29.aspx[^].

See also:
http://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.plaintextcontentcontrol_members%28v=vs.90%29.aspx[^],
http://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.plaintextcontentcontrol.plaintextcontentcontrol%28v=vs.90%29.aspx[^].

—SA
 
Share this answer
 
Comments
Abhinav S 13-Oct-11 2:11am    
My 5!
Sergey Alexandrovich Kryukov 13-Oct-11 15:07pm    
Thank you, Abhinav.
--SA
Espen Harlinn 13-Oct-11 17:47pm    
Excellent reply :)
Sergey Alexandrovich Kryukov 13-Oct-11 19:33pm    
Thank you, Espen.
--SA
Hamid Noahdi 23-Oct-11 7:29am    
Thanks alot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900