How to solve confilct between two namespace? - c#-4.0

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.

Related

Additional GS1 codes support in Acumatica

We need to add support for GS1 Barcode Customer Part Number in the Purchases - Receive and Put Away screen, it is not supported by default and I can't a find a way to add it.
From looking at the source code, it seems like I need to override GS1Support property or the GetGS1ApplicationSteps() method on PX.Objects.PO.WMS.ReceivePutAway class but I can't find a way to to this. I tried to override using PXGraphExtension method:
public class ReceivePutAway_Extension : PXGraphExtension<ReceivePutAway>
{
}
but then I get the following error:
CS0311 The type 'PX.Objects.PO.WMS.ReceivePutAway' cannot be used as type parameter 'Graph' in the generic type or method 'PXGraphExtension'. There is no implicit reference conversion from 'PX.Objects.PO.WMS.ReceivePutAway' to 'PX.Data.PXGraph' class.
UPDATE:
After updating the extension class declaration as suggested, now the error is gone but I'm still unable to find a way to override GetGS1ApplicationSteps() method on the BLC extension class PX.Objects.PO.WMS.ReceivePutAway, .
Does anybody know how to make the override work for a class like this or maybe has good suggestion on how to add support for additional GS1 barcodes?
ReceivePutAway is not a Graph, therefore you cannot do a simple Graph Extension directly on it. ReceivePutAway inherits from WMSBase which is actually defined as a Graph Extension. This means that you need to end up with a second level graph extension.
If you need to customize ReceivePutAway, I would suggest to try the approach mentioned here:
https://help-2021r1.acumatica.com/(W(1))/Help?ScreenId=ShowWiki&pageid=c86fdae8-fef9-4490-aa57-3528d0fa172e
Refer to section 'Second-Level BLC Extension' in the above link. In your case, it might be something like this:
public class ExtensioReceivePutAway_Extension :
PXGraphExtension<ReceivePutAway, ReceivePutAwayHost>
{
}

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.

MonoTouch Binding - Binding #DEF from separate header

I'm binding a ObjC library and it all works well, but I have one problem.
The ObjC library is using some values that are defined in a separate header.
For example, a header with:
#define SOME_PROPERTY_1 TRUE
#define SOME_PROPERTY_2 TRUE
#define SOME_PROPERTY_3 FALSE
Dependant on these properties, the library will make some changes to the view (so these changes are in the library, not in my C# code).
I would like to have access to these properties from my C# code so that I can change them. Now I need to build my library again if I want to change them and I can't change them dynamically (what the goal is).
Is this possible?
I have searched on this, but I didn't understand the two proposed solutions:
Putting them in my C# code instead of in my binding
-> I assume this is not a solution, because in that case the library will not know about these changes? (no connection)
Binding them as (static) properties
Unfortunately, I don't know how to do this. In this header, these is no Class/Interface, only #DEF statements, so I don't know in which 'class' I should define these properties.
The header is then included in some other ObjC classes. I was trying to see if I could define them there, but it's an interface and properties are not accepted.
So basically, there is a "SomeController" class that I'm binding and the "SomeController.h" is defined as interface
#interface SomeController : UIViewController
And in the "SomeController.m" you then have
#import "Constants.h" //The file with only #DEF statements
#implementation SomeController
{
...
}
Any ideas?
Regards,
Matt
This is not possible, because your SOME_PROPERTY_# aren't actually variables, they're preprocessing directives.
This means that the ObjectiveC preprocessor will replace all instances of SOME_PROPERTY_# in your source code with the value you defined it to be, but there is no SOME_PROPERTY_# variable/constant in the final executable.
For example:
#define SOME_PROPERTY_1 TRUE
void foo ()
{
Bool value = SOME_PROPERTY_1;
}
will be converted to this by the preprocessor:
void foo ()
{
Bool value = TRUE;
}
As you can see there is no SOME_PROPERTY_1 in the converted source code.
This means that you can't change the value of SOME_PROPERTY_# dynamically.

Conflict in namespace in C#

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;

Namespace nesting in C++/CLI

I know nesting of namespaces is allowed in C++/CLI. So my question is if we have something like this:
...
namespace one
{
// blah blah blah
// ...
namespace two
{
// another set of blah blah blah
// ...
}
}
and I need to use some functions and variables in namespace two, do I use:
one::two
or
one.two
Another question is that if I have a statement like
using namespace one;
do I have access to variables and functions in any nested namespaces like
namespace two
I'm asking because, in some programs I have seen (and written), there's something like:
using namespace System;
using namespace System::Text;
using namespace System::IO;
Isn't the System namespace supposed to cover the System::Text and System::IO namespaces?
You need to use
one::two::some_variable_or_function
The . operator is for accessing non-static struct/class members. Static members can then again be accessed through the scope resolution operator ::.
If you only would use using System;, you could access the System::Text functions/variables by
Text::some_function_or_variable
using the parent namespace does not imply importing all sub-namespaces.
Yes, you need use one::two instead of one.two to access symbols in a nested namespace.
If you just using namespace one; you don't automatically have the access to the nested namespace. You'll have to use two::
Example:
namespace one
{
int i;
namespace two
{
int j;
}
}
If you use:
using namespace one;
Your code looks like:
i = 1;
two::j = 2;
If you use:
using namespace one;
using namespace one::two;
Your code looks like:
i = 1; //Compile fails if no "using namespace one".
j = 2;
one::two
or
one.two
You need to use one::two. one.two is the syntax for package access in Java
Another question is that if I have a
statement like
using namespace one;
do I have access to variables and
functions in any nested namespaces
like
namespace two
No, you can use them as two:: instead of one::two::
I'm asking because, in some programs I
have seen (and written), there's
something like:
using namespace System;
using namespace System::Text;
using namespace System::IO;
Isn't the System namespace supposed to
cover the System::Text and System::IO
namespaces?
No, they aren't the same. You have to specify usage of each child namespace.
In general, you use the dot only when you're referring to a member of an instance, and :: everywhere else. So to access stuff in your namespace two, you'd call it one::two::whatever.
As for using namespace System;, it'd import stuff from the System namespace. While System::IO and System::Text are in System, it doesn't import them directly into the current namespace. AFAIK you'd be able to say using namespace System; and then refer to a class within a nested namespace as, say, IO::Stream. But that would get confusing fast, if you use a bunch of namespaces.
1) one::two
2) using a parent namespace doesn't automatically expand any nested namespace.

Resources