
.. _c-sharp-users-page:

##################################
C# Users: Features and Differences
##################################

*************
Documentation
*************

|ProductName| is written in C++ and the C# version is provided as a wrapper layer on top of this. Because of this, 
all documentation and tutorial snippets are provided in C++ only.
As a result, all documentation and tutorial snippets are exclusively available in C++. Thanks to the strong similarities 
between C++ and C#, comprehending class and function descriptions as well as code examples in the C++ documentation 
should pose no significant challenge for C# developers.

**********
Namespaces
**********

While the namespaces in C++ are quite short (``cee::ug``, ``cee::vis``, ...) the namespaces in the C# version have been written 
out with long names. The main namespace ``cee``, is in C# replaced with ``Ceetron.CeetronEnvision``. 
All namespaces under cee are renamed as follows:

-   vis -> Visualization
-   geo -> Geometry
-   ug -> UnstructGrid
-   win -> Win
-   exp -> Export
-   vtfx -> VTFx
-   imp.cae -> ImportCae
-   rep -> Report
-   plt -> Plot2d

All members of the Core component are located on the root namespace ``Ceetron.CeetronEnvision``. Note that the same applies 
to C++ where they are located directly in the ``cee`` namespace.

**********
Properties
**********

The C# version uses properties instead of the standard set'ers and get'ers in C++. For instance, the visibility for an 
object is typically accessed using visible()/setVisible() in C++, while in C# it will be a property called Visible.

.. code-block:: cpp

    // C++
    part->settings()->setVisible(true);

    // C#
    part.Settings.Visible = true;


***********
Inheritance
***********

Due to limitations in the C# wrapper layer, there is a special handling of inheritance in the C# version of |ProductName|.
The problem is downcasting objects that are fetched from within |ProductName|. For instance:

.. code-block:: cs

    Model model = myView.model(0);  // Get the first model (GeometryModel) from the Visualization.View instance. 
    GeometryModel normalCastGeometryModel = model as GeometryModel;                 // null due to wrapper limitations
    GeometryModel ceeCastGeometryModel = GeometryModel.castFromBaseClass(model);    // Correct cast
    MarkupModel ceeCastedWrongModel = MarkupModel.castFromBaseClass(model);         // null due to wrong cast

In this scenario, we KNOW that the first model in the view is of type GeometryModel, but casting using "as" will fail 
and normalCastGeometryModel will be null. To work around this limitation, we have provided casting methods for all such
classes. Using the static castFromBaseClass will always give you a correct cast. For an invalid cast, the returned value 
will be null.

This downcasting issue **only** applies to objects retrieved from Envision toolkits. Casting will always work for 
classes created and managed in your application. For instance:

.. code-block:: cs

    Model myModel = new GeometryModel();
    GeometryModel normalCastMyGeometryModel = myModel as GeometryModel;
    GeometryModel ceeCastMyGeometryModel = GeometryModel.castFromBaseClass(myModel);


In this case, both cast methods are valid and return the correct object of type GeometryModel. 

**********
Deployment
**********

For |ProductName|, the development language is C++, which means that any product developed using one of our toolkits 
must are depending on Visual C++ redistributables. For more information on deployment of Visual C++ based applications, 
see `Deployment in Visual C++ <https://learn.microsoft.com/en-us/cpp/windows/deployment-in-visual-cpp>`_

Using the redistributable packages is recommended because they enable automatic updates of the Visual C++ libraries.
The latest Visual C++ Redistributable Packages for Visual Studio 2015-2022 can be downloaded using this permalink for 
the latest supported x64 version: https://aka.ms/vs/17/release/vc_redist.x64.exe


