| | |
Custom class object question
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
I have a custom class that is an entire structure within itself, many layers deep. However, this object is stored in memory through sessions. I need a way to retrieve the session variable without having to call it through a return method. An Example:
This is what I currently have to do:
I want to be able to cast it just like this, and retrieve it from the session at the same time:
I am not sure how to do this since I cannot return something from a constructor, and I cannot assign something to the class with the "this" keyword, or alike.
Thank you.
This is what I currently have to do:
ASP.NET Syntax (Toggle Plain Text)
ClassName variable = new ClassName().GetSessionObject(); variable.MethodCall();
I want to be able to cast it just like this, and retrieve it from the session at the same time:
ASP.NET Syntax (Toggle Plain Text)
ClassName variable = new ClassName(); variable.MethodCall();
I am not sure how to do this since I cannot return something from a constructor, and I cannot assign something to the class with the "this" keyword, or alike.
Thank you.
Last edited by SheSaidImaPregy; Dec 31st, 2008 at 10:05 pm.
I answer pm's.
I answer questions.
I answer quickly.
I answer.
I answer questions.
I answer quickly.
I answer.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
All GetSessionObject() would do is return the session variable and convert it into the ClassName object.
I have never heard of the class factory design pattern, and was an interesting read. However, it follows the pattern I was hoping to avoid, which would basically be creating the instance of a class and calling another method to return the session object. An example of what I have is below:
Now what I am trying to do is minimize the request and call only
Is it possible to do this? The best, but unavailable, method would be to re-assign the "this" reference, however, this is not allowed through csharp.
I have never heard of the class factory design pattern, and was an interesting read. However, it follows the pattern I was hoping to avoid, which would basically be creating the instance of a class and calling another method to return the session object. An example of what I have is below:
ASP.NET Syntax (Toggle Plain Text)
ClassName obj = new ClassName().GetSessionObject(); public class ClassName { public ClassName() { } public GetSessionObject() { return (ClassName)HttpContext.Current.Session["ClassName"]; } }
Now what I am trying to do is minimize the request and call only
ClassName obj = new ClassName(); instead of calling the additional GetSessionObject(); explicitly. Now it would be easy if ClassName was a container / wrapper, and there was another class beneath it that contained all the information, but this is not the case.Is it possible to do this? The best, but unavailable, method would be to re-assign the "this" reference, however, this is not allowed through csharp.
Last edited by SheSaidImaPregy; Jan 1st, 2009 at 9:53 am.
I answer pm's.
I answer questions.
I answer quickly.
I answer.
I answer questions.
I answer quickly.
I answer.
•
•
Join Date: Jul 2008
Posts: 49
Reputation:
Solved Threads: 7
Alright, that cleans things up a bit. The proper way to do this would be to create a static method GetSessionInstance() to return an instance of ClassName from session cache. This behavior is not instance-specific, meaning it doesn't and shouldn't rely on an existing instance of ClassName hence it should be static.
As far as overwriting the current class instance. For one thing you really cannot do this. Well, what you CAN do is retrieve your class from session cache and then simply assign every property of your current class instance to the one returned from session. This is ugly and most would tell you not to do this for the sake of software engineering practices.
Hope that helps.
As far as overwriting the current class instance. For one thing you really cannot do this. Well, what you CAN do is retrieve your class from session cache and then simply assign every property of your current class instance to the one returned from session. This is ugly and most would tell you not to do this for the sake of software engineering practices.
Hope that helps.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
All I will be doing for this is creating the large object when initialized and stored in a single session variable. When needed, it will be brought in and be a reference, so when updated, it will immediately reflect that within the session state. This is a relatively large application that relies on the session completely and only for this object. There will not be a lot of users for this, at least concurrent. At max, there will be 15 to 20 concurrent users, and more than enough memory, processing power, and everything to handle this at impressive speeds.
And thank you for your help, but that would still involve creating another class or repeated function, which in turn will still require me to reference it the way I am, one way or another. Thank you, though.
And thank you for your help, but that would still involve creating another class or repeated function, which in turn will still require me to reference it the way I am, one way or another. Thank you, though.
I answer pm's.
I answer questions.
I answer quickly.
I answer.
I answer questions.
I answer quickly.
I answer.
![]() |
Similar Threads
- Need Help in Collection (Java)
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
- adding columns (Java)
- creating a JOptionPane quiz (Java)
- GUI proram organization question (C++)
- Help with priority queues (C++)
- Audio: Reading Internet "Playlist" and outputting audio (Java)
- Help with < (less than) operator on classes (C++)
- Question about indexing objects (Java)
- ASP and SQL ? (MS SQL)
Other Threads in the ASP.NET Forum
- Previous Thread: regarding drpo down list
- Next Thread: a creative question
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances asp asp.net beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions compatible content contenttype countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv formatdecimal formview gridview gudi iis javascript list listbox menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order panelmasterpagebuttoncontrols problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl tracking treeview unauthorized validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers






