如何防止在访问C#中的成员函数时调用一个类的构造函数?(How to prevent calling constructor of one class while having access to its member functions in C#?)
我有一个类
A
和一个类AStore
。 我的要求是阻止所有其他方法初始化A
类的实例,他们应该从AStore
获取一个实例。 另外,我还需要从实例中访问A
的成员函数。
A
的构造函数仍然是公共的,工厂模式不适合这个问题。 理想情况下,在访问其成员函数时调用类A
的构造函数时,应该抛出编译错误。我可以获得C#解决方案吗?
I have a class
A
, and a classAStore
. My requirement is to prevent all other methods from initializing an instance of classA
, which they should get an instance fromAStore
. In addition, I also need to access the member functions ofA
from the instance.Factory pattern is not suitable for this problem as the constructor of
A
is still public. Ideally, it should throw compilation error when calling the constructor of classA
while having access to its member functions.Can I get C# solutions to this?
原文:https://stackoverflow.com/questions/41984648
最满意答案
我遇到了类似的问题,并在调用显示错误的元素之前添加延迟线(WebUI.delay(3))来解决此问题。
I had a similar issue and resolved it by adding a delay line (WebUI.delay(3)) before the call to the element that shows the error.
相关问答
更多-
如何使用_this_ Jeditable获得操纵DOM元素的值?(how to get to the value of manipulated dom element using _this_ Jeditable?)[2022-06-29]
不幸的是,当你在代码中使用this ,它引用了参数集合,而不是你试图访问的jQuery对象。 要完成您要执行的操作,您需要在参数集合之外引用jQuery对象。 就像是: $('.editme').each( function() { var rel = $(this).attr('rel'); $(this).editable('savedata.php', { placeholder : "zzz" + rel, } ); }); U ... -
如何验证Katalon Studio中元素的值是否为空(how to validate if element's value is not empty in Katalon Studio)[2022-07-27]
如果你想验证一个html元素具有特定的值,你可以使用: WebUI.verifyEqual(yourElement.getAttribute('value'),'') 寻找元素: def driver = DriverFactory.getWebDriver() WebElement elem = driver.findElement(ByTagName.tagName('theElementYouWantToFind')) 所以如果你想让测试用例在空值的情况下失败: WebUI.verifyNotE ... -
我遇到了类似的问题,并在调用显示错误的元素之前添加延迟线(WebUI.delay(3))来解决此问题。 I had a similar issue and resolved it by adding a delay line (WebUI.delay(3)) before the call to the element that shows the error.
-
首先是你的直接问题:如何使RichTextBox的内容“活跃”。 在RichTextBox IsDocumentEnabled属性设置为True,如下所示:
... -
在没有相关代码试用版和相关HTML的情况下,很难调试异常/错误。 但是,似乎有一个问题如下: 这里的主要问题是您使用的二进制文件之间的版本兼容性如下: 你正在使用chromedriver = 2.35 chromedriver版本注释= 2.35清楚地提到了以下内容: 支持Chrome v62-64 您正在使用chrome = 65.0 ChromeDriver v2.37发行说明清楚地提到了以下内容: 支持Chrome v64-66 所以ChromeDriver版本( v2.35 )和Chrome浏览器版 ...
-
如果要在jQuery选择器中使用元素ID,则需要#前缀,因此它应该是: word1 = jQuery('#'+elementId).text(); 但是你为什么要首先获得身份证? 您已经拥有对该对象的引用,因此您无需搜索它。 做就是了: word1 = jQuery(evnt.target).text(); 你的处理程序也可以更精致: jQuery("#word_set span.set1").click(function() { if(audioIsPlaying !== true) { ...
-
应用程序的真正下拉列表由bootstrap库生成。 您必须单击按钮并从下拉菜单中的列表中选择项目。 请参阅以下示例: var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(d => !d.FindElement(By.Id("busy")).Displayed); // Click first month driver.FindElement(By.CssSelector(".bootstrap-select. ...
-
解决了。 我在geb页面扩展了以前在spock规范中访问过的geb页面。 通过将导航器复制到子页面来解决问题。 我的想法是,父页面(先访问过)解决了导航器,并且孩子找不到以前解析的导航器。 有人可以验证或纠正我吗? 我不喜欢我必须复制此代码。 Solved. The geb page I was at extended a geb page that was visited previously in the spock spec. Issue was resolved by duplicating the ...
-
如果你得到Element is not currently interactable请检查该元素是否未被禁用且是否可见。 如果你想hack它执行JS来启用它。 我访问了主页id ita_form_location_RouteLanguageTextBox_0存在,在第一次飞行中没有Enter routing code 。 我可以看到说airport city or city name的文本框 此外,如果你有id更喜欢使用find_element_by_id如果不是尝试使用css selector如果你可以而 ...
-
这适用于你给我们的代码,我刚添加了form.children().length == 0 。 $('input.task').click(function(){ var checkbox = $(this); var form = $(this).parents('form'); if (checkbox.prop("checked")) { checkbox.parent().css('text-decoration', 'line-through').fadeOut(1000, f ...