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
Solved

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

Posted on 2006-11-04
5
228 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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