我应该如何创建PlainTextContentControl的实例? [英] How should i make an instance of PlainTextContentControl?

查看:122
本文介绍了我应该如何创建PlainTextContentControl的实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何创建PlainTextContentControl的实例?像:

How should i make an instance of PlainTextContentControl? like:

PlainTextContentControl p = new PlainTextContentControl( ...);



我不想使用:



I do not want to use:

plainTextControl p= 
Globals.ThisDocument.Controls.AddPlainTextContentControl("ControlName");


我需要创建一个新实例.

谢谢.
Hamid Noahdi


I need to make a new instance.

Thanks.
Hamid Noahdi

推荐答案

问题很简单.它的构造函数可用,但Microsoft标记为基础结构".这是他们不时使用的一些不够完美的Microsoft设计技巧的一个例子,因为他们未能以优雅的方式隐藏对那些构造函数的访问并把它们公开.

从实际的角度来看,即使从技术上讲不是,这些构造函数privateinternal仍应考虑.

一个类不必具有public构造函数,因为它可以在某些非构造函数方法中构造,并且该方法可以返回实例.这种 factory 方法可以在同一类中,也可以在其他一些类中. .NET库中有许多这样的设计示例.

这是在PlainTextContentControl情况下发生的情况:它的实例可以由方法AddPlainTextContentControl构造并返回,如此处的代码示例所示:
http://msdn.microsoft. com/en-us/library/microsoft.office.tools.word.plaintextcontentcontrol%28v = vs.90%29.aspx [ 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 [
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


这篇关于我应该如何创建PlainTextContentControl的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆