Conflict in namespace in C# - c#-4.0

If my namespace is
Cytel.GlobalSettings.ChartSetting
and
I have a static class ChartSetting
packed in dll.
then when I use ChartSetting class in other project it shows red color with Chartsetting class's method and public members are not shown

It is interpreting your reference to ChartSetting as a reference to the namespace. You should use the fully qualified name of the ChartSetting static class. If it has an empty namespace, then you will need to use the global qualifier thus:
global::ChartSetting
You can also specify an alias to this class:
using MyAlias = global::ChartSetting;

Related

How can I use the same namespace names in cpp-winrt idl file and a normal/standard cpp class?

The scenario is new and I believe it might be a bug in cpp-winrt module or the vc compiler.
The Problem
1. Create a "windows runtime component" using the cpp-winrt template for universal windows.
2. Note the namespace name defined in the idl file. By default the idl file is named as class.idl.
3. Add a "new standard cpp class" to the project using the class wizard.
4. Put the new class under the same namespace name as defined in the idl file.
5. Build the project.
a. The build should succeed.
6. Use the standard cpp class in the runtime implementation class.
7. Now try to build the project again.
a. The build will fail this time.
The Reason
1. cppwinrt.exe generates source files from the idl file.
2. The runtime implementation class namespace is prefixed by "winrt".
3. The standard cpp class is not prefixed by the namespace "winrt".
4. The vc compiler expects the standard cpp class namespace to start from "winrt"
5. Otherwise the name resolution fails even if you try to use the fully qualified namespace name.
Example runtime idl file
namespace NMLevel1.NMLevel2
{
[default_interface]
runtimeclass Class
{
Class();
void RuntimeMethod1();
Int32 RuntimeMethod2(Int32 arg1);
String RuntimeMethod3(String arg1);
Int32 MyProperty;
}
}
Example standard cpp file
#pragma once
#include <string>
using namespace std;
namespace NMLevel1::NMLevel2
{
class StdCPPClass
{
public:
StdCPPClass();
virtual ~StdCPPClass();
void method1();
int method2(int arg1);
wstring method3(wstring arg1);
};
}
Example runtime class implementation
#include "pch.h"
#include "Class.h"
#include "NMLevel1.NMLevel2.Class.g.cpp"
#include "StdCPPClass.h"
using namespace winrt;
using namespace Windows::Foundation;
namespace winrt::NMLevel1::NMLevel2::implementation
{
void Class::RuntimeMethod1()
{
NMLevel1::NMLevel2::StdCPPClass stdcls;
Uri uri(L"http://aka.ms/cppwinrt");
//printf("Hello, %ls!\n", uri.AbsoluteUri().c_str());
printf("RuntimeMethod1(): Hello, %ls!\n", stdcls.method3(uri.AbsoluteUri().c_str()).c_str());
}
}
NMLevel1::NMLevel2::StdCPPClass stdcls; is not allowed without prefixing the namespace with winrt.
Is this a bug or a design limitation that cannot be overcome?
or How can I use the same namespace 'NMLevel1::NMLevel2' in idl and cpp files?
Name lookup in C++ is fairly involved, especially when namespaces get essentially merged through using declarations. To help the compiler identify the name you want, you'll have to be explicit, and use a fully qualified name (as opposed to a qualified name, as in the sample).
You'll have to change
void Class::RuntimeMethod1()
{
NMLevel1::NMLevel2::StdCPPClass stdcls;
// ...
}
to
void Class::RuntimeMethod1()
{
::NMLevel1::NMLevel2::StdCPPClass stdcls;
// ...
}
Note the leading :: scope resolution, which limits lookup to the global scope (or namespaces introduced into the global namespace through a using declaration). You'll find additional information here: Qualified name lookup.

Does Haxe pickup on typedefs in interfaces and classes?

If I declare a typedef in a class or interface, can classes that import/implement the class/interface use the typedef?
You import a module, which can have a list of typedefs and direct definitions in it(and MUST have one definition with the same name as module). If definition isn't marked as private, it will be imported in your scope and you will be able to use it(with or without namespace).

In MEF, where is the container for the ImportingConstructor?

I'm trying to use the MEF ImportingConstructor in my class, and while I've used MEF successfully in the past, I've always started with creating the CompositionContainer to assemble all the exports.
What container does the ImportingConstructor use to satisfy it's imports?
You still need to create a container and either supply the exports yourself or supply catalogs to identify how to find the exports. Once those are provided, the imports are resolved from the container used to get the exported value.
So if you have:
[Export]
public sealed class A
{
}
[Export]
public sealed class B
{
[ImportingConstructor]
public B(A a)
{
}
}
Then you call container.GetExportedValue<B>(), it will look in the catalog to find the export for B, then find the importing constructor, then try to resolve the import for A. Assuming that class A is part of your available exports (either added explicitly or, more typically, part of a catalog), it will then get the exported value of A (possibly constructing it) and use that to construct B.
Assuming that your confusion is over the catalogs part of this, check out this guide. Basically you just need to add catalogs for the assemblies whose exports you want exposed.

Reference C++ managed class library from C# class library

How to reference class library from C++ managed? I can reference C++ managed library from another C++ managed library and use classes from it. But when i reference it from C# library it does not provide classes and namespaces from C++ (object browser show classes as well).
C++ Managed Class library1
namespace ns1{
public ref class Class1{};
}
C++ Managed Class library2
using namespace ns1;
namespace ns2{
public ref class class2{
ns1::Class1 _cl;
};
}
And i can not do the same from C# class library.
VS 2010 can not reference C++ managed library from C# as 'Project reference'.
It is necessary to reference .dll file.
Did not you forget public keyword?
Class definition should look like this:
public ref class MyClass
{
}
to be accessible from another assembly.

How to solve confilct between two namespace?

If I have namespace with two classes. I want to use class from one namespace and I have Resharpner tool. Even I select full qualifies name of my Font class it will use Font from System namespace. How to use label and will it removed debugging capability
using System.Windows.Forms;
using Cy.GlobalSettings.ChartSettings;
but have problem
current namespace is Cy.GlobalSettings.ChartSettingsUC;
Font class has a confilct?
You can rename classes if the class name is the same in both referenced namespace. If both namespace have a class called Font you can create an alias for a namespace or a type:
using System.Windows.Forms;
using Cy.GlobalSettings.ChartSettings;
using CyFont = Cy.GlobalSettings.ChartSettings.Font // This is the full name of the Font class which is causing the conflict.
Font y; // class from System.Windows.Forms
CyFont x; // class from Cy.GlobalSettings.ChartSettings
After this you can use both Font and CyFont in your code without conflicts.
using Directive (C# Reference)
http://msdn.microsoft.com/en-us/library/sf0df423(v=vs.80).aspx
Fully qualified name should work as well.

Resources