This is a total hack, obviously. But is it OK? Assuming it isn't given bad indexes, can it fail somehow?
Not much exceptions that are thrown by those functions, according to MSDN. You might want to check whether the topic 'verification' from this page[^] applies to your situation.
No, wouldn't call it a hack, but emitting code is not a widely-understood topic; so you might wanna document what you did there. An implementation that 'generates' the required switch-code and compiling that with the built-in mechanism would be more familiar - also a bit slower, but I doubt that the layout of the class will change often, so it'd be a matter of compiling once and re-using the existing thing.
I'd go for reflection, as mentioned by others. Caching the results might improve speed there, but it's fast enough for most tasks without additional caching.
It's not "insane code", just a tad more scary than seeing someone compile code on the fly. Maintainability might be an issue. It may fail due to a security-update when you're celebrating a wedding in Hawaii, so it'd be best to put some explanation and some hyperlinks in the xml-comment header.
harold aptroot wrote:
but the situation demands it
Is this situation a person? It prolly ain't Mr. Performance
This is one of the rare times where the situation itself is more interesting then the programming-exercise.
i'm using an outlook add-in using these below events i got sent and received mails in my wcf service but only when outlook is running if outlook is closed and somebody send me mails than the add-in does not call my wcf service method
here are events
privatevoid ThisAddIn_Startup(object sender, System.EventArgs e)
this.Application.ItemSend += new ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
this.Application.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(Application_NewMailEx);
I agreed with you. but i'm talking about those mails which come to me when my outlook is not running and as i run my outlook i got all mails in my outlook but i wonder on which event i can call my WCF service method to get those mails
All new emails that come into the client will raise the exact same event, no matter if they show up when Outlook starts or not.
The problem is that your Add-In may not have wired up the event handlers before that happens. Add-Ins are loaded before Outlook checks with the mail servers to pickup mail, but it doesn't wait for each Add-In to completely load and initialize itself. You have to make sure that one of the first things you do is wire up the events you want and don't take forever to init your code.
I have a stream object containing html that I can read as a List<Char>. The stream contains html. What I need to do is convert the stream of html into xml and store the xml into a xmlDocument in C#. Can anyone show me some code that will help me do this?
Please explain what do you mean by "convert html to xml". Both are just strings wiht set format, but there are many cases that valid html is not valid xml (for example <br> and <p> tags may be not terminated)
You can try to parse the html and try to "fix" it, but it may not be worth the effort.
On the other hand if you have control over the html and can ensure correct structure yourself, nothing prvents you from creating XmlDocument out of it using Load() or LoadXml() methods.
"My software never has bugs. It just develops random features."
What I mean is that I am reading excel spreadsheet cells pasted into an editor and pulling the content of the editor into a stream of html. Next, what I want to dso is take the html stream and make it into an XML stream that I can load into an XMLDocument (ie <table .. ></table> into <table>......<table>) then I will parse the xml data and store it into the database.
The codeplex library is great. One question; however. It's class object works by writting the html to a file on the server then the app code must read the file back into an xmldocument. Because of security reasons we can't allow the application to save a file from the browser to the server and then read it back from the server. Is there anyway to have the html to xml converter class write the converted html to a stream or some thing else besides a file on the server?
Goodmorning to all!
Ehm i want create a button ribbon and when i press it load a windows form integrated into outlook 2010 or 2007 or 2013 (if it exited from building). Ehm i started creating button ribbon with this guide:
When i press it i would load a form into outlook that load all contacts of my public folder with this name "Contatti Itech" into a datagrid view.
How can i do it?
Plz help me!
Thanks for any help! Code are appreciated too!!!
The long string [000000001A447390AA6611CD9BC800AA002FC45A0300D4985F464F07654AA9CA8D6B785E166E000000004E3B0000] is id for my public folder. Is there anyway to get public folder by name such as "Contatti Itech"?
I am trying to convert the string to datetime including the milliseconds... unfortunately when I used the Convert.ToDateTime method, it does not return the milliseconds... I have tried the parse and parseExact method in the Datetime and DateTimeOffset classes as well... none of them returning the milliseconds... I read the previous discussion regarding this issue and none of the solutions return the milliseconds...This is what I am trying to do:
Thank you so much for taking your time to respond to my post... I really appreciate it... but the solution both of you mentioned does not work for my situation... may be I did not state my question clearly... I apologize for that...
Pete, in your solution, you are converting the date to string again... that's not what i want...
And BMS121, I used the 'TimeOfDay' property as you suggested , but I could not assign that to datetime variable... I get compiler error :'Cannot implicitly convert System.TimeSpan to System.Datetime...
This is what I want to accomplish:
I am getting the datetime as a string from client ... so I have to convert that string to datetime including millisecond and then I have to store/save that datetime in the database (the datebase column is datetime type)...
Here is the code snippet:
string strDate = "2012-11-09 07:20:07.410"
Datetime actualDate = Convert.ToDateTime(strDate); -(L2)
L2 : does not return millisecond...
As per BMS121 suggestion, I tried the following :
(my entity object is called EDEntitiy)
Edentity.Timestamp = actualDate.TimeOfDay;
But above statement causes compiler error:
'Cannot implicitly convert System.TimeSpan to System.Datetime...
You are misunderstanding Pete's solution. Convert.ToDateTime is already giving you the right answer, but the default ToString on a DateTime omits the milliseconds, so it looks like it isn't when you look at the string representation of the DateTime you create. If you format it with milliseconds, you'll see that you got what you expected.
Thanks. Really appreciate it. My issue is this.
string strDate = "2012-11-09 07:20:07.410"
Datetime actualDate = Convert.ToDateTime(strDate);
Now when I save this date (actualDate) in the database(I am using the Entity Frame work to connect to the database), this is what i see in the database : 2012-11-09 07:20:07.000
As you can see, the millisecond is zero in the database... so my question is how do I save date (after converting from string to datetime) with milliseconds... my datebase date column is SQL datetime type...