|
To quote the OP "I want to do something like this". He was clearly aware that what he wrote was not possible, but the general idea (using reflection) is possible.
|
|
|
|
|
The best way to go about this depends upon your exact situation:
- You should do a sanity check over what you are doing. If you want to pass objects/information round as strings, you can easily serialize/deserialize between objects and XML. Here, most of the work is done for you
- If you can't change the format, and you have a limited number (e.g. 10 or so) of inbound types, just implement a simple if statetment.
- If you have more types to deal with, you'll need to do the work by reflection. Reflection takes much more code and is relatively messy.
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
string strType = "System.DateTime";
string strValue = "04/21/2010";
object o2 = Convert.ChangeType(strValue, Type.GetType(strType));
Type t = o2.GetType();
try this once.....
Hope this could help you.
Regards
surender
No Defeat Is Final Until You Stop Trying!.......
|
|
|
|
|
Hi Surender,
Your solution works very nicely but it failed for nullable types i.e. i was not able to convert "04/21/2010" to type "System.DateTime?" or "Nullable<System.DateTime>".
So I googled a bit and found that this is actually a limitation of Convert.ChangeType . I found a method which handles converting string to nullable type on this site.
I hope this would be helpful for others and thanks once again surender.
Regards,
Samar
|
|
|
|
|
|
hi! i wanted to send a custom ethernet layer packet to the network!
for example sending a packet with a custom Source IPaddress and Custom MAC Address...
i have found that NDIS (Driver) interface or WinPCap can do this for me , but i don't want to use third party applications and drivers,...
|
|
|
|
|
Hi
I am trying to use ICCompress in C# to compress images from a IP camera. Its not going very well im getting this exception:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt
The code that causes the exception is,
byte[] outImgData = new byte[outbi.biHeight * outbi.biWidth * (outbi.biBitCount / 8)];
GCHandle pinnedArray = GCHandle.Alloc(outImgData, GCHandleType.Pinned);
IntPtr outImgPtr = pinnedArray.AddrOfPinnedObject();
BitmapData inBmpDat = image.LockBits(
new Rectangle(
0, 0, image.Width, image.Height),
ImageLockMode.ReadOnly, image.PixelFormat);
Avi.ICCompress(compressorHnd,
Avi.AVICOMPRESSF_KEYFRAMES,
ref outbi,
outImgPtr,
ref bi,
inBmpDat.Scan0,
0,
0,
frameNum,
0,
5000,
0,
0);
Im new to importing DLL's so im not to sure if the arguments im using are correct. Can anyone help?
Thanx
|
|
|
|
|
I got a FileSystemWatcher which detect file change,i have encounter a problem with multi-files.
When i create/delete/change SINGLE files the filesystemwatcher would run normally. BUT when i try to copy and paste more than 1 files to the watched destination at the same time,the event will still fired but only fired the first files into listbox.THIS APPLY TO DELETE also if multi-files deletion. ANYONE HAVES CLUES what the code i lack off?
|
|
|
|
|
How to search special character ' (single quote) in Sql server 2005?
For eg.
select Cust_Name from tbl where CustName like '%'%'
Thanks in advance.
modified on Wednesday, April 21, 2010 4:37 AM
|
|
|
|
|
|
Hi,
After modifying the content in xml file, I tried to save in the same location. It is throwing an exception that the file is already in use. So unable to save in the same location. When I tried to save in the other location, its working fine.
Please guide me to save in the same path. thanks in advance.
string filePath="C:\\test\\sample.xml";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filePath);
----------
----------
xmlDoc.Save(filePath);
|
|
|
|
|
try renaming the modified xml document.like original filename + date modified.
|
|
|
|
|
Its like creating a new file. Isn't there a way to replace the file?
|
|
|
|
|
Hi Narvish,
There is no problem with code, the same is worked for me.
i would suggest to make the document object null in finally block.
In your case the worker process might be using the file in memory.
Regards
Surender
No Defeat Is Final Until You Stop Trying!.......
|
|
|
|
|
As per your suggestion, I kept the code in try block and I added
finally
{
xmlDoc = null;
}
Still it is throwing exception that process cannot use that file.. because it is using by other thread.
|
|
|
|
|
Make sure the file and folder have proper permissions set and file is not kept open anywhere.
remove file manually and try again.
Regards
Surender
No Defeat Is Final Until You Stop Trying!.......
|
|
|
|
|
yes, thats the problem with the file. I copied the file with other name and used it. it worked fine. Thank you
|
|
|
|
|
Hallo can someone please help me, I've got this table:
Valuation Date Construction
30/03/2009 30,625.26
30/04/2009 269,825.04
30/05/2009 850,056.45
30/06/2009 1,922,475.06
30/07/2009 3,500,852.19
30/08/2009 5,757,055.16
30/09/2009 8,699,041.1
30/10/2009 12,232,330.17
30/11/2009 16,612,763.46
30/12/2009 19,166,542.19
30/01/2010 22,098,191.54
28/02/2010 33,539,289.47
30/03/2010 40,518,025
30/04/2010 48,372,377.98
30/05/2010 56,543,248.62
30/06/2010 65,507,314.28
30/07/2010 74,607,415.4
30/08/2010 84,352,063.34
30/09/2010 94,325,187.87
30/10/2010 104,060,459.19
30/11/2010 114,040,884.2
30/12/2010 119,094,482.8
30/01/2011 124,342,210.61
28/02/2011 140,316,539.09
30/03/2011 146,909,564.95
Calculated from this formula:
<br />
public string Calculation(double b, DateTime validation, DateTime start, DateTime end, double alpha, double beta)<br />
{<br />
System.TimeSpan sp_start =<br />
validation.Subtract(start);<br />
string sp_start_str = sp_start.TotalDays.ToString("#");<br />
double t1 = double.Parse(sp_start_str);<br />
<br />
if (validation.Month == 12)<br />
t1 = t1 - 14;<br />
if (validation.Month == 01)<br />
t1 = t1 - 28;<br />
<br />
System.TimeSpan sp_end =<br />
end.Subtract(start);<br />
string sp_end_str = sp_end.TotalDays.ToString("#");<br />
double t2 = double.Parse(sp_end_str);<br />
t2 = t2 - 28;<br />
<br />
double divide = (t1) / (t2);<br />
double minus1 = (1 - (divide));<br />
double pow1 = 1 - (Math.Pow(minus1, alpha));<br />
double calculation = Math.Round(b * (Math.Pow(pow1, beta)), 2);<br />
<br />
return String.Format("{0:#,###,###,###.##}", calculation);<br />
}<br />
What i need to do is:
The first January, all the months following t2 = 28;
After the second January, all the months following t2 = 56;
I probably need to use a for loop??? But not sure how to go about this.
Please someone help!!
Thanks.
|
|
|
|
|
How can i search for some value in a non sorted column of bound datagridview?
|
|
|
|
|
for(int x=0;x<DGV.Rows.Count;x++)
{
if(Val==DGV[COL,x].Value)
{
messageBox.Show("Row="+x);
breake;
}
}
EASY COME EASY GO
|
|
|
|
|
Hello,
i've build a simple server-application, which only needs to hold a TCP-Connection to the client and which listen async for data. This application also do a few tasks for each user....
So i have got a class "UserSession" in which i store the User-Informations and the TCP-Connection. This UserSession runs in a own thread.
My question is now, what's with performance? Is it a problem, that every user has a own Thread? Even if no requests are incoming? The amount of data, which are receiving/sending from this server-application is very low...
I need to handle a lot of user (i don't know how much) this could be 100, 1000 or even 10 000 user...
So, is this a good idea to give each user a own Thread? Or how can i handle such an amount of Users and TCP-Connections very fast?
|
|
|
|
|
excuse me guys...need help here...i'm having a trouble when i deployed my web service.it's giving me an error of "Object Reference not set to an instance of an object". on debug mode,it doesn't give me that error.but when i deploy it to other work station, it gives me that error.i can't trace where the error is coming from.can you help me guys.thanks a lot..
|
|
|
|
|
You need to put in a try-catch block and log the full exception. You will then at least have a chance of spotting where the problem is. Other than that, it's all guess work!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Thank you very much for the reply..but i've already done that but to no avail,i still can't seem to find where the error is coming from..
|
|
|
|
|
Does the exception not give a class and line number?
Normally the Exception.ToString() lists the Exception.StackTrace, which gives this.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|