parameters

Throw/do-not-throw an exception based on a parameter - why is this not a good idea?

那年仲夏 提交于 2021-02-08 13:38:52
问题 I was digging around in MSDN and found this article which had one interesting bit of advice: Do not have public members that can either throw or not throw exceptions based on some option. For example: Uri ParseUri(string uriValue, bool throwOnError) Now of course I can see that in 99% of cases this would be horrible, but is its occasional use justified? One case I have seen it used is with an "AllowEmpty" parameter when accessing data in the database or a configuration file. For example:

Custom arguments to std::set comparison function

本小妞迷上赌 提交于 2021-02-08 12:01:22
问题 I know how to pass a regular comparison class or function to set::set<>. I am writing some test code and I want to emulate some C libraries using STL's std::set and I want to be able to pass a C callback to the comparison object so a different comparison takes place. I have the following theoretical code: struct MyClass { int a; }; typedef bool (*user_callback_t)(void *, void *); class MyComparison { private: user_callback_t cb = nullptr; public: MyComparison(user_callback_t cb): cb(cb) { }

How do you pass a List<> of Lists<> to a background worker?

北城余情 提交于 2021-02-08 11:42:16
问题 I have a backgroundWorker that is processing two lists. I need to pass the Lists to the worker. the result is empty lists. Code to pass the Lists (and 2 other parameters). In my test, each list has 20+ items, and the List<> items show that the 20+ items are intact just prior to the call. In the inspector they say "Count" followed by the number of items. List<Object> arguments = new List<object>(); // Add arguments to pass to background worker arguments.Add(managerSource); arguments.Add

pass job parameters to custom writer Spring batch

雨燕双飞 提交于 2021-02-08 03:47:41
问题 I have a custom writer with a FlatFileItemWriter and i want to pass a job parameter( a output file) defined in the main class How can i deal with this ? Thank you very much CustomWriter public class PersonItemWriter implements ItemWriter<Person> { private FlatFileItemWriter<String> flatFileItemWriter = new FlatFileItemWriter<String>(); private Resource resource; @Override public void write(List<? extends Person> personList) throws Exception { flatFileItemWriter.setResource(new

pass job parameters to custom writer Spring batch

ⅰ亾dé卋堺 提交于 2021-02-08 03:46:24
问题 I have a custom writer with a FlatFileItemWriter and i want to pass a job parameter( a output file) defined in the main class How can i deal with this ? Thank you very much CustomWriter public class PersonItemWriter implements ItemWriter<Person> { private FlatFileItemWriter<String> flatFileItemWriter = new FlatFileItemWriter<String>(); private Resource resource; @Override public void write(List<? extends Person> personList) throws Exception { flatFileItemWriter.setResource(new

Using a generic parameter on overloaded methods

随声附和 提交于 2021-02-07 19:12:00
问题 Why does this program output Generic Value and not Hello world! : using System; class Example { public static void Print<T>(T value) { Console.WriteLine("Generic Value"); } public static void Print(string value) { Console.WriteLine(value); } public static void GenericFunc<T>(T value) { Print(value); } static void Main() { GenericFunc("Hello world!"); } } How is the generic method parameter being translated under the hood of C#? 回答1: Overload resolution is only done at compile-time. Since

What function signature should I use to return a reference to an object that might not exist?

余生长醉 提交于 2021-02-07 14:31:31
问题 I'm writing a simple container class in C++ similar to a map that stores objects indexed by a key. I'd like to provide an accessor function such as: V& getValue(const K &key); where I return a reference to the value. But I also wanted to handle the case where the key/value is not present and be able to return some status to the user (there could be some reasons why it is not there that I want to communicate back to the caller via some Status type). I suppose I could do the following but

Build an URL with parameters in R

拥有回忆 提交于 2021-02-07 12:18:28
问题 What is the best way to build a request URL with parameters in R? Thus far I came up with this: library(magrittr) library(httr) library(data.table) url <- list(hostname = "geo.stat.fi/geoserver/vaestoalue/wfs", scheme = "https", query = list(service = "WFS", version = "2.0.0", request = "GetFeature", typename = "vaestoalue:kunta_vaki2017", outputFormat = "application/json")) %>% setattr("class","url") request <- build_url(url) What I like about the code that I have now, is that I can easily

Build an URL with parameters in R

混江龙づ霸主 提交于 2021-02-07 12:17:22
问题 What is the best way to build a request URL with parameters in R? Thus far I came up with this: library(magrittr) library(httr) library(data.table) url <- list(hostname = "geo.stat.fi/geoserver/vaestoalue/wfs", scheme = "https", query = list(service = "WFS", version = "2.0.0", request = "GetFeature", typename = "vaestoalue:kunta_vaki2017", outputFormat = "application/json")) %>% setattr("class","url") request <- build_url(url) What I like about the code that I have now, is that I can easily

How to get parameters from the Angular ActivatedRoute

非 Y 不嫁゛ 提交于 2021-02-07 10:50:56
问题 I'm trying to get the prameter :id from my activated route using observables. When I print params on the console I get the right values for :id. But it's not the case for this.id. I get the value NaN. Can you tell me what is the problem export class RecipeEditComponent implements OnInit { id: number; editMode = false; constructor(private route: ActivatedRoute) { } ngOnInit() { this.route.params.subscribe( (params: {id: string}) => { this.id = +params.id; console.log(this.id); } ); } } 回答1: