|
Iterate through each items in the persons collection, create new items with the same value and add to newPersons . This will be the most easiest way. Something like
foreach(Person person in persons)
{
newPersons.Add(new Person(person.Name,person.Email,...));
} You will have new instances with same value in the newPersons collection. Is this what you are looking for or I got you wrong ?
|
|
|
|
|
(I'm not sure what a "ListCollectionView" is, but I can give some general information on creating a deep-copy of an object graph)
well...there are several approaches you could take. All have their pros and cons...here's one technique.
Mark all of your objects in your object graph with the Serializeable attribute. There are 2 noticeable cons to this technique: One- you have to mark each class individually, so there is a chance that one could be accidentally omitted. Two- You don't want to serialize objects that contain references to external resources (databaseConnections being a prime example)
Your procedure (in pseudo-code)
Create a BinaryFormatter
Create a MemoryStream to store the serialized buffer of your object graph
formatter.Serialize(buffer, source)
return the clone by Deserializing the buffer and applying a C-cast to the stream.
The Serializeable attribute will take care of the rest
The objects in the graph DO NOT have to be ICloneable. The Serializeable attribute is all that is needed. You do, however need to mark anything that you do not want to be contained in the clone as Transient
"I need build Skynet. Plz send code"
|
|
|
|
|
Alaric_ wrote: (I'm not sure what a "ListCollectionView" is
ListCollectionView[^]
Yes. Binary Serialization would be great.. I found an example that shows how to deep-copy the object using XmlFormater but that guy said that we should consider using Binary Serialization... But the problem is that there is no [Serializeable] attribute in ListCollectionView. and I can't modify the code since ListCollectionView is a part of .NET framework..
|
|
|
|
|
Hello,
Ok, we've gone round and round on this, so let me place an open question. I have a data table where some field values have this ". e.g. Nail 4".
I need to replace this with \" as they are bringing error on my excel output. How can I access each field value and replace the " with \" ?
Please help me, I'd really appreciate your help.
Let's do this !
|
|
|
|
|
string initial = "\"";
string final = initial.Replace("\"", "\\\""));
|
|
|
|
|
Thanks for that, I have it already. But how do I apply this to all the elements in the table ?
Let's do this !
|
|
|
|
|
You need to use foreach and process each row in the table. You may be able to use linq to do an update but I don't know linq yet!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
How are you outputting the Excel, what kind of errors do you get, and why do you think that \" should be used to escape the quotation marks?
I would rather expect that "" should be used...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Ok,
I am getting data from a datatable and exporting it to an excel sheet. I was using the RKLib.Export library, however this doesn't handle " quotes in the field values. It displays unintelligible data.
So I decided to use the function I am asking about to clean out the datatable before exporting it.
By the way, do you know where I would get code to export data to excel which handles quotes ?
Let's do this !
|
|
|
|
|
That would also be a clue that what you think is a " is not a ", find out what it is.
modified on Friday, August 15, 2008 9:52 AM
|
|
|
|
|
I found very little about RKLib.Export when searching for it. Does it export to CSV?
In that case, escaping quotation marks with a backslash will not help you at all.
A value in CSV that contains commas (or whatever separator is used), line breaks or quotation marks should be enclosed with quotation marks, and quotation marks are escaped by putting double quotation marks in the value.
If the library doesn't handle escaping at all, you can do something like this:
if (value.indexOfAny(new char[]{ ',', ';', '"', '\x0d', '\x0a'}) != -1) {
value = "\"" + value.Replace("\"", "\"\"") + "\"";
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
Hello everyone,
Two basic questions about BeginInvoke in asynchronous model. More specifically I am asking from this URL,
http://msdn.microsoft.com/en-us/library/bb559033.aspx
1.
I am wondering whether there is any benefit to pass an object by reference to BeginInvoke? Since in EndInvoke, the results will be retrieved. So, pass by value is fine? Any benefits to pass by reference in BeginInvoke?
2.
Any needs to pass asyncState parameter? I think we can define enough values in the 1st input parameter to BeginInvoke and then asyncState parameter will become useless?
thanks in advance,
George
|
|
|
|
|
George_George wrote: I am wondering whether there is any benefit to pass an object by reference to BeginInvoke? Since in EndInvoke, the results will be retrieved. So, pass by value is fine? Any benefits to pass by reference in BeginInvoke?
which object are you talking about ? The question doesn't make any sense at all.
George_George wrote: Any needs to pass asyncState parameter? I think we can define enough values in the 1st input parameter to BeginInvoke and then asyncState parameter will become useless?
assyncState will be assigned to IAsyncResult 's AsyncState[^] property. So it is not useless.
|
|
|
|
|
Thanks N a v a n e e t h,
N a v a n e e t h wrote: which object are you talking about ? The question doesn't make any sense at all.
My question is more about asynchronous method call in Web Services scenario. For example,
http://www.codeproject.com/KB/cpp/async_xmlws.aspx[^]
In the beginXXX method, like BeginPrime, there are 3 parameters,
int num, System.AsyncCallback callback, object asyncState
My question is, I think the 3rd parameter is useless, since we can change the 1st parameter to some type which wraps both the 1st and 2nd parameter.
Any comments?
regards,
George
|
|
|
|
|
George_George wrote: My question is, I think the 3rd parameter is useless, since we can change the 1st parameter to some type which wraps both the 1st and 2nd parameter.
That's your case. They have made it generic to support everyones needs. The parameters are clear. asyncState can contain any user state, callBack will be the delegate which calls back. So it's the pattern. BTW, what is the issue you are facing ? Your question looks odd.
|
|
|
|
|
Thanks N a v a n e e t h!
My question is, I think using asyncState to transfer variable is useless as I can see from the sample, because we can wrap the asyncState into the 1st parameter of BeginInvoke method.
In another way to express, my question is in what situations does the 3rd parameter of BeginInvoke method have special function -- which we can not wrap it into the 1st parameter?
(my English is not good, please feel free to let me know if you have any questions about my description.)
regards,
George
|
|
|
|
|
George_George wrote: I think using asyncState to transfer variable is useless as I can see from the sample, because we can wrap the asyncState into the 1st parameter of BeginInvoke method.
Yeah, you can do that. C# is a flexible language. There are many ways to achieve result. If you felt that is the good design, go with that and pass null to asyncState.
George_George wrote: my question is in what situations does the 3rd parameter of BeginInvoke method have special function
When you won't be able to wrap the user state in the first parameter as you said.
|
|
|
|
|
Thanks N a v a n e e t h,
1.
There is a further question, suppose we pass a reference variable a to BeginInvoke method, then I think in the real actual asynchronous execution, the content of real object instance (which the variable is binded to) modified, correct?
2.
If it is yes to (1), then I think even before EndInvoke, in theory we can access the modified/updated content of the object instance by the reference variable, correct?
regards,
George
|
|
|
|
|
I think YES. Have you tried it ?
|
|
|
|
|
Hi N a v a n e e t h,
I asked two questions, you mean yes to both?
regards,
George
|
|
|
|
|
I am not sure as I haven't tried what you are asking. That's why I ended with a single YES. Better option is to try yourself.
|
|
|
|
|
Thanks N a v a n e e t h,
These days I am thinking and experimenting with a prototype. I want to use BeginRead and EndRead to prove what we discussed here,
http://www.codeproject.com/script/Forums/View.aspx?fid=1649&msg=2689514[^]
But find it is hard to retrieve in the middle of an asynchronous I/O reading. Do you have any ideas how to prototype and prove our two points discussed before?
regards,
George
|
|
|
|
|
Hi All,
are there any ways that i can generate these pieces of code by CodeDom:
public object GetAccessGetPatientCount(string firstName, string lastName)
{
using (PatientTableAdapter ta = new PatientTableAdapter())
{
// this is what i wanted, whihc has parameters
return ta.GetAccessGetPatientCount(firstName, lastName);
}
}
i am only able to generate these pieces of code:
public object GetAccessGetPatientCount(string firstName, string lastName)
{
using (PatientTableAdapter ta = new PatientTableAdapter())
{
// but i am only able to get the codes like this, which does not have parameters
return ta.GetAccessGetPatientCount;
}
}
by these c# codes:
webMethodDeclaration.Statements.Add(new CodeSnippetExpression("return ta." + methodInfo.Name));
Many thanks in advance.
Andie Du
|
|
|
|
|
AndieDu wrote: are there any ways that i can generate these pieces of code by CodeDom:
Yes, now what is the problem?
|
|
|
|