Mono predefined macro? [duplicate] - c#

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I conditionally compile my C# for Mono vs. Microsoft .NET?
I have sqlite in my project and I'd like to run it in mono. The code is exactly the same for mono and nonmono however mono needs me to include a different namespace. Does mono have a predefined macro? Right now i define USE_MONO. Is there an official definition i can use?
#if USE_MONO
using Mono.Data.Sqlite;
#else
using System.Data.SQLite;
#endif

(From the duplicate question) The mono compiler defines __MonoCS__ for this purpose so you can use:
#if __MonoCS__
using Mono.Data.Sqlite;
#else
using System.Data.SQLite;
#endif

Related

How can I disable Top-level statements when using `dotnet new console`? [duplicate]

This question already has an answer here:
Create a Web API without top-level statements
(1 answer)
Closed 24 days ago.
I created a C# project with the below command in VSCode and enabled Top-level statements automatically for this project.
How can I disable Top-level statements in Visual Studio Code for a C# project?
dotnet new console --framework net7.0
Add --use-program-main. See the documentation for details.

How to share the "using" in multi-files? [duplicate]

This question already has answers here:
C#: Same "using" in multiple files
(2 answers)
using directive with whole program scope
(3 answers)
Closed 3 years ago.
I want to wrap some c\c++ dll to c#, and need to write some "using" statement to transfor some types, such as
using FoorInteger = int;
But it only works in single file. I must copy it to the other files.
How to make it works in multi-files just like the "#define " in c\c++ headers?
It works in C/C++ because of the #include directive, which tells the compiler "take everything from this other file and put it in this file". So any #define statements you have in the file you included are also defined in the file that has the #include directive.
There is no such thing in C#. There are other preprocessor directives that are similar to C/C++, but no #include. Since you cannot "include" another file, so there is no way to tell the compiler to include the using directives from another file.
You will need to copy the using directive to every file that uses it.

how to check type of processor architcture runtime [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Identifying the CPU architecture type using C#
my program is using diffrent assemblies for its final part.The problem is that amd and intelx64 assemblies are not fully compatible. Its is for an compiler im working on.
you could use exception handling, using try and catch.
try
{
// intel assembly
}
catch
{
// amd assembly
}

Mono compiler indication [duplicate]

This question already has answers here:
Compiler #if directive to split between Mono and .NET [duplicate]
(3 answers)
Closed 8 years ago.
Because Mono doesn't support some windows functions in .NET, is there any pre-compiler derivative that indicates that the compiler is a mono compiler?
Example, in Visual Studio there is a derivative #DEBUG and #TRACE is there such a derivative for mono that's something like `#MONO' that automatically is added if the compiler is mono?
Or do we have to add the derivative ourselves and change as necessary?
Mono compiler defines MonoCS, I think
So:
#if __MonoCS__
should work...

Library for parsing/modifying C# source code (and compiling after that) [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Parser for C#
Any (free) libraries that can parse C# source code and make a DOM of it?
I need to add an attribute to all classes in bunch of .cs files and then compile them to an assembly. This needs to be done in an asp.net application, so I'm not interested in Visual Studio plugins or similar.
I need to achieve this
input: ~/plugins/MyPlugin/MyPlugin.cs
public class MyPlugin : PluginBase, IEntitySavingPlugin
{
}
output: Plugins.dll
[PluginDirectory("~/plugins/MyPlugin/")]
public class MyPlugin : PluginBase, IEntitySavingPlugin
{
}
You can try to use Antlr Parser, a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions.
Support C#; C# 2 ;C# 3
http://www.antlr.org/
Duplicate of question Parser for C#.
Your best bet may be one of these:
http://csparser.codeplex.com/
http://wiki.sharpdevelop.net/NRefactory.ashx

Categories