?
Solved

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

Posted on 2006-11-04
5
Medium Priority
?
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

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!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

771 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