namespaces

Using namespaces with classes created from a variable

孤者浪人 提交于 2020-01-26 14:13:00
问题 So I created these two classes //Quarter.php namespace Resources; class Quarter { ... } //Epoch.php namespace Resources; class Epoch { public static function initFromType($value, $type) { $class = "Quarter"; return new $class($value, $type); } } Now this is a a very simplified version of both, but is enough to illustrate my question. The classes as they are shown here will not work as it will not find the Quarter class. To make it work I could change the $class variable to $class = "

App runs normally but has “errors” during design time: “does not exist in namespace” and “an error occured when finding the resource dictionary”

限于喜欢 提交于 2020-01-25 23:56:11
问题 My application has certain errors, in its error box during design time, to do with it's resource dictionary. For example, in my Main Window a resource dictionary is called as follows; <Window.Resources> <ResourceDictionary Source="Resources.xaml"/> </Window.Resources> I get a blueline on the middle line saying "An error has occurred while finding the resource dictionary "Resources.xaml". Yet, the Resources.xaml is in the root folder of the project, and so is the MainWindow. I am aware that

How can I dynamically execute function in current scope and add it as property of the calling function?

≡放荡痞女 提交于 2020-01-25 11:08:33
问题 I have some code like this: def f1(): <some stuff here> . . . @mylib.codegen def f2(args): f1() <some more stuff here> mylib.py : def codegen(fn): src = inspect.getsource(fn) original_ast = ast.parse(src) new_ast = transform_ast(original_ast) code_obj = compile(new_ast, '<auto-generated>', 'exec') myscope = {} exec code_obj in myscope fn.generated_fn = myscope['name'] # Where name is the binding created by execing code_obj To summarize, mylib.codegen is a decorator which parses code of f,

How can I dynamically execute function in current scope and add it as property of the calling function?

≡放荡痞女 提交于 2020-01-25 11:06:22
问题 I have some code like this: def f1(): <some stuff here> . . . @mylib.codegen def f2(args): f1() <some more stuff here> mylib.py : def codegen(fn): src = inspect.getsource(fn) original_ast = ast.parse(src) new_ast = transform_ast(original_ast) code_obj = compile(new_ast, '<auto-generated>', 'exec') myscope = {} exec code_obj in myscope fn.generated_fn = myscope['name'] # Where name is the binding created by execing code_obj To summarize, mylib.codegen is a decorator which parses code of f,

how do I access the return value of this ajax request?

大兔子大兔子 提交于 2020-01-25 08:28:20
问题 I have this code var stats = { GetMetaData : function() { var url = 'http://www.bungie.net/api/reach/reachapijson.svc/game/metadata/'+storage.get('apikey'); $.ajax({ url: url, success: function(data) { return data; } }); return 'abc'; } } I call the function using stats.GetMetaData(); I would expect the value returned to be the data variable from the ajax request. But instead it is the string 'abc' why is this? How can I return the data variable? I tried doing return $.ajax({ but that just

What is the best way to define a double constant in a namespace?

半腔热情 提交于 2020-01-25 04:40:14
问题 What is the best way to define a double constant in a namespace? For example // constant.h namespace constant { static const double PI = 3.1415926535; } // No need in constant.cpp Is this the best way? 回答1: I'd say: -- In c++14: namespace constant { template <typename T = double> constexpr T PI = T(3.1415926535897932385); } -- In c++11: namespace constant { constexpr double PI = 3.1415926535897932385; } -- In c++03 : namespace constant { static const double PI = 3.1415926535897932385; } Note

How to use same named class in PHP without namespacing?

回眸只為那壹抹淺笑 提交于 2020-01-24 10:42:08
问题 I have a problem, where I have two third party libraries classes that I have to extend and use together. But both have the same naming convention and two class name end up having the same name. Since I cannot extend two classes, I don't know how to fix them, how to create a wrapper against one. I cannot use PHP Namespaces as the PHP version is just 5.2.10 and not 5.3. What options I have? 回答1: I think you can implement rpc like interface, for one class. For other you can extend and use. http:

Class library reference problem

狂风中的少年 提交于 2020-01-23 12:49:10
问题 I am building a class library and using its default namespace as "System". There suppose I am creating a generic data structure say PriorityQueue and putting it under System.Collections.Generic namespace. Now when I am referencing that library from another project, I can't see PriorityQueue under "System.Collections.Generic" namespace anymore. Though the library is referenced in that project I can not access any of the classes in it. My question was mscorlib and System.dll share similar

How to assign and reference environment variables containing square brackets in Powershell

[亡魂溺海] 提交于 2020-01-23 12:27:46
问题 When the PSDrive is not specified, the following works: ${[foo]}="bar" echo ${[foo]} But the following does not work $env:${[foo]}="bar" At line:1 char:1 + $env:${[foo]}="bar" + ~~~~~ Variable reference is not valid. ':' was not followed by a valid variable name character. Consider using ${} to delimit the name. At line:1 char:6 + $env:${[foo]}="bar" + ~~~~~~~~~~~~~~ Unexpected token '${[foo]}="bar"' in expression or statement. + CategoryInfo : ParserError: (:) [],

Rust “use” vs. C++ “using namespace”

不打扰是莪最后的温柔 提交于 2020-01-22 18:33:14
问题 Is it considered bad style to declare multiple "use" statements in Rust? I am a C++ programmer that recently began trying out Rust. One thing I've noticed as I review Rust code is that in many Rust programs there will be a bunch of use statements at the top of the program. Coming from C++, it was discouraged to use using namespace std especially when making header files, but that doesn't seem to be the case in most of the Rust programs I've seen. So which of the following trivial examples is