compiler-directives

Getting rid of precompiler directives in C#

℡╲_俬逩灬. 提交于 2019-12-07 03:04:15
问题 I've been asked to maintain some not-as-legacy-as-I-would-like code, and it is riddled with compiler directives, making it pretty much unreadable and almost as maintainable. Case in point: #if CONDITION_1 protected override void BeforeAdd(LogEntity entity) #else protected override void BeforeAdd(AbstractBusinessEntity entity) #endif { #if CONDITON_1 entity.DateTimeInsert = DateTime.Now; #else ((LogEntity) entity).DateTimeInsert = DateTime.Now; #endif base.BeforeAdd(entity); } using directives

Where do I define symbols tested with {$IFDEF}?

霸气de小男生 提交于 2019-12-05 14:14:42
问题 When I use Delphi directives in code, like: {$IFDEF something} . . . {$ENDIF} Where do I assign the word 'something' in the project? I tried in some places in project options but it didn't work. Guess I didn't find the correct one. 回答1: It's in the Conditional Defines slot under Project | Options, which looks like this on D2010: 回答2: Other answers have pointed you at the places to define symbols and the scope implications of the different approaches. However, what no-one has yet mentioned is

How to set project wide #define in C#

自闭症网瘾萝莉.ら 提交于 2019-12-05 09:52:59
问题 I have several classes in a project which need to only be in certain builds of the application which are currently not ready for release or debug. To prevent these classes from being used, I want to set around them this: #if USE_MYCLASS // Code here... #endif Unfortunately, I don't know how to setup a project wide #define. Is there a functionality in Visual Studio to set project wide definitions. If there is, though I don't need it right now, is there a functionality to set solution wide

Getting rid of precompiler directives in C#

回眸只為那壹抹淺笑 提交于 2019-12-05 07:19:01
I've been asked to maintain some not-as-legacy-as-I-would-like code, and it is riddled with compiler directives, making it pretty much unreadable and almost as maintainable. Case in point: #if CONDITION_1 protected override void BeforeAdd(LogEntity entity) #else protected override void BeforeAdd(AbstractBusinessEntity entity) #endif { #if CONDITON_1 entity.DateTimeInsert = DateTime.Now; #else ((LogEntity) entity).DateTimeInsert = DateTime.Now; #endif base.BeforeAdd(entity); } using directives are even prettier: #if CONDITION_1 using CompanyName.Configuration; #endif #if CONDITION_2||CONDITION

#warning directive in VB.net

匆匆过客 提交于 2019-12-05 03:25:26
I know the #warning directive does not exist in vb.net... is there anything like it? I want to be able to throw messages (warnings) at compiler time. As far as I've ever been able to find... no. 来源: https://stackoverflow.com/questions/192822/warning-directive-in-vb-net

Implicit casting Integer calculation to float in C++

亡梦爱人 提交于 2019-12-04 16:43:38
Is there any compiler that has a directive or a parameter to cast integer calculation to float implicitly. For example: float f = (1/3)*5; cout << f; the "f" is "0", because calculation's constants(1, 3, 10) are integer. I want to convert integer calculation with a compiler directive or parameter. I mean, I won't use explicit casting or ".f" prefix like that: float f = ((float)1/3)*5; or float f = (1.0f/3.0f)*5.0f; Do you know any c/c++ compiler which has any parameter to do this process without explicit casting or ".f" thing? If you don't like either of the two methods you mentioned, you're

How can I temporarily disable the “return value might be undefined” warning?

时光毁灭记忆、已成空白 提交于 2019-12-04 00:59:04
I want to disable a specific warning (W1035) in my code, since I think that the compiler is wrong about this warning: function TfrmNagScreen.Run: TOption; begin if ShowModal = mrOk then Result := TOption(rdgAction.EditValue) else Abort end; There is no way the result could be undefined, since Abort throws EAbort . I tried: {$WARN 1035 Off} : Apparently this only works for some specific errors (see Documentation ) {$W-1035} : Does nothing at all I know I can switch off the warning globally in the project options, or using {$WARNINGS OFF} , but that is not what is intended here. Edit: I have QC

Where do I define symbols tested with {$IFDEF}?

末鹿安然 提交于 2019-12-04 00:26:52
When I use Delphi directives in code, like: {$IFDEF something} . . . {$ENDIF} Where do I assign the word 'something' in the project? I tried in some places in project options but it didn't work. Guess I didn't find the correct one. It's in the Conditional Defines slot under Project | Options, which looks like this on D2010: Other answers have pointed you at the places to define symbols and the scope implications of the different approaches. However, what no-one has yet mentioned is that if you change the DEFINE symbols you MUST do a FULL BUILD of your project for them to have any effect on

Delphi #IF(DEBUG) equivalent?

爱⌒轻易说出口 提交于 2019-12-03 11:27:56
问题 Is there a Delphi equivalent of the C# #if(DEBUG) compiler directive? 回答1: Use this: {$IFDEF DEBUG} ... {$ENDIF} 回答2: Apart from what lassevk said, you can also use a few other methods of compiler-evaluation (since Delphi 6, I believe) : {$IF NOT DECLARED(SOME_SYMBOL)} // Mind you : The NOT above is optional {$ELSE} {$IFEND} To check if the compiler has this feature, use : {$IFDEF CONDITIONALEXPRESSIONS} There are several uses for this. For example, you could check the version of the RTL;

Conditional compile when running in Simulator as opposed to on a device

烈酒焚心 提交于 2019-12-03 04:46:08
问题 Is there a compiler directive I can use to compile a different line of code when targetting the simulator as opposed to my device. Something like: # IF SIMULATOR [self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; # ELSE [self.imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera]; # END EDIT Direct link to docs. 回答1: #if TARGET_IPHONE_SIMULATOR [self.imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary]; #else [self.imagePicker