C# Namespace reserved words - c#

I make the following query, is that I am taking a project which contains a class project with namespace Application.ProyectoA is that now I need to use from a windows project and gives me problems with the proper namespace System.Windows.Application, now try thereby instantiate
_viewModel.Item = global :: Application.ProyectoA.ProyectoManager.Get (200);
I've also tried changing the name of the alias and using external alias, but you can not.
but does not recognize "Application.ProyectoA" anyone has any solution for this, change the namespace cumbersome Original is half as this project is used in several places.
Greetings and thank you very much.

Related

how to use namespace of external project?

Currently :
I have the following Using in my program.
using Mtx;
which allows me to use Mtx.* properties. It refers to a file in "Externals" folder.
Path is : Externals/Mtx.dll
Needed :
However, for debugging purposes, I'd like to now have the whole mtx solution in external and use it.
Path is : Externals/Mtx/(solution in there with all folders)
How can I do so, so instead of Using refers to the Mtx.dll, it now refers to the solution and build it has part of its own?
I think that you are misunderstanding some concepts and mixing things. Let me explain with your own explanation:
I have the following Using in my program.
using Mtx; which allows me to use Mtx.* properties. It refers to a
file in "Externals" folder.
Path is : Externals/Mtx.dll
The using keyword allows you to use the classes inside a namespace without typing the whole namespace everytime. It has nothing to do with dll classes, you can use all the public dlls insidea class just using the whole namespace + the class name only adding it as a project reference.
Needed :
However, for debugging purposes, I'd like to now have the whole mtx
solution in external and use it
For debugging purposes all you need are the pdb's of the dlls used and you will be able to debug any class considering you have its source code without changing anything else.

Namespace Shadowing Class Name

I have the following situation:
A compiled library with the namespace Library which contains class Feauture.
Now there is another library in development, one which intends to utilize the feature, and that has been dubbed Library.Feature. Finally there is a third library: Library.Feature.UI.
When working in the Library.Feature.UI project, which has both other libraries referenced, VS is yelling a lot about trying to using the Feature class, because it is seeing it primarily as a namespace.
I've tried a few different using directives to get around this, as well as trying to qualify the class name, but nothing is working.
Assuming I don't have the ability to change any of the namespaces or existing class names, is there a way to circumvent this issue?
You can either use fully qualified names where you specify the namespace together with the type name or you can use a using directive to create an alias:
using MyFeature = Library.Feature;
You can use alias directives to give a different name to any namespace, and then use that alias to reference that namespace.
By doing this you can differentiate between the class and the namespace.
write the following on top while using namespaces.
using FeatureClass = Library.Feature;
For more knowledge on this, you can refer:
https://msdn.microsoft.com/en-us/library/aa664765%28v=vs.71%29.aspx
Let me know if you have any further issue...
This should do the trick (references)
using FeatureClass = Library.Feature;

Silly Namespace Question

Ok, I have a c# project named BusinessLayer which produces an assembly called BusinessLayer and the namespace is BusinessLayer.
Inside of this project, I am using folders to store code. One folder is called FilterElements and it has folders called FilterKeyReversal, FilterRandom and FilterToday.
Let's take the example of the FilterRandom folder. It has a class called LessThan10DaysGreaterThan50A with a namespace of BusinessLayer.FilterElements.FilterRandom and a single public static method called RunFilter();
In the code behind page of the website that is consuming this method, I have the using statement, Using BusinessLayer. I also have another using statement, using BusinessLayer.FilterElements.
I would think that to expose the RunFilter() method of the LessThan10DaysGreaterThan50A class, I could use the following syntax: FilterRandom.LessThan10DaysGreaterThan50A.RunFilter(), however I get the following error: The name FilterRandom does not exist in the current context.
If I use the following syntax inline, the error goes away: BusinessLayer.FilterElements.FilterRandom.LessThan10DaysGreaterThan50A.RunFilter(), or if I use a using statement of: Using BusinessLayer.FilterElements.FilterRandom, the following syntax works: LessThan10DaysGreaterThan50A.RunFilter().
I would rather use FilterRandom.LessThan10DaysGreaterThan50A.RunFilter() as it seems to make code more readable. If I use an alias with the following syntax of using FilterRandom = BusinessLayer.FilterElements.FilterRandom, I can get what I want, but don't really like the idea of using an alias since it can lead to confusion down the line.
I thought that since my BusinessLayer namespace has nested namespaces, I'd be able to pick up the remaining namespace, but I can't seem to get it to work. Anybody know how to make this work without using an alias, or am I going to have to use the entire namespace name every time?
Thanks.
Nope, it doesn't. I know it's very irritating.
My first try at solving this issue (I had the same issue) was adding these usings:
using FilterRandom = BusinessLayer.FilterElements.FilterRandom;
The problem then becomes that you have to add one for every sub namespace you want to include, and that becomes a mess.
How I permanently solved this is by changing the namespaces in the project so that, in your example, FilterRandom would e.g. be in BusinessLayer.
The problem you are actually seeing is that you have too many namespaces. It isn't strange it happens. They are a great way of organizing your code and classes and it's not that hard to have it go out of hand. What I mean by changing the namespaces is that I merged many small namespaces into larger ones. This sometimes means renaming classes, but my opinion is that the class name on itself should be meaningful, without the namespace prefix.
This way, I permanently solved these issues in my project (60kloc) and it worked out great.

Using Namespaces

I have a "Web Project" in VS.
File structure
- AdminCms
- Sections
- CmsAuthors
- App_Code
- Business Logics
- Common
- BuilderStrings.cs
- DataAccess
-CmsModel.edmx
When I Build the Project VS in BIN Create a Cms.dll file.
In file "BuilderStrings.cs" I use:
namespace Cms.App_Code.BusinessLogics.Common
Using this code from folder "CmsAuthors"
using Cms.App_Code.BusinessLogics.Common;
As so far all is working fine.
Now for my understanding I should be able to name the namespace as I want ex:
namescape Wdg.Cms.Common
so if I use:
using Wdg.Cms.Common;
Script should be work just fine. Instead I get an error "Missing Assembly Reference".
What is wrong?
It is namespae a sort of path how to retrieve the Class?
Why I cannot use a different name?
Thanks guys for you help!
It is perfectly fine. Have you saved and rebuild your project?
** I did get the error for the first time as I didn't save my changes in app_code.
Nothing wrong here.
The main purpose of having namespace is to avoid class name collision. For example, you have StringBuilder.cs in App_Code/Admin and App_Code/Common, you can differentiate them by using name space: Wdg.Cms.Common.StringBuilder and Wdg.Cms.Admin.StringBuilder
You can use a different name.
namespaces should be defined using conventions, according to Microsoft "The general rule for naming namespaces is to use the company name followed by the technology name and optionally the feature and design as follows: CompanyName.TechnologyName[.Feature][.Design]
".
Have a look here : http://msdn.microsoft.com/en-us/library/893ke618%28VS.71%29.aspx
http://msdn.microsoft.com/library/ms229002
http://10rem.net/articles/net-naming-conventions-and-programming-standards---best-practices
You should keep your namespaces the same throughout your solution. You've used Cms.App_Code.BusinessLogics.Common in several places, so continue to use that in all places.
Your usage of Wdg.Cms.Common may be the cause of your Missing Assembly error.

How do I make a namespace containing 'System' in .NET without it conflicting?

Sometimes I've made a namespace in C# (I don't know if the problem is the same in VB.NET) containing 'System' and when I include it from a different DLL it goes crazy and conflicts with everything containing 'System'. This leads to crazy errors such as the following :
The type or namespace name
'ServiceModel' does not exist in the
namespace 'RR.System'
The type or namespace name 'Runtime'
does not exist in the namespace
'RR.System'
The type or namespace name
'SerializableAttribute' does not exist
in the namespace 'RR.System'
If you don't know what I'm talking about then good for you :) I'm sure many have seen this issue.
I'm not completely sure why it does this. It will occur even in files, such as generated code for web services that doesn't contain any reference to RR.System.
This all occurs just because I'm including RR.System the DLL in a different project.
How can I avoid this happening? Or fix it?
I still don't see why a child namespace conflicts with a root namespace? All types under a namespace can be fully qualified, and the fully qualified names refer to different types. e.g.
System.Abc.Xyz.Type
has nothing in relation to
Abc.Xyz.System.Type
The System in the first case refers to a completely different concept (The Company name under the guidelines), whereas the System in the second case could refer to the product or subsystem name.
If root namespaces can cause this kind of interference then surely that's a big problem because I may choose to call my new rainforest monitoring product Amazon and put all my types under MyCompany.Amazon. Then later on I may choose to store my data using the S3 storage and suddenly the namespace Amazon causes a conflict.
We've just run into the same issue as our project is split into 3 major sub-systems - Database, User and System. These seem like obvious child namespaces under our MyCompany root namespace.
Remember, this has nothing to do with Using statements as Simon said "It will occur even in files, such as generated code for web services that doesn't contain any reference to RR.System"
UPDATE: The following Stack Overflow question is along the same lines. However the MSDN article it points to discusses a class name called System hiding a namespace (fair enough) and also using System as a top-level namespace (fair enough). However it does not discuss why a child namespace conflicts with a root one.
Stack Overflow Q: Is global:: a bad code smell in C#?
MSDN Article: How to: Use the Namespace Alias Qualifier
Odd.
Now, why are you calling your project "System"?
To avoid confusion, you can fully qualify your namespace references:
global::System.ServiceModel
etc.
There isn't a way to reference both namespaces using the shorthand method. You'll either have to rename your class to prevent the collision, or alias your class like so (which will require you changing your references in your code to use the alias)...
Using System; // The namespace seen and used in all .cs files
Using Sys = RR.System; // Just replace -your- 'System' references with 'Sys'
While this method is legal in C#, it's messy and would suggest renaming your referenced class.
This reminded me of an old joke - Compiler, It hurts when I do this
If you have the option you may want to consider renaming your namespace to something like SystemUtilities or such, or you can just fully qualify all other references which can be a serious pain. Ambiguity with the BCL can lead to some nasty looking code.
If your project contains references to both System and your custom library (RR.System), the compiler will have an ambiguous reference to sort out. It's not sure which one you want.
You can always use aliasing to ensure that your code is explicitly referencing the correct code from your project.
BTW, there's a huge amount of best practice information to follow from Brad Abrams in Framework Design Guidelines.
The namespaces on my companies main projects are broken down to a few levels:
Company.au.ProductName.GUI.*
Company.au.ProductName.Data.*
...
where * would be further broken down depending on function
My company uses Company.Group.Platform.Application.Layer.Component.* It's very annoying and confusing. Needless to say, I use aliases

Categories