how to refernce a folder?

M

mp

It's been suggested to me to put some .cs files in subfolders of my project
folder
(to separate BLL and DAL)
and then to reference those subfolders
I can't find a way to do that in express....maybe it's onlly avail in the
full version?
to refernce a file I don't get an option for .cs files, only .dll, .exe, etc
what am i missing>?
thanks
mark
 
J

Jeff Johnson

It's been suggested to me to put some .cs files in subfolders of my
project folder
(to separate BLL and DAL)
and then to reference those subfolders
I can't find a way to do that in express....maybe it's onlly avail in the
full version?
to refernce a file I don't get an option for .cs files, only .dll, .exe,
etc
what am i missing>?

You're missing a stick with which to smack the person who gave you this bad
advice. I could lend you one....

Perhaps, as Pete suggested, this person was just using bad terminology.
Perhaps he was thinking in terms of SourceSafe, or VB6, where you can "link"
to external items.

Either way, this just isn't possible in C#. If you try to add an existing
item from outside the project's folder hierarchy, a COPY of that item will
be made somewhere within the hierarchy. C# simply cannot "reference" outside
the folder tree where the project is.

The main way to share code between projects is to put it in its own project
and reference that project (or its output) from others.
 
M

mp

Peter Duniho said:
IMHO, you should wait for clarification from the person who suggested that
in the first place.

well, that's kinder than Jeff's idea
:)
I believe that the crux of the issue is a failure to use precise meanings
for terms like "reference". Without clarification of the original
suggestion, it's not going to be possible to know exactly what the right
thing to do in VS is.

I will also take this opportunity to caution you against taking anything
you read, here or elsewhere, as the final truth.

yeah, that's my default MO. Though until someone or my own experience
shows something to be wrong, i have no basis for what to accept/reject.

For example, I note in
the MVC/MVP discussion it was suggested that the presenter/controller
object should know about the specific UI controls. However, while it's
true that when one is being lax about the division of labor, the
presenter/controller often has specific knowledge about the view object
(and indeed, may be the same object), that would not be true when using
MVC or MVP in their purest forms.

i was a little surprised about that too.

Instead, the view would expose some UI-agnostic interface used by the
presenter, encapsulating all of the actual UI-specific control types, etc.
and hiding them from any other class. To do otherwise ties the non-UI
code to a specific UI implementation.

that's what I thought it would look like

can you give me a hint what that would look like in my case,
if i have a form with a DataGridView
I have a presenter which has gotten some data from a 'business object'
i'm picturing something like

IUI_Interface
private void DisplayData(<type> data) ;
(not sure what type to use to make it theoretically agnostic to my current
app? i assume object?)
in theory, in future projects, maybe data will come in as a string, or a
List<string> or collection or ???
in my case, in the instance i'm thinking of, i will have a List<string> I
want to display..
but an interface wants to be as generic as possible, right?

then in the actual form
private void DisplayData(object? data)
{//current implementation
...cast data to List<string>
...put list into datagridview
etc}

then in the presenter
ConcreteForm.DisplayData(this.data);

???somethign like that???
One of the major values of following a true MVC/MVP design is that you can
replace your view with anything you like without requiring changes to the
other elements. If you start with a view that exposes .NET Forms types to
the controller (for example), then changing the UI to be based on WPF,
web-based, console-based, etc. becomes very problematic, because none of
those view implementations would naturally have any Forms types at all.

exactly. And for what I'm trying to do this is getting way more complicated
than it needs to be...however, due to a significant defect in my character
<g>
I want to learn the "right/best" way to do things, even though I have no
economic
justification for all the time i'm spending trying to learn all this which
is so far
above my head....:)
Anyway, that's a long way of saying that you should take everything with a
grain of salt. Start with some fundamental design goals, and then take a
moment to evaluate any advice against those goals. It's pragmatic to be
flexible about what goals one is addressing and how, sacrificing purity of
design for practicality. But make sure you do so consciously, rather than
just taking at face value everything you read. :)

Pete

I very much appreciate everyone's help that i receive here, and of course
on my own have little to go on in terms of corroborating/evaluating the
validity
of some of it...Thats' why I so appreciate the different voices that can
come in
and address any specifics that I may be getting confused on due to my lack
of knowing.
:)
Thanks
mark
 
A

Arne Vajhøj

It's been suggested to me to put some .cs files in subfolders of my project
folder
(to separate BLL and DAL)
and then to reference those subfolders
I can't find a way to do that in express....maybe it's onlly avail in the
full version?
to refernce a file I don't get an option for .cs files, only .dll, .exe, etc
what am i missing>?

BLL and DAL should be in different projects not different subfolders
in a single project.

Arne
 
A

Arne Vajhøj

BLL and DAL should be in different projects not different subfolders
in a single project.

But if you insist:

right click project, new folder, specify folder
right click new folder, new item, pick class, specify new class

VS will automatically update the .csproj file to include the
..cs files in the folder in the build.

And that should work for all VS editions.

Arne
 
M

mp

Arne Vajhøj said:
BLL and DAL should be in different projects not different subfolders
in a single project.

Arne

thanks Arne,
I'm getting different advices and trying to weed out which to follow.
changing folders didnt' seem necessary and I don't see what benefit it was
intended to provide.
I'm going back to try and simplify.
all this mvp stuff has added complexity (due to my inexperience)
without any observable value at this point
mark
 
A

Arne Vajhøj

I'm getting different advices and trying to weed out which to follow.
changing folders didnt' seem necessary and I don't see what benefit it was
intended to provide.

If you have many files then it can structure the project.

ASP.NET MVC uses different folders to group source code
files (actually it is the VS wizard that set it up that way,
but ...).
I'm going back to try and simplify.
all this mvp stuff has added complexity (due to my inexperience)
without any observable value at this point

MVP is a good thing.

I prefer MVC, but ...

Arne
 
M

mp

Peter Duniho said:
In other words, don't be too afraid of giving up on advice prematurely.
It's not likely to hurt you too much in the long run.

thanks for the thoughts

[]
Alternatively, much of a UI is in fact very generalizable. That's why in
.NET we have classes like BindingList<T>, which provide a specific kind of
way to access list data that allows a UI to update itself according to
changes in the data. One might use such a type in the UI interface, with
the presenter/controller mediating between the underlying model data (i.e.
supplying an instance of BindingList<T> to the UI, and updating it as
needed based on events in the model). Or if appropriate, the model data
might just use that type directly, with the presenter/controller being
responsible simply for connecting the two ends.

i'll look into that BindingList object

[]
On the other hand, if you take advantage of the event-driven programming
style enabled in C#, then data structures can persist in their
connections, with observers such as the view types responding to events
that signal when the data structure has changed. The observers then
"pull" data from their sources as needed, according to the events that are
raised.

i usually misunderstand, so i'll repeat what i think that means so you can
correct me <g>
1 my business object Portfolio.cs gets a string from somewhere that it wants
to display
2 it raises an event GotStringToDisplay(string str) (or whatever better
name) when it has it...
3 the presenter InvestmentPresenter.cs (another badly named object i know)
subscribes to that event
and raises it's own event GotStringToDisplay(string str)
4 the view(form) InvestmentView.cs subscribes to that event and fills it's
datagrid (or whatever other control) with the string???

am i even close???
if so, is the string passed somehow through the EventArgs object? (from one
object to the other)

[]

IMHO you should definitely beware of trying to learn too much at once.

that's definitely the problem i'm suffering from at this point...i've spent
a week or more
trying to understand various sometimes conflicting info on mvp / tutorials/
ngs / websites/etc
and all this time all i'm trying to do is show a comma delimited string in a
flipping form
:)))
Anyway, sorry for the essay. I realize most of the above has nothing to
do with the specific question. But hopefully there is some useful advice
nonetheless. :)

Pete

much appreciated as always
mark
 
A

Andy O'Neill

<<snip>>
I think there's a difference between express and full VS.
With full visual studio you can add an app_code folder, organise some
folders underneath it and still compile.
By default the code you create in there has a namespace corresponding
to your directory structure.
So if you left it as generated then you'd need to add references
elsewhere.
I tend to overwrite the namespace and just have one if I'm working in
a small sized app.
So to be charitable to the person recommending the restructuring,
maybe that's sort of what he had in mind.
This allows you to separate your code out into sub-folders and find
stuff easier later.
When I tried to open an app which was structured in this way a while
ago express c# didn't like the folder structure.
Not really sure why as I didn't have to work on the app there and
then. I shrugged and opened the specific file I wanted to copy code
out of.
 
M

mp

Big Steel said:
Arne Vajhøj said:
On 10-01-2011 14:46, mp wrote:
It's been suggested to me to put some .cs files in subfolders of my
project
folder
[...]
changing folders didnt' seem necessary and I don't see what benefit it was
intended to provide.
I'm going back to try and simplify.
all this mvp stuff has added complexity (due to my inexperience)
without any observable value at this point

http://www.aspiringcraftsman.com/tag/model-view-presenter/

MVP promotes the separation of business and data access logic out of the
codebehind file. You can unit test and functional test from the MVP and
down with a test harness without writing lick of code in the UI to test
anything.

You can't unit test the UI with a test harness. You can however unit test
every aspect of the View and the Presenter for expected results with a
test harness.

Threr is one other pattern that is missing he
in the link. Not only are the UI controls controlled on the View by the
Presenter, all the events for a given control on the View are passed into
like events in the presenter. Also any form events are passed into the
Presenter making the form dumb, and the Presenter and View are unit
testable for expected results.

That is the value of the MVP, which is more flexible than MVC IMHO.

Steel,
thanks for hanging in with my slow learning curve
I misspoke when i said "without any observable value at this point"
I understand the testability argument (although at my level i'm not doing
tdd)
at the moment i posted that my brain was just getting frustrated that it
takes
me so long to understand things (as they apply to my simplistic situation)

I see the mvp (and other patterns) really kick in value for an
enterprise/multi developer context

me doing a tiny personal app on my laptop,
some of the "benefits" of trying to follow patterns remain a bit
theoretical.

thanks for the other link, i'll check that out too
(i am followign the tutorial you showed me by the way)
I took the exact project (the 4th one in the series) and just changed the
names to fit my program
all of the following questions on my part are just attempts to figure out
how to apply the project to my actual needs.

it was when you started mentioning moving .cs files into different folders
and
referencing the folders(which is different than the tutorial i'm trying to
follow)
that I got really confused as the express version
doesn't allow me to add a reference to a folder, just a file.

thanks again for all your help and info
mark
 
J

Jeff Johnson

[...]
Either way, this just isn't possible in C#. If you try to add an existing
item from outside the project's folder hierarchy, a COPY of that item
will
be made somewhere within the hierarchy. C# simply cannot "reference"
outside
the folder tree where the project is.

Actually, when adding an item, there's a drop-down in the "Add" button for
the file dialog. If you choose "Add As Link", then the item won't be
copied; it will be referenced from wherever its existing location is.

Ahhhh, that's it. So the VB-like functionality IS there; they just swapped
out an easy-to-see check box for a much harder to discover drop-down button.
 
J

Jeff Johnson

I have used the Express editions several years ago. So you can't
right-click a project and add a folder? I find that kind of strange.

You can't use a using statement that uses the namespace pointing to the
folder in the namespace? I don't care what anyone else is talking about.
You are referencing that folder in the namespace as far as I am concerned
so one doesn't have to use the fully qualified path to get to the folder
in code. :)

If that's what you're talking about, then fine, and thanks for finally
explaining it. But you need to realize that you are making up your own
definition of "referencing" which is different from what the rest of us know
as referencing as far as Visual Studio is concerned, so don't be too upset
when everyone says you're wrong. The real term for what you are doing is
"aliasing."
 
M

mp

Steel said:
On 1/11/2011 10:34 AM, mp wrote: [...]

I have used the Express editions several years ago. So you can't
right-click a project and add a folder? I find that kind of strange.

ah, yes, I can right click the project and get a drop down menu
the closest menu item is Add New Folder
That creates a new, empty folder under the project folder...
That created NewFolder1
So I copied ExcelReader.cs (my dal object) into that folder and renamed it
ExcelReader2.cs
I opened that file and renamed the namespace to ExcelReader2 (to avoid
conflict with the existing one in the bus.obj. project in the businesslayer
main folder)

Then I went back to the business layer project and added the using directive
at the top of the file( Investment.cs - the business object)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewFolder1.ExcelReader2; <<<<< added this here
namespace Investments.BusinessLayer
{

But i get the following compile error
Error 8 The type or namespace name 'NewFolder1' could not be found (are you
missing a using directive or an assembly reference?)

....well I thought that *WAS* the using directive...??? sorry i'm confused
again
I can see NewFolder1 in the list of refernces for that project...

You can't use a using statement that uses the namespace pointing to the
folder in the namespace? I don't care what anyone else is talking about.
You are referencing that folder in the namespace as far as I am concerned
so one doesn't have to use the fully qualified path to get to the folder
in code. :)

I don't want to get too hung up on the folder thing, i don't have so many
files in this project
that i need a heirarchy of folders to divide them up.
but i want to at least get to where I understand exactly what you're
doing...
sorry but the exact steps in the ide to do what you're suggesting may be
required, as so far
i don't seem to have enough understanding of the ide to physically follow
your suggestions yet.

what am i missing?
thanks
mark
 
M

mp

Steel said:
On 1/11/2011 1:58 PM, mp wrote: []
using NewFolder1.ExcelReader2;<<<<< added this here
1) You can give the folder a meaningful name other than Newfolder1.

I know that but i'm just trying to get this to work, at this moment i don't
care about the name
2) The folder was created within a project.

correct it was created by the ide when I went Add New Folder
it appears in the references list for the project
3) using projectname.foldername; // will now allow you to see a class
in the project.

or you can do #4

4) using projectname.foldername = mp;

var someobj = new mp.Classname();

var theobj = someobj.SomeMethodInTheObject();


Any new class created in the folder is going to get namespace
projectname.foldername

Any class you copy into the folder will need to have its namespace changed
to match projectname.foldername

the project name is Investments.BusinessLayer
when i do this
using Investments.BusinessLayer.NewFolder1.ExcelReader2 = er;

I get an error at the = sign, saying ; expected

???

mark
 
A

Arne Vajhøj

<<snip>>
I think there's a difference between express and full VS.
With full visual studio you can add an app_code folder, organise some
folders underneath it and still compile.

That would be surprising since the compile is done by ASP.NET not VS.

You could write these files in notepad and ASP.NET would not know it.
By default the code you create in there has a namespace corresponding
to your directory structure.
So if you left it as generated then you'd need to add references
elsewhere.

????

References is for assemblies.

Arne
 
A

Arne Vajhøj

I have used the Express editions several years ago. So you can't
right-click a project and add a folder?

You can.
You can't use a using statement that uses the namespace pointing to the
folder in the namespace? I don't care what anyone else is talking about.
You are referencing that folder in the namespace as far as I am
concerned so one doesn't have to use the fully qualified path to get to
the folder in code. :)

????

You import namespaces.

You refer to assemblies.

VS handles folders without any intervention.

There are no strong correlation between namespaces and folder
(like in Java). The only correlation is what the new class wizard
suggests for namespace.

It is possible to use completely different terms for everything
in .NET, but for communication widely the only sane approach
is to use the standard terminology (mostly defined by Microsoft).

Arne
 
A

Arne Vajhøj

On 1/11/2011 1:49 PM, Jeff Johnson wrote:

<snipped>

I didn't like your smart mouth lip-service in another post, so you heard
from me.

You may not like it, but you should thank him.

If you listen to him you may end up sounding as someone
that know about C# and .NET !

Arne
 
A

Arne Vajhøj

ah, yes, I can right click the project and get a drop down menu
the closest menu item is Add New Folder
That creates a new, empty folder under the project folder...
That created NewFolder1
So I copied ExcelReader.cs (my dal object) into that folder and renamed it
ExcelReader2.cs
I opened that file and renamed the namespace to ExcelReader2 (to avoid
conflict with the existing one in the bus.obj. project in the businesslayer
main folder)

Then I went back to the business layer project and added the using directive
at the top of the file( Investment.cs - the business object)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewFolder1.ExcelReader2;<<<<< added this here
namespace Investments.BusinessLayer
{

But i get the following compile error
Error 8 The type or namespace name 'NewFolder1' could not be found (are you
missing a using directive or an assembly reference?)

...well I thought that *WAS* the using directive...??? sorry i'm confused
again
I can see NewFolder1 in the list of refernces for that project...

Folders has fundamentally nothing to do with namespaces.

The create class wizard may put a suggestion for namespace in
the generated code.

But since you did not use that but instead used an existing file
then that does not apply to you.

If ExcelReader.cs contains:

namespace ExcelReader2
{

then you import as:

using ExcelReader2;

no matter what folder it is in.
I don't want to get too hung up on the folder thing, i don't have so many
files in this project
that i need a heirarchy of folders to divide them up.
but i want to at least get to where I understand exactly what you're
doing...
sorry but the exact steps in the ide to do what you're suggesting may be
required, as so far
i don't seem to have enough understanding of the ide to physically follow
your suggestions yet.

See above.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top