c# function

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;
            }
        }
ube100Asked:
Who is Participating?
 
Saqib KhanSenior DeveloperCommented:
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
 
Saqib KhanSenior DeveloperCommented:
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
 
Carlos VillegasFull Stack .NET DeveloperCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
nmarunCommented:
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
 
Carlos VillegasFull Stack .NET DeveloperCommented:
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
 
ube100Author Commented:
helped
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.