从局部类初始化一个类 [英] initialize a class from a partial class

查看:147
本文介绍了从局部类初始化一个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从另一个类中初始化一个类以使用其属性和方法,但是该类具有2个构造函数(1个带参数的构造函数,一个不带参数的构造函数).一个没有参数的就可以了,一个没有参数的就看不到了.是因为它是局部类?

这是代码:

I am trying to initiate a class to use it''s attributes and method from another class, but the class has 2 constructors(1 with parameters, and one without). the one without parameters it is finding ok, the one with parameters it is not seeing it. it is because it is a partial class?

this is the code:

public partial class ScenarioEditorView : UserControl, IScreenSelectorSubItem, IActionable, INotifyPropertyChanged
   {

        string p1 = "";
        string fullp = Path.GetFullPath(p1);
        ScenarioEditorViewModel viewModel = new ScenarioEditorViewModel(fullp);
}


丰满未知.

请帮助


fullp is unknown.

please help

推荐答案

确保:
-您没有忘记第二个构造函数public
-如果第二个构造函数在另一个文件中(您说您的类是局部的),则请确保该类的名称拼写正确,否则它将被视为另一个类.

目前,我什么都没有看到.如果您需要更多帮助,请发布更多代码.
Make sure that:
- you didn''t forget public for your second constructor
- if the second constructor is in another file (you said your class is partial), then make sure the name of the class is spelled properly, otherwise it will be considered as another class.

For now I don''t see anything else. Please post more code if you want more help.


不,不是因为类是部分的:"partial"关键字唯一要做的是 ^ ] .当类的一部分由工具生成时,这尤其有用.

换句话说,关键字"partial"纯粹是编译时的构造:一旦编译了一个类,则除partial之外的部分和非部分类在所有方面都相同的情况下,就没有可检测的差异. >
编译器无法看到"已声明的构造函数的唯一原因是因为该构造函数不是公共的,并且您的代码不允许对其进行访问.您可以张贴错误的详细信息以及构造函数标头的代码吗?
No, it is not because the class is partial: the only thing the "partial" keyword does is letting you split a class (an interface, a struct) among two or more compilation units[^]. This is especially useful when parts of your class are generated by a tool.

In other words, keyword "partial" is purely a compile-time construct: once a class is compiled, there are no detectable differences between a partial and a non-partial classes if they are identical in all respects except being partial.

The only reason why a compiler could not "see" a declared constructor is because that constructor is not public, and your code is not allowed access to it. Could you post the details of your error, and a code for the constructor''s header?


这篇关于从局部类初始化一个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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