PC Review


Reply
Thread Tools Rate Thread

How can I pass an XmlDocument as a value type?

 
 
William
Guest
Posts: n/a
 
      22nd Jun 2006
I would like to pass an XmlDocument to a method as a non-referenced object.
Can this be done?


 
Reply With Quote
 
 
 
 
Tom Spink
Guest
Posts: n/a
 
      22nd Jun 2006
William wrote:

> I would like to pass an XmlDocument to a method as a non-referenced
> object. Can this be done?


Hi William,

You'll need to clone it. I believe the XmlDocument object exposes a Clone
method, which you can use to clone it, and so pass it in like this:

SomeClass.SomeMethod( theXmlDoc.Clone() as XmlDocument );

The reason for the 'as' there is that the Clone() method returns an XmlNode,
and (hopefully) will actually return the cloned instance of the
XmlDocument, since XmlDocument inherits from XmlNode.

Hope this helps,
-- Tom Spink
 
Reply With Quote
 
=?Utf-8?B?SmVmZnJleSBIb3JuYnk=?=
Guest
Posts: n/a
 
      22nd Jun 2006
I'm not sure what you mean by this. All object variables in C# are
references, so the idea of passing a non-referenced object doesn't make
sense. What are you trying to do?

--
Jeffrey Hornby
Hornby Consulting, Inc.



"William" wrote:

> I would like to pass an XmlDocument to a method as a non-referenced object.
> Can this be done?
>
>
>

 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      22nd Jun 2006
Hi,

Would mind to further explain what you want?

If you want to modify it inside a method and this action do not have effect
in the calling method then you need to clone it.
You can save to a string and then create a new document from this string.
Not sure if there is a better way .


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



"William" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I would like to pass an XmlDocument to a method as a non-referenced object.
>Can this be done?
>



 
Reply With Quote
 
William
Guest
Posts: n/a
 
      22nd Jun 2006
I was wonering if there might be something comparable to boxing/unboxing for
reference types, but this does not seem to be the case. I decided to go
ahead and just clone it.

"Jeffrey Hornby" <(E-Mail Removed)> wrote in message
news:5E6DA989-825C-481B-9B1F-(E-Mail Removed)...
> I'm not sure what you mean by this. All object variables in C# are
> references, so the idea of passing a non-referenced object doesn't make
> sense. What are you trying to do?
>
> --
> Jeffrey Hornby
> Hornby Consulting, Inc.
>
>
>
> "William" wrote:
>
>> I would like to pass an XmlDocument to a method as a non-referenced
>> object.
>> Can this be done?
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to pass a type as a generic parameter to a function and return an instance of that type? foolmelon@hotmail.com Microsoft C# .NET 2 4th Apr 2007 07:32 PM
Cannot implicitly convert type 'object' to 'System.Xml.XmlDocument' Error Patrick Olurotimi Ige Microsoft ASP .NET 3 4th May 2005 06:21 AM
XmlDocument Web method returns type XmlNode John Bailo Microsoft Dot NET 2 25th Oct 2004 09:26 PM
XmlDocument Web method returns type XmlNode John Bailo Microsoft C# .NET 2 25th Oct 2004 09:26 PM
loading xmlcontent from one xmldocument into another xmldocument Shoval Tomer Microsoft ASP .NET 0 9th Jul 2003 05:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:25 PM.