Click here to Skip to main content
15,891,733 members
Home / Discussions / C#
   

C#

 
Questionhash value of user password from Domain Pin
Member 31961327-Nov-08 5:11
Member 31961327-Nov-08 5:11 
AnswerRe: hash value of user password from Domain Pin
Dave Kreskowiak7-Nov-08 7:33
mveDave Kreskowiak7-Nov-08 7:33 
AnswerRe: hash value of user password from Domain Pin
Dan Neely7-Nov-08 10:26
Dan Neely7-Nov-08 10:26 
Questioncalling C# code from SQL Server procedure. Pin
pankazmittal7-Nov-08 4:10
pankazmittal7-Nov-08 4:10 
AnswerRe: calling C# code from SQL Server procedure. Pin
Simon P Stevens7-Nov-08 4:33
Simon P Stevens7-Nov-08 4:33 
AnswerRe: calling C# code from SQL Server procedure. Pin
Guffa7-Nov-08 11:37
Guffa7-Nov-08 11:37 
AnswerRe: calling C# code from SQL Server procedure. Pin
Atif Shahbaz8-Nov-08 6:18
Atif Shahbaz8-Nov-08 6:18 
QuestionCopying an object instance instead of a reference [modified] Pin
Ankit Rajpoot7-Nov-08 3:54
Ankit Rajpoot7-Nov-08 3:54 
This may be a stupid question, which may be easily solved if I just study the C# programming guide thoroughly, yet I expect help from Codeproject members as I don't have enough time.

I've a library with a class called RegistryBrowser, that simply encapsulates the Microsoft.Win32.Registry and Microsoft.Win32.RegistryKey classes to provide a simple stateful access mechanism to the windows registry. This is a code fraction from the class:

public class RegistryBrowser
    {
        RegistryKey currentKey, regRoot, tempKey;
        bool writable;
        string temp;

        public string FullPath
        {
            get
            {
                return currentKey.Name;
            }
        }

        public int SubKeyCount
        {
            get
            {
                return currentKey.SubKeyCount;
            }
        }

        public int ValueCount
        {
            get
            {
                return currentKey.ValueCount;
            }
        }

        public RegistryBrowser(RegistryKey root, bool writable)
        {
            regRoot = root;
            currentKey = regRoot;
            this.writable = writable;
        }

        public RegistryBrowser(RegistryKey root, string subKey, bool writable)
        {
            regRoot = root;
            currentKey = regRoot.OpenSubKey(subKey, true);
            this.writable = writable;
        }

        public bool BrowseTo(string subKey)
        {
            tempKey = currentKey;
            currentKey = currentKey.OpenSubKey(subKey);
            if (currentKey == null)
            {
                currentKey = tempKey;
                return false;
            }
            else if(tempKey != regRoot)
                tempKey.Close();
            return true;
        }
        .
        .
        .


Now the problem is that both the constructors simply copy the object reference 'root'. What if the calling method calls the .Close method on the same instance. I need to secure my library against this. So how do I copy the object, instead of just copying the reference, or maybe I need a better design. If so, please suggest.

I encounter this problem very often and it's the source of most of bugs in my programs. Please suggest at the earliest.

modified on Friday, November 7, 2008 10:08 AM

AnswerRe: Copying an object instance instead of a reference Pin
J a a n s7-Nov-08 4:01
professionalJ a a n s7-Nov-08 4:01 
GeneralRe: Copying an object instance instead of a reference Pin
Simon P Stevens7-Nov-08 4:26
Simon P Stevens7-Nov-08 4:26 
AnswerRe: Copying an object instance instead of a reference Pin
J4amieC7-Nov-08 4:06
J4amieC7-Nov-08 4:06 
GeneralRe: Copying an object instance instead of a reference Pin
Ankit Rajpoot7-Nov-08 4:16
Ankit Rajpoot7-Nov-08 4:16 
GeneralRe: Copying an object instance instead of a reference Pin
Simon P Stevens7-Nov-08 4:38
Simon P Stevens7-Nov-08 4:38 
GeneralRe: Copying an object instance instead of a reference Pin
Ankit Rajpoot7-Nov-08 5:08
Ankit Rajpoot7-Nov-08 5:08 
AnswerRe: Copying an object instance instead of a reference Pin
Dave Kreskowiak7-Nov-08 4:10
mveDave Kreskowiak7-Nov-08 4:10 
AnswerRe: Copying an object instance instead of a reference Pin
Ben Fair7-Nov-08 5:04
Ben Fair7-Nov-08 5:04 
GeneralRe: Copying an object instance instead of a reference Pin
Ankit Rajpoot7-Nov-08 5:18
Ankit Rajpoot7-Nov-08 5:18 
QuestionGame programming reference request Pin
Russ Ferrill7-Nov-08 3:51
Russ Ferrill7-Nov-08 3:51 
AnswerRe: Game programming reference request Pin
Simon P Stevens7-Nov-08 4:14
Simon P Stevens7-Nov-08 4:14 
AnswerRe: Game programming reference request Pin
Anthony Mushrow7-Nov-08 10:10
professionalAnthony Mushrow7-Nov-08 10:10 
QuestionDraw an transparent and alpha image Pin
duta7-Nov-08 3:47
duta7-Nov-08 3:47 
AnswerRe: Draw an transparent and alpha image Pin
Dave Kreskowiak7-Nov-08 4:12
mveDave Kreskowiak7-Nov-08 4:12 
AnswerRe: Draw an transparent and alpha image Pin
J a a n s7-Nov-08 4:15
professionalJ a a n s7-Nov-08 4:15 
QuestionHow do I remove internal/private elements from my XML Documentation files? Pin
pdohara7-Nov-08 3:26
pdohara7-Nov-08 3:26 
AnswerRe: How do I remove internal/private elements from my XML Documentation files? Pin
PIEBALDconsult7-Nov-08 3:45
mvePIEBALDconsult7-Nov-08 3:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.