I am brand new to Visual Studio. I have been coding in Java for many years but have taken on a project which requires me to use c# and visual studio 2012.
What I need to know is how to utilize a different SDK. I want to use something called Honeywell SDK instead of Visual Studios inherent SDK but I cannot find out where to change this setting. If anyone has an answer that would be greatly appreciated!
as a Java developer you are probably used to imports and presumably understand how to use the import statement to import the classes in a namespace.
In C#, the first thing you must do is add a reference to the library containing the methods you require - this is normally done by right clicking your project in Solution Explorer, clicking add reference, and then selecting browse to browse to the location what is normally a DLL containing the library methods in question.
Once you have added a reference to your project, you can access the classes in the library either using a fully qualified name, e.g. to access the Thread class in .NET's System.Threading namespace for example, fully qualified use would be as follows:
System.Threading.Thread thread = new Thread();
Alternatively, you can put a using directive at the top of each file where you intend to use the client to avoid the need for the fully qualified name. For example:
using System.Threading;
Then in code, you can simply use the shortened version of the class name by itself:
Thread thread = new Thread();
As you can see, the using directive is effectively C#'s equivalent of Java's import directive. Note that to import all classes in a namespace you do not need the .* wild card at the end of the using directive as you do an equivalent Java import statement.
In practice, you may need to refer to the documentation you have to confirm what namespaces they use, and what files you need to add references to to use their libraries as this detail will be vendor specific. For more detail and a more thorough explanation of the using directive then the MSDN documentation is likely to be the most helpful source:
http://msdn.microsoft.com/en-gb/library/sf0df423%28v=vs.80%29.aspx
and:
http://msdn.microsoft.com/en-gb/library/z2kcy19k%28v=vs.80%29.aspx
There is no inherent SDK per-se in a .NET project, though normally references to the .NET framework and default using directives will be added. You will probably find these useful as they contain core functionality and the references normally added by default in a new project will provide you access to things such as collections and so forth.
One final note is that C# has a using statement, as well as the using directive, so if searching for additional information on the directive, be careful not to confuse it for the using statement.
Related
In Visual Studio 2022 we have the classic search function with which we can find a particular string of text in our solution. I'm wondering if there is a way to lookup all the classes inside a file that are defined in a package that is imported via the using directive.
Say for example i'm using package x.Business in my namespace using x.Business; is there a way to then lookup the classes inside this namespace which are coming from this imported package?
What I think you're asking is... "In any class file in my own solution, I want to be able to identify which types used in it (for parameters, variables, etc) are from a particular assembly that is in a using directive."
I don't know of any tool that does this, but the easiest way to identify usages in your file is to comment out the using directive. Any types, methods, etc that exist in that namespace will turn red showing that they can't be found.
(By the way, now is a good time to learn the proper term for those lines at the top of the class files. They're called "using directives", and they're not importing a whole package necessarily, but rather a particular namespace. Not to be confused with "using statements", which are a statement you can write inside of a method that automatically handles disposing of resources.)
The AutoComplete Function in VS2017 suggests me fully qualified using statements.
I have two projects with following (simplified) structure:
Company.Contracts
IMyExample.cs
Company.Core
MyExample.cs
Now when I use IMyExample in Class MyExample, VS2017 suggests me a using statement like
using Company.Contracts
But I think that there was a time when VS2017 suggested me:
using Contracts
which is sufficient as the projects share the same main namespace.
How can I configure VS2017 so that it prefers simplified instead of fully qualified namespaces? In fact this is the opposite of StyleCop Rule SA1135.
Hint: I was using VS2019 before but switchted back to VS2017 because the test licence ended and I'm pretty sure, that I didn't have to correct my using statements. Maybe in VS2019 this is possible?
Maybe in VS2019 this is possible?
Sorry but the answer could be negative, I test it in VS2019 release 16.3.4 and confirm this behavior is not supported for now.
In your situation, instead of using full qualified names, you can also use the format like Contracts.ClassName.
And for the reason why full qualified namespace is more preferred in this situation, assuming your current project Company.Core references one assembly whose root namespace is also named Contracts, now if VS do what you suggested, add the using Contracts when you use functions from Company.Contracts project, the intellisense would be confused about this. See:
In that situation you suggested, VS intellisense may get confused about what the using Contracts really mean, another assembly whose root namespace is Contracts or Company.Contracts project? So I think this could be one possible reason why it suggests full qualified namespace.
And if you do need one option which supports this behavior, I suggest you can send a feature request here.The team would consider about it if this request gets enough votes.
Hope my answer makes some help:)
In PresentationFramework from .NET 4.5 there is a namespace called Standard. Look here for more info: What is the namespace 'Standard'?
The problem is that in my C++/CLI project I am using an unmanaged library, which also defines a class called Standard. So I get the following compiler error:
error C2869: 'Standard' : has already been defined to be a namespace
I cannot remove the reference to PresentationFramework, and I cannot stop using the said library. Is there anything I can do? Like un-importing the namespace?
P.S. I am using VisualStudio 2012. I think that an upgrade to 2013 might help, but that will require the whole team to move to it.
That namespace was added to PresentationFramework by .NET 4.5, I believe, and I don't think changing to Visual Studio 2013 will help you. Everything in that namespace is defined as internal, and it mostly consists of Enums and Structs used with Windows SDK functions called by PresentationFramework.
Unfortunately, I have no idea what to do about your problem. Perhaps you can convince whoever supplies the third-party library to change their namespace. The fact that Microsoft is now using it would be a good reason for them to do so. Whoever these people are that are creating namespaces with a simple, generic name such as "Standard" need to have their heads examined.
I'm in C# land today. I'm trying to write a function which accepts a user agent string and returns an object that gives me at least the browser name and version. So I tried this answer, but apparently I don't have access to HttpBrowserCapabilities. It tells me the type or namespace name could not be found (yes, even if I add using System.Web, it still doesn't show up, or when I type using System.Web. it doesn't pop up, so it's obviously not there).
I'm using .net 3.5, but the documentation for that class shows it existed even in 3.5, so I'm not sure what's going on. I have access to the browscap files - ini or xml. Am I going to have to write this from scratch?
Edit: I've fixed the reference problem. But Chrome is being reported as AppleMAC-Safari 5.0. I'm wondering if I'm going to need a completely different approach. PHP figures it out with the same ini file fine.
Adding a using block does not automatically import the DLL. All a using does is allow you to not write:
System.Web.HttpClient //Or whatever
All over the place, and use HttpClient instead.
You need to add a reference to System.Web to the project before any of its classes will be available to you.
Did you have a using System.Web; statement in your source file?
Here's a tip: if you're using Visual Studio, and you have a reference to the System.Web.dll in your project, if you type the name of a type and press Ctrl-. it will give you a popup menu to add the namespace reference to your source file.
Do you see it in the ObjectBrowser (assuming you are using Visual Studio)? I found the namespace this morning (granted I'm on 4.5 - but documentation shows it has been around since 3.5 and earlier)
(Yet another question from my "Clearly I'm the only idiot out here" series.)
When I need to use a class from the .NET Framework, I dutifully look up the documentation to determine the corresponding namespace and then add a "using" directive to my source code:
using System.Text.RegularExpressions;
Usually I'm good to go at this point, but sometimes Intellisense doesn't recognize the new class and the project won't build. A quick check in the Object Browser confirms that I have the right namespace. Frustration ensues.
Using HttpUtility.UrlEncode() involved adding the appropriate directive:
using System.Web;
But it also required adding a reference to .NET Framework Component for System.Web, i.e. right-click the project in Solution Explorer, select Add Reference and add System.Web from the .NET tab.
How might I discern from the documentation whether a .NET namespace is implemented by a .NET Framework Component that must be referenced? I'd rather not hunt through the available components every time I use a namespace on the off chance that a reference is needed.
(For those who like to stay after class and clean the erasers: Will Organize Usings > Remove and Sort also remove references to componenents that are not used elsewhere in the project? How do you clean up unnecessary references?)
Check out this link for UrlEncode:
Namespace: System.Web
Assembly: System.Web (in System.Web.dll)
The Assembly line tells you which dll to reference.
You'll note that the documentation (e.g. http://msdn.microsoft.com/en-us/library/system.web.httputility.aspx) tells you the name of the assembly/DLL that the class should be found in, along with the class's namespace.
Namespace: System.Web
Assembly: System.Web (in System.Web.dll)
On a side note, I know it can be a little dear, but Resharper makes things like this so much easier. If you're a serious developer, you may want to consider investing in a license. For the eraser-cleaners, Resharper adds a handy little "Find Code Dependent on Module" item to the right-click menu on references in the Solution Explorer. It's not quite an automatic cleanup, but it makes it a lot easier to see whether something's still being used by your project.
The documentation specifies two things for any type:
The namespace of the type (for the using directive)
The assembly containing the type (this is what you add a reference to)
To take an example where the two are different, look at the documentation for Enumerable:
Namespace: System.Linq
Assembly: System.Core (in System.Core.dll)
If you look at the MSDN docs, e.g.
http://msdn.microsoft.com/en-us/library/system.web.httputility.aspx
It tells you the namespace and the assembly that is required.
First, a correction to your terminology: What you are referencing is called an "assembly". An assembly contains classes that belong to a namespace. A namespace can span across multiple assemblies.
Most assemblies are named the same as the main namespace that is contained in them. For example, System.Web exists in System.Web.dll. The documentation also usually tells you which assembly needs to be referenced.
I think that you are running into a difference between c# and C here. To compare: In C, all you need to do to include a new library is to include it in the header.
It .net, you need to be aware of 2 things:
A namespace can span more than one assembly/dll (that means that you might not get a compiler error on the using clause, because some of the dlls that support that namespace are referenced -- just not the one that you need)
To "see" the contents of a given assembly, you have to add a reference to it. The using clause alone just gives you some short-cut syntax so that you can write HttpUtility.Encode(), instead of System.Web.HttpUtility.UrlEncode(), you have to add the reference in order for the compiler to "know" about the class.
To avoid your problem:
In the MSDN documents, pay attention to the assembly that the class is in, and make sure that you have a reference to the assembly.
If you browse to the MSDN for the class you're trying to use. It typically tells you the assembly that the class is in. For example the Regex class is in Assembly System (in System.dll) or the HttpUtility class is in Assembly System.Web (in System.Web.dll).
I believe tools such as ReSharper help with this, as well, and automatically references the assemblies you need.
I'm pretty sure you have to manually remove the unused references in C# projects. In VB.NET projects there's a button to list the unused references when you're in the project properties page. I don't see this in C# projects, though.