简体   繁体   English

如何为我的代码中需要的类找到要在C#中导入的嵌套名称空间?

[英]How do I find which nested namespace to import in C# for the classes I need in my code?

This is one of the things I find infuriating about C#. 这是我发现令C#恼火的一件事。 I have thsi massive library im trying to use right now and for some reason the people who create the code examples are not smart enough to include the namespaces you need to import in the examples. 我有大量的库正在尝试使用,由于某种原因,创建代码示例的人不够聪明,无法在示例中包含需要导入的名称空间。 This is usualyl the case. 这是通常的情况。 I find myself searching through the namespace, hundreds sometimes nested trying to figure out which ones i need to import. 我发现自己正在搜索命名空间,有时有数百个嵌套试图找出我需要导入的名称。 In java netbeans, it even tells me which packages to import because it searches for me. 在java netbeans中,它甚至会告诉我要导入的软件包,因为它会搜索我。 But in C# i always waste countless time searching through the namespace manually. 但是在C#中,我总是浪费无数的时间手动搜索名称空间。

Is there any way I can get around this. 有什么办法可以解决这个问题。 Like right now im trying to find which namespace contains TwitterCredentials for Tweetinvi library. 就像现在一样,我试图查找哪个名称空间包含Tweetinvi库的TwitterCredentials。

Seriously, why do people not include the namespace in code examples. 严重的是,为什么人们没有在代码示例中包含名称空间。 It's just stupid not to! 不去只是愚蠢的! And why does visual studio not make suggestions like java. 为什么Visual Studio不提供像Java这样的建议。 It's just common sense really.... 真的,这只是常识。

You can press Ctrl + . 您可以按Ctrl + on each word that has error or point to small blue bar under the word and click on dropdown, and use offered namespace. 在每个有错误的单词上,或指向该单词下的小蓝条,然后单击下拉列表,然后使用提供的名称空间。

在此处输入图片说明

I am the developer of Tweetinvi :) 我是Tweetinvi的开发人员:)

ALL the classes you need in Tweetinvi are located in the Tweetinvi.Core.* namespace. Tweetinvi中需要的所有类都位于Tweetinvi.Core。*名称空间中。

TwitterCredentials.cs TwitterCredentials.cs

To answer your question regarding Namespaces and why I do not include them in the examples. 回答您有关命名空间的问题,以及为什么我不在示例中包括它们。 The reason is that as mentioned by Reza Aghaei Visual Studio and Resharper allow developers to include namespaces. 原因是如Reza Aghaei所述,Visual Studio和Resharper允许开发人员包括名称空间。

Furthermore as you mentioned the library is big and therefore multiple namespaces might be required and I am not going to add all of them in each example. 此外,正如您提到的,库很大,因此可能需要多个名称空间,在每个示例中我都不会添加所有名称空间。 Otherwise the documentation would just be huge. 否则,文档将非常庞大。

I hope you will like the library and please feel free to ask any question here on stackoverflow or on github . 我希望您会喜欢该库,请随时在stackoverflow或github上提问。

Happy coding. 快乐的编码。

PS: By the way you can also use Github to search for filename with a 't' keystroke on the Source Code page. PS:顺便说一句,您还可以使用Github在“源代码”页面上按“ t”键来搜索文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM