Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# using others code

Iv'e downloaded a C# interval tree collection class class from here http://intervaltree.codeplex.com/SourceControl/list/changesets -> Right hand side -> Download.

However I can't open the whole project on my Microsoft Visual C# 2010 Express (that also runs C# XNA) because

Solution folders are not supported in this version of the application

Also I just want the class to use separately in my own seprate project.

I tried to copy the three important seeming files Interval.cs, IntervalNode.cs and IntervalTree.cs into my project but this generated the compile error

There are no importers which handle this file type

I've also tried to copy and paste the contents of the three files into my project, encapsulating them into there own namespace as well as there was a lot of code. I had to rearange some of the usings a little but have run into the problem that possibly it wants PowerCollections .dll and .pcb files as using Wintellect.PowerCollections; causes

The type or namespace name 'Wintellect' could not be found (are you missing a using directive or an assembly reference?)

I'm not sure how to continue or if I'm doing the right thing at all in how to get this class to work.

like image 783
alan2here Avatar asked Jan 08 '12 15:01

alan2here


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What is C language basics?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.


2 Answers

Add the library to your solution

Copy the IntervalTreeLib directory into your solution directory. Then, right-click your solution, and add existing project. Point it at IntervalTreeLib.csproj in IntervalTreeLib, and click Open. That should add the IntervalTreeLib project to your solution.

Add Existing Project Screenshot

Add a reference to the library in your project

Then, in your project, add a reference to the IntervalTreeLib proejct: - Right click the References folder, and Add Reference. Click the Projects tab, and select IntervalTreeLib.

Add Reference Screenshot

Select Project Reference Screenshot

Use the classes in your code

To use classes from the library in your source then, you need to either add:

using IntervalTreeLib;

void Foo() {
    IntervalTree<int, int> tree = new ...
}

Or, refer to them by their full name:

IntervalTreeLib.IntervalTree<int, int> tree = new ...
like image 126
Jonathon Reinhart Avatar answered Sep 28 '22 02:09

Jonathon Reinhart


Open the IntervalTreeLib.csproj file if you want to be able to open the project in it's entirety (or in your current solution add an existing project (you can right-click on the solution) and select the IntervalTreeLib.csproj). If you are trying to grab just the code file in your project, ensure you also grab the PowerCollections.dll file (I see it is in the same folder as the code files) or your code will not compile (as you have discovered). You'll need to add a reference to it and include the needed using statement at the top of the code files making use of this library (or use fully qualified name with the namespace).

using IntervalTreeLib;

or

var myObj = new IntervalTreeLib.[WhateverClass](...);

Also, make sure you read the license.txt file. You may need to include it if you are using the code. Give credit where it is due.

UPDATE:

If the test project is causing you problems, just open the library project. Ideally you could just open that and compile it, adding the output DLL files that are generated directly into your solution. This is ideal unless you are planning on changing the library source code itself.

like image 37
Jason Down Avatar answered Sep 28 '22 02:09

Jason Down