static-methods

using static Dictionary instead of session asp.net mvc

白昼怎懂夜的黑 提交于 2019-12-25 08:48:37
问题 i have serialization problem with session(as i described here) so i used static Dictionary instead of session asp.net mvc public static Dictionary<string, object> FlightDict; FlightDict.Add("I_ShoppingClient", client); in this case user will override their values?are there any problem with that because they says with static variable users data can be overrided 回答1: Yes, you can change the static variables in the site, But You need to use this to change the data but that is not enough you need

How to access all specific versions of a generic static class in C#?

≯℡__Kan透↙ 提交于 2019-12-25 05:26:28
问题 Let's say I have the following static class: public static class Foo<T> { private static T Baz; /* other members */ public static void Bar() { //do something with Baz } } Is there a built-in way to call Bar() for all specific versions of the generic class without knowing the type parameters that were used? That is, if the consumer of Foo<T> has used it as Foo<Larry> , Foo<Curly> and Foo<Moe> , how can I call all the Foo<Larry>.Bar() , Foo<Curly>.Bar() etc. methods automatically without

F# Extension Methods on Lists, IEnumerable, etc

雨燕双飞 提交于 2019-12-25 04:45:32
问题 In C#, if I had a widget definition, say: class widget { public string PrettyName() { ... do stuff here } } and I wanted to allow for easy printing of a list of Widgets, I might do this: namespace ExtensionMethods { public static PrintAll( this IEnumerable<Widget> widgets, TextWriter writer ) { foreach(var w in widgets) { writer.WriteLine( w.PrettyName() ) } } } How would I accomplish something similar with a record type and a collection (List or Seq preferrably in F#). I'd love to have a

How to call a static function?

扶醉桌前 提交于 2019-12-25 02:43:36
问题 I have defined 2 functions in my class Matrix as follows (in Matrix.hpp) static Matrix MCopy( Matrix &a ); static Matrix MatInvert( Matrix &x ) static double MatDet( Matrix &x ); // Matdef function In my Matrix.Cpp file, I defined these functions as follows: Matrix Matrix::MatCopy( Matrix &a ) { Matrix P( a.getRow() , a.getCol() , Empty ); int j=0; while( j != P.getRow() ){ int i=0; while( i != P.getCol() ){ P(j,i)=a(j,i); ++i; } ++j; } return P; } Matrix Matrix::MatInvert( Matrix &x ) {

Why am I not able to find static methods through Expression Language

戏子无情 提交于 2019-12-25 02:41:52
问题 I was having a class MyClass with a static method getmyStaticMethod() While trying to access this method through EL in my jsp : ${MyClass.myStaticMethod} It was giving me unable to find the value for "myStaticMethod" in object of the class MyClass is it because the static method being at Class level and the EL looking only at the Object level is not able to find it ???? Thanks in advance. :) 回答1: The JSP EL can't access static methods of classes. ${MyClass.myStaticMethod} means: find an

Using this in parameters of static methods in static class?

眉间皱痕 提交于 2019-12-25 02:29:13
问题 Why should I use 'this' in static functions of static classes to objects in parameter? I mean is the real difference between using those 2 methods? public static class Extensions { public static string AsJson(this object obj) public static string AsJson2(object obj) } 回答1: public static string AsJson(this object obj) Its is an Extension Method on type object Extension methods are defined as static methods but are called by using instance method syntax. Their first parameter specifies which

Static methods on ASP.NET web sites

寵の児 提交于 2019-12-24 19:29:24
问题 i was wondering.. if i have a static method on an asp.net web site (plain vanilla), is that accessible by all users of all sessions? I guess what i am saying is the single instance of a method available to each client? or is there 1 instance for all clients for the site.. 回答1: The static value is the same for all users on the same pool. Different pools have different static values. The session have nothing to do with the static values, and the users that are on the same pool have the same

How to cover a method calling a static method using JUnit mocking?

自作多情 提交于 2019-12-24 15:03:52
问题 Consider two classes A and B . class A { static int a(){} } class B { void something(){ int value=A.a(); .......}} Now I have to cover class B using Junit Test case and hence I create a new class (class TestB ) to cover the class B . class TestB { @Test public void testsomething(){...} } Here my question is if there is any way I can cover the line A.a() as this is the static method. I know that I can't easy mock it because there is no object involved. So how would I proceed? I am using JUnit

__callStatic doesn't handle missing static calls

∥☆過路亽.° 提交于 2019-12-24 13:06:15
问题 class Foo { public function bar(){ echo "Non-static\n"; } public static function __callStatic($name, $arguments) { if ($name === 'bar') { echo "Static\n"; } } } Foo::bar(); Class Foo does not have a static bar method. That is why I was expecting the Foo::bar() to be handled by the __callStatic method. Unfortunately for me that's not happening for some reason. The non-static method is being called on null instead. Is it a bug or a feature? How can I make the __callStatic to handle that call of

How to change attribute of object in C++ from static method

喜欢而已 提交于 2019-12-24 11:37:40
问题 How to change object attribute from static method in C++? My method must be static. Code: class Wrapper { private: double attribute; //attribute which I want to change public: Wrapper(); ~Wrapper(); static void method(double x); } I tried: std::string Wrapper::method(double x) { attribute = x; } But: error: invalid use of member ‘Wrapper::attribute’ in static member function 回答1: A static member function cannot access a non-static member because there is no object whose member you'd be