Solved

Newbie Question regarding this syntax --> public HttpRequestToken(string rsaKey) : base(rsaKey)

Posted on 2006-11-04
5
220 Views
Last Modified: 2011-09-20
I'm working through someones code and I'm not sure what is happening here.

Here's the method in question:

public HttpRequestToken(string rsaKey) : base(rsaKey)
{
}

This is called via this (the RSAKeyInXMLString is actually the RSA Signing Key as an XML string):

MyToken.HttpRequestToken oToken = new MyToken.HttpRequestToken (RSAKeyInXMLString);

Can anyone explain the syntax here? I'm confused over why this method is empty and what the ": base (rsaKey)" is all about?

Also after this, are these lines:

    oToken["UserID"] = idLoginName.Text;
    oToken["Password"] = idLoginPassword.Text;

Does this (oToken["SomeValue"]) represent some kind of Forms collection or something?

Cheers in advance.
0
Comment
Question by:w3digital
  • 3
  • 2
5 Comments
 

Author Comment

by:w3digital
ID: 17874292
OK, I think I get it.

The ": base(rsaKey)" is refering back to the inherited class and passing it the key so in reality


public HttpRequestToken(string rsaKey) : base(rsaKey)
{
}

Is really calling this method in a different class:

public Token(string key)
            {
                  _des = new DESCryptoServiceProvider();
                  _des.GenerateIV();
                  _des.GenerateKey();

                  CspParameters cspParams = new CspParameters();
                  cspParams.Flags = CspProviderFlags.UseMachineKeyStore;

                  _rsa = new RSACryptoServiceProvider(cspParams);
                  
                  _rsa.FromXmlString(key);

                  EnsureDocument();
            }

Does that seem right?

Still no idea what the

oToken["UserID"] = idLoginName.Text;
oToken["Password"] = idLoginPassword.Text;

is all about though.

Ta.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 17874483
Yes you are correct.

    base(rsaKey)

Means "pass the rsaKey value in my constructor to the contructor of the class I inherit from".

As for:

    oToken["UserID"] = idLoginName.Text;

Your HttpRequestToken class, or its base class, should have a method that looks something like:

     public string this[string key]
     {
     }

This is called an indexer and is usually used to expose some sort of collection object (ArrayList, HashTable, etc) stored inside the class and allows you to get/set values based on a name or index number. The specific signature may be a little different in your code, i'm just basing the sample above on what it probably looks like. The important part is "this[]" the return type and type within the square barackets may be different for you.
0
 

Author Comment

by:w3digital
ID: 17876139
Hey that's an awesome answer and perfect for what I need!!! I believe the code you are talking about is shown below?

So am I right in thinking that whatever I define as oToken["MyNewValue"] will become part of a dynamically created XML document (i.e. in the form of <MyNewValue>the value</MyNewValue>)? I suspected this but couldn't see where it was happening.

And I presume the code then checks if it already exists and if so it updates the value, otherwise it creates it as a new child node and appends it to the document?

Thanks so much that really helps me understand what's going on here.

public string this[string index]
            {
                  get
                  {
                        EnsureDocument(); // This ensures there is always an XML doc in place
                        XmlNode oNode = _document.SelectSingleNode("MyToken/Items/Item[@key='" + index + "']/@value");

                        if (oNode == null) return "";

                        return oNode.Value;
                  }
                  set
                  {
                        EnsureDocument();
                        XmlNode oNode = _document.SelectSingleNode("MyToken/Items/Item[@key='" + index + "']/@value");

                        if (oNode != null)
                              oNode.Value = value;
                        else
                        {
                              XmlElement oElement = _document.CreateElement("Item");
                              oElement.SetAttribute("key", index);
                              oElement.SetAttribute("value", value);

                              XmlElement oItems = (XmlElement)_document.SelectSingleNode("MyToken/Items");
                              oItems.AppendChild(oElement);
                        }
                  }
            }
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17876149
It appears to be looking for an "Item" node with an attribute called "key" whose value is whatever you pass in for "index", and then sets the "value" attribute of that node to the value you specify, otherwise it creates a new "Item" node.

So, if you call:

    oToken["UserID"] = "Bob";

And the node doesn't already exist, then it will create a node in the form:

    <Item key="UserID" value="Bob" />

Which it then appends to the "Items" node of the document.
0
 

Author Comment

by:w3digital
ID: 17876252
Great stuff. Thanks again!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now