天道酬勤,学无止境

initialization

Initializing AutoMapper in an Azure Function

I am trying to create an Azure function in which I am using some code with AutoMapper. I am quite new to C#, Azure and AutoMapper and I'm having some trouble finding the correct way of initializing my AutoMapper configuration. MapInitializer.cs: public static class MapInitializer { public static void Activate() { Mapper.Initialize(cfg => { // initialize mappings here }); } } Then in my function, I am trying to do the following: Function.cs: public static class ProcessQueueForIntercom { [FunctionName("ProcessQueue")] public static void Run([QueueTrigger("messages")]string myQueueItem

2021-06-14 15:22:38    分类:问答    c#   azure   initialization   automapper   azure-functions

Is there a way to force static fields to be initialized in C#?

Consider the following code: class Program { static Program() { Program.program1.Value = 5; } static List<Program> values = new List<Program>(); int value; int Value { get { return value; } set { this.value = value; Program.values.Add(this); } } static Program program1 = new Program { value = 1 }; static Program program2 = new Program { value = 2 }; static Program program3 = new Program { value = 3 }; static void Main(string[] args) { if (Program.values.Count == 0) Console.WriteLine("Empty"); foreach (var value in Program.values) Console.WriteLine(value.Value); Console.ReadKey(); } } It prints

2021-06-14 10:54:43    分类:问答    c#   static   initialization

Implementation of dynamic initialization for global variables and static member variables in C++

I have some questions about the implementation of variable initialization in C++ in regards to the linking and executable module loading process. My main concern is with dynamic initialization of global variables and static member variables, wherein the initialization process involves the execution of code. I'm looking for the answer to address my questions for both Windows and Linux. I already understand that in the case of static initialization: -the initial value is placed into its own section during compilation -the sections are mapped into memory by the OS module loader -the variable is

2021-06-14 08:15:23    分类:问答    c++   static   linker   initialization

Double brace initialization - Advantage

Got to know that we can initialize a collection in java by using double brace initialization. And did some search on that and found that it is not advised to use it because of its performance issue. private static final Set<String> VALID_CODES = new HashSet<String>() {{ add("XZ13s"); add("AB21/X"); add("YYLEX"); add("AR2D"); }}; Just want to know, is there any positive side or advantage of DOUBLE BRACE INITIALIZATION??

2021-06-14 08:11:15    分类:问答    java   collections   initialization

Might not have been initialized error at null check

I'm checking if the variable is initialized but at that point netbeans is giving me variable reader might not have been initialized warning. How do I fix/suppress this? This is my code (summary): final Reader reader; try { reader = new Reader(directory); //additional stuff that can cause an exception } catch (Exception ex) { //do stuff } finally { if (reader != null); } The point of the if check is to determine whether it is initialized. And what is the best practice for this?

2021-06-14 08:01:35    分类:问答    java   initialization   final

Different ways to initialize variables

There are different ways to initialize a variable in c++. int z(3) is same as int z=3. Is int z; z(3); same as int z; z=3; ?

2021-06-14 07:43:25    分类:问答    c++   variables   initialization

“Uninitialized use” warning in the g++ compiler

I’m using g++ with warning level -Wall -Wextra and treating warnings as errors (-Werror). Now I’m sometimes getting an error “variable may be used uninitialized in this function”. By “sometimes” I mean that I have two independent compilation units that both include the same header file. One compilation unit compiles without error, the other gives the above error. The relevant piece of code in the header files is as follows. Since the function is pretty long, I’ve only reproduced the relevant bit below. The exact error is: 'cmpres' may be used uninitialized in this function And I’ve marked the

2021-06-14 06:49:45    分类:问答    c++   g++   warnings   initialization

Is it okay to call an init method in self, in an init method?

Recently I realized I needed to add an argument to the init method for a helper class I've got. The helper class deals with alert views so it already has a bunch of arguments in the init, which are looked at, tweaked, and then sent on to the alert view. Since I'm using the method as it is in various places, I don't want to risk crashing (by missing one of those places and getting an 'unrecognized selector' in the hands of a customer) so I decided to add a second init method. I.e. - (id)initWithA:B:C:D: and - (id)initWithA:B:C:foo:D: Right now I've simply copy pasted the first one's

2021-06-14 04:11:48    分类:问答    objective-c   initialization

How to initialize 'attr_accessor' attribute values? [duplicate]

This question already has answers here: Closed 8 years ago. Possible Duplicate: attr_accessor default values I am using Ruby on Rails 3.0.9 and I would like to initialize some attr_accessor attribute values in my class\model that inherits from ActiveRecord::Base. That is, ... in my module I have: class User < ActiveRecord::Base attr_accessor :attribute_name1, :attribute_name2, :attribute_name3, ... end and I would like to set to true all attr_accessor attribute values. How can I do that? P.S.: Of course I would like to solve the above issue approaching "à la Ruby on Rails Way". I know about

2021-06-14 03:56:34    分类:问答    ruby-on-rails   ruby   ruby-on-rails-3   attributes   initialization

Possible to prevent init from being called?

I'm editing the original question because we're all focusing on SHOULD you ever want to do this. My question is simply CAN I do this and HOW (understanding that there may be several solutions). So I'm just going to leave the actual question and cut out the background. Suppose I have a base class and a child class. Is there anything I can do in the base class to prevent __init__ from being called on the child class - or at least throw an exception or even log if __init__ exists or is called on the child class? I do want the __init__ method to be called on the parent class. Edit/Conclusion -

2021-06-14 03:41:45    分类:问答    python   initialization