All Questions
168
questions
82
votes
9
answers
178k
views
C# Macro definitions in Preprocessor
Is C# able to define macros as is done in the C programming language with pre-processor statements? I would like to simplify regular typing of certain repeating statements such as the following:
...
52
votes
11
answers
31k
views
Why aren't there macros in C#?
When learning C# for the first time, I was astonished that they had no support for macros in the same capacity that exists in C/C++. I realize that the #define keyword exists in C#, but it is greatly ...
19
votes
6
answers
18k
views
C# version of __FUNCTION__ macro
Does anyone has a good solution for a C# version of the C++ __FUNCTION__ macro? The compiler does not seem to like it.
11
votes
4
answers
1k
views
How to Paste as Comment in VS2010?
This is a micro optimization that I'd have in my ideal IDE - the ability to paste from the clipboard directly into the editor as a comment. The idea is sometimes I feel like I lose entire seconds to ...
9
votes
2
answers
2k
views
Is there a method to swap the left and right hand sides of a set of expressions in Visual Studio?
I have a decent sized set of data that needs to be stored in an active record. In order to prepopulate the form fields on the page, I have already written the following code:
Device device = new ...
9
votes
2
answers
8k
views
DTE.ExecuteCommand and wait
I would like use macros for publishing my webapplication project. The little problem is, DTE.ExecuteCommand run asynchronously, and I need to wait until the command is done.
Example:
DTE.Windows....
8
votes
6
answers
1k
views
#define conversion from C to C#
Is this C code:
/* LERP(a,b,c) = linear interpolation macro, is 'a' when c == 0.0 and 'b' when c == 1.0 */
#define LERP(a,b,c) (((b) - (a)) * (c) + (a))
http://www.brucelindbloom.com/index.html?...
6
votes
3
answers
5k
views
GET_WHEEL_DELTA_WPARAM macro in C#
How would I go about using the GET_WHEEL_DELTA_WPARAM macro in C#?
6
votes
3
answers
2k
views
Is there a way to generate multiple files through one template/macro with Resharper?
When I write my APIs for applications I always follow a set pattern (who doesnt!?) that looks like this:
User (Folder/Namespace)
User.cs
UserDao.cs
UserDaoFactory.cs
UserService.cs
...
6
votes
4
answers
476
views
Implement similar properties within a class using a "template" in C#
I've been wondering for a time now - in C# is there a way to define a "template" for several properties within a class. Here is what I mean:
Let's assume I have the following class
class ...
6
votes
1
answer
1k
views
Run macro until the end of the file in Visual Studio
Is there some AddIn or extension for Visual Studio 2008 that will allow me to run Macro until the end of the file? I really hate holding CTRL+SHIFT+P and waiting until end of the file is reached.
5
votes
4
answers
4k
views
Why is post-compilation code injection a better idea than pre-compilation code injection?
So we all know that C# doesn't have a C-like macro pre-processor (and there's a good thread on why here). But now that AOP is gaining traction, it seems like we're starting to do stuff with post-...
5
votes
2
answers
3k
views
Scheduling to run a macro on every hour
Is there anyway to schedule a macro in Umbraco or a .ascx file to run every hour?
thanks
4
votes
4
answers
2k
views
Are there macro facility for Java or C#?
Macros are useful.
Therefore, I occasionally bemoan the absence of macros in Java and C#. Macros allow me to force in-line but allow me the code-manageability of non-macro code.
Is there any Java- ...
4
votes
2
answers
4k
views
Visual Studio user-defined property sheet macros in C#
I have inherited a C# solution where the projects have a configured "Post-build command line". In this command line, there are a couple of user-defined property sheet macros that copy various output ...
4
votes
1
answer
1k
views
How would I retrieve the fully qualified name of an identifier in a VS macro?
I'm trying to resolve the fully qualified name of a c# identifier at a certain point (cursor) of a code window, using a Macro (or even an Add-in) in Visual Studio 2008.
For example, if the cursor is ...
4
votes
2
answers
2k
views
C# macro-style generics
I am looking for a way to have generics which only exist at compile time for the purpose of code reuse: not having to copy/paste classes and methods. Just text replacement basically, like macros, with ...
3
votes
2
answers
3k
views
Create a macro for Microsoft Access via Interop
Is it possible to create a new macro using C# using the Interop library in Microsoft Access in a similar fashion as Word, Excel, or PowerPoint? In the other applications, you have access to Microsoft....
3
votes
4
answers
188
views
Is there any way to emulate "macros" in c#?
I’m trying to make CodeContracts in C# look more like statements so i need a tool that allows me substitute some code before the compiler sees it, if there is no way to do it i guess a Visual Studio ...
3
votes
7
answers
319
views
Macro-like structures in C# ==OR== How to factor out a function containing 'return'
I never thought I'd have a need for anything this (since macros are bad, right?), but it turns out I do.
I find myself repeating the following pattern over and over again in my code, dozens if not ...
3
votes
3
answers
2k
views
Creating Inline Functions and Macros
I know this is wrong (trying to code in C# with a C/C++ mindset).
But is it possible to create inline functions / inline recursive functions (til the Nth call) / macros in C#?
Because if I intend to ...
3
votes
1
answer
2k
views
Defining custom macros to be used in build events
I am trying to define custom macros like pretty commonly done in c++ solutions to be used in, but not limited to, build events in .net core.
For example, I would like to extend pre-defined macros such ...
3
votes
2
answers
859
views
Query custom table in form builder auto responder
I have a custom form built using Kentico form builder. In my form, I reference a custom table via a foreign key...meaning that my form stores the id that is a reference to my custom table data. In my ...
3
votes
1
answer
547
views
Find docs that have macros in C#
I'm trying to build a tool in C# that will trawl through a list of documents, and produce a list that have macros. I can't find a property that will let me identify such documents though.
Is there a ...
3
votes
2
answers
3k
views
Can I disable the generation of obj in the same directory for _every_ project I have?
I'm tidying my projects. And I found the way to remove the object folder with adding:
%TEMP%
In my projects. But I want somehow to make this global setting or to auto delete my obj dirs after a build....
3
votes
2
answers
580
views
C# GUI macro libraries or general approaches?
In a C# WinForms application (on .NET 3.5, probably 4.0 soonish), how would you go about allowing the user to define their own macros? For instance, a user could want the key press CTRL+K to mean ...
3
votes
0
answers
188
views
Umbraco 8 - Error in all.generated.cs when I add Macro inside RTE
When I try to add any kind of Macro (Even if it just includes an empty <Div>) into a RTE, it throws the next error:
Newtonsoft.Json.JsonSerializationException: Error getting value from '***' on '...
3
votes
1
answer
2k
views
error "the action was blocked by organization policy ms office 2016"
I am working on MS Office plugin. On MS Office previous version then 2016, it works fine but on MS Office 2016, I am getting an error "the action was blocked by organization policy ms office 2016". As ...
3
votes
0
answers
804
views
I need a Visual Studio macro to split one CS file with multiple classes into multiple files with single classes
I believe that this type of functionality is built into JetBrains ReSharper, which I've actively decided not to use (oh stop with your surprised face and gasping). Nothing against ReSharper, I just ...
2
votes
3
answers
8k
views
C# How to Select an Open Application Window
I'm trying to create a basic macro recording/playback system. If I wanted to select an open application (like notepad) to bring it to the front for input, how would I go about calling it by name or ...
2
votes
3
answers
348
views
Using Generics in c# in order to avoid code duplication
(Language is c# with VS 2008)
I have the following problem:
There are a number of structs (provided as is from 3rd party) that all implement certain methods with the same signatures.
I would like to ...
2
votes
3
answers
4k
views
replace placeholders in string
I have strings like below:
Insert into Emp(Id,Name,Number,Address) values({Id},"Abc",{Number},{Address});
In above string {Id} ,{Number} and {Address} are placeholders which I want to replace with ...
2
votes
3
answers
9k
views
Convert String or Char to Keys object
If I use the following code:
for (int i = 0; i < text.Length; i++)
{
char c = text[i];
Keys k = (Keys)(byte)c;
MessageBox.Show(c.ToString() + "|" + k.ToString());
}
...
2
votes
6
answers
245
views
Using AWK or SED to Duplicate Lines and Ultimately Create Method Wrappers
No solution found yet on stackoverflow for this simple question. Some answer it somewhat but I am a newbie at awk and sed.
I would like to create wrappers for my methods in my input code file. It has ...
2
votes
1
answer
9k
views
Sorry, we couldn't find Test.xlsm. Is it possible it was moved, renamed or deleted?
I am running a macro code from my C# application. I have placed the Test.xlsm file in the project itself with Properties:
Build Action: Content
Copy to Output Directory: copy always.
However, I get ...
2
votes
2
answers
123
views
Regex.Match not working for finding string contained in other text C#
I am using the following C# Regex call to find all instances of some macros that are placed in a text file:
MatchCollection matches = Regex.Matches(txt, @"/{macro:(.*?)}/");
but it is returning no ...
2
votes
1
answer
475
views
How to setup different Resources for different compile macros in Visual Studio?
I have a String resource that needs to have different value based on the conditional compile.
How to setup different Resources for different compile macros in Visual Studio 2008 Professional?
2
votes
4
answers
398
views
C# generic with similar classes
Suppose I have a C# class like:
class MyClass
{
String a, b, c, d;
int e, f, g, h;
}
Now suppose I also have:
class OtherClass1
{
String a, b, c, d;
int e, f, g, h;
}
and ...
2
votes
1
answer
736
views
Simplified C-macro-like function calls in C#
I'm writing a wrapper for a C dll. Various C functions are wrapped for C# applicatons. Now consider some simplified part of the wrapper below.
public enum ErrorCode
{
OK = 0,
...
...
}
...
2
votes
1
answer
4k
views
no overload for method 'Open'/'Run' takes '1' arguments
I met this problem as title showed when I editing script task in C # in SSIS, I tried several solutions found online, but don't work. can you find out why?
using Microsoft.VisualBasic;using System;
...
2
votes
1
answer
2k
views
Excel Interop C# Can't add VBProject Error 800A03EC on Workbook.VBProject.VBComponents.Add(..)
I) Global Explanation
Hello,
I'm developing an app in C# using Microsoft.Office.Interop.Excel. In my case I implement some olds macros stored in a file to an Excel Workbook, opened by C#, to upgrade ...
2
votes
2
answers
2k
views
How to find and use process ID to send keystroke to Excel application in C#
A process is identified by filtering parent process ID numbers,
when the correct process is found that should receive a keystroke.
This application is an Excel workbook. A macro is run inside this ...
2
votes
2
answers
535
views
Visual Studio 2012 - How to automate open close curly brace?
In Visual Studio 2012 I created a macro to create an open curly brace, create a new line, create a new line, create closing brace and move cursor one line up followed by a TAB.
That macro was ...
2
votes
0
answers
211
views
Compile code based on which version of Visual Studio you are using with .Net
Is there a way to detect Visual Studio version via a macro or code? (C#)
I'm trying to maintain a repository whose codebase is written in C# where users are using both VS2015/VS2019. So far I have ...
2
votes
0
answers
457
views
Is it possible to write Visual Studio 2010 macros in C#? [duplicate]
Possible Duplicate:
C# for writing macros in Visual Studio?
Is there a way to write Visual Studio 2010 macros in C#? If not, any idea when this will be possible?
2
votes
2
answers
789
views
How does someone go about writing a "macro" in C#?
I know something about MACROS. I don't mean the ASSEMBLY language kind. I am talking about those programs that you can use perform repetitions actions on another program. I am talking about those ...
1
vote
8
answers
4k
views
Is there a way in Visual Studio to convert text to a C# string literal?
Is there a way in Visual Studio to convert text to a C# string literal and back?
For example if I have the text:
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh ...
1
vote
4
answers
221
views
C++ What is this simple macro doing?
I'm converting a C++ application in C# and managing to work my way through most of it. However I'm stuck with the following statement:
#define GET_SHCALL_ID(L) (((L) >>...
1
vote
2
answers
1k
views
Visual Studio Macro - Code Gen Language
I am writing a macro for Visual studio that will generate some code.
I would like for the macro to generate for both C# and VB, is there a way to determine what language is being used in the active (...
1
vote
1
answer
3k
views
Kentico macro method inside template not working
I have recently been working on Kentico sites, and the following issue has occurred recently, and never thought this won't work.
I have got a template on Kentico 8, and I want to display the content ...