[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

c# function

Posted on 2011-05-03
6
Medium Priority
?
418 Views
Last Modified: 2012-05-11
Hi,

Can somebody explain to me what this function doing here please? as I don't know much about web development:

 private static object RequestObject
        {
            get
            {
                object loRequestObject;

                if (HttpContext.Current != null &&
                    HttpContext.Current.Request != null)
                {
                    loRequestObject = HttpContext.Current.Request;
                }
                else if (WebOperationContext.Current != null &&
                    WebOperationContext.Current.IncomingRequest != null)
                {
                    loRequestObject = WebOperationContext.Current.IncomingRequest;
                }
                else
                {
                    loRequestObject = null;
                }

                return loRequestObject;
            }
        }
0
Comment
Question by:ube100
6 Comments
 
LVL 23

Assisted Solution

by:Saqib Khan
Saqib Khan earned 501 total points
ID: 35517400
its not really a Function, its a READ ONLY PROPERTY.  a readonly properly almost does the same job as a function...it RETURNS a value.

Your Function basicly returns CURRENT Context(URL) of the Page/Service OR it reads the incoming data coming from different source.

so loRequestObject  is of type Object. your function is returning an object of type HttpContext.Current.Request
 OR WebOperationContext.Current.IncomingRequest

WebOperationContext.Current.IncomingRequest = A helper class that provides easy access to contextual properties of Web requests and responses.

0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35517959
Hi, it will return the available Request object based on the current context of your code.

I meant, if it is called from an aspx page it will return HttpContext.Current.Request, but if it is called from another kind of application and HttpContext.Current.Request is not available then will try to return the WebOperationContext.Current.IncomingRequest, if not, return null.
0
 
LVL 27

Assisted Solution

by:nmarun
nmarun earned 249 total points
ID: 35578534
adilkhan - You're slightly off when you say: it's not really a function. On the contrary get and set accessors are ACTUALLY methods. Read my blog article below:

http://weblogs.asp.net/nmarun/archive/2011/01/05/get-and-set-property-accessors-are-actually-methods.aspx

ube100 - Your get accessor (or the get_RequestObject method, see my article) is actually trying to find the Request object in the context of a web application. It's trying to look at a couple of 'locations' to see if it can find a non-null request. In case it fails, it is returning null.

From your question it seems to me that you happened to find this snippet of code and are trying to understand the concepts. My 2 cents is that you pick up an asp.net book and get a hold of the big-picture before getting into such nitty-gritty snippets.

Thanks,
Arun
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Accepted Solution

by:
Saqib Khan earned 501 total points
ID: 35659003
nmarun I totaly understand that, but if you read question carefully, poster asked what does this "function" do. I never used the word "Method" in my answer. Method could be either a function or Sub. and i also mention it does almost the same thing.

I think it is our job to tell poster the difference. Properties are used basicly when you are creating a Class and you need to Set or a Return Value (eg; Item Attrbiutes etc). While function could be used within the Code file (anywhere).

Properties are supposed to return value and the same value each time unless something else is called in between. A Method on the other hand is typically expected to do something in the background to get the value, or that the method may change the value each time it is called, like GetNextId() or something.

So Technicaly if you are learning programming you cannot say Property and Method is Absolute SAME THING.

0
 
LVL 17

Expert Comment

by:Carlos Villegas
ID: 35689607
and I dont understand why that is too important, ube100 is just asking:

Can somebody explain to me what this function (whatever, you get the idea) doing here please?
I agreed with nmarun
0
 

Author Closing Comment

by:ube100
ID: 35724245
helped
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview
Suggested Courses
Course of the Month19 days, 7 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question