How to iterate the List in Reflection

You just need to cast it: var collection = (List<Student>) studentPro.GetValue(studentObj,null); The value returned to you and stored in var is of type object. So you need to cast it to List<Student> first, before trying looping through it. RANT That is why I personally do not like var, it hides the type – unless in … Read more

How can I find the upgrade code for an installed application in C#?

I have discovered the upgrade codes are stored in the following registry location. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes The registry key name is the upgrade code and the registry key value name is the product code. I can easily extract these values however the codes are stored in a different format. The red circle shows the formatted upgrade code, … Read more

Parsing a string C# LINQ expression

You have some options: Do something homegrown, parsing the text and building an Expression Tree. The standard approach to this would be to use a language parser to parse the string (like ANTLR). Use CodeDOM to compile the query (NOT recommended for a Production environent as this is slow and generates an assembly per compilation … Read more

How can I cin and cout some unicode text?

I had a similar problem in the past, in my case imbue and sync_with_stdio did the trick. Try this: #include <iostream> #include <locale> #include <string> using namespace std; int main() { ios_base::sync_with_stdio(false); wcin.imbue(locale(“en_US.UTF-8”)); wcout.imbue(locale(“en_US.UTF-8″)); wstring s; wstring t(L” la PolynĂ©sie française”); wcin >> s; wcout << s << t << endl; return 0; }

How to kill a process without getting a “process has exited” exception?

You could P/Invoke TerminateProcess passing it Process.Handle. Then manually evaluating the cause of it (GetLastError()). Which is roughly, what Process.Kill() does internally. But note that TerminateProcess is asynchronous. So you’d have to wait on the process handle to be sure it is done. Using Process.Kill() does that for your. Update: Correction, Process.Kill() also runs asynchronously. … Read more

Getting an array of bytes out of Windows::Storage::Streams::IBuffer

You can use IBufferByteAccess, through exotic COM casts: byte* GetPointerToPixelData(IBuffer^ buffer) { // Cast to Object^, then to its underlying IInspectable interface. Object^ obj = buffer; ComPtr<IInspectable> insp(reinterpret_cast<IInspectable*>(obj)); // Query the IBufferByteAccess interface. ComPtr<IBufferByteAccess> bufferByteAccess; ThrowIfFailed(insp.As(&bufferByteAccess)); // Retrieve the buffer data. byte* pixels = nullptr; ThrowIfFailed(bufferByteAccess->Buffer(&pixels)); return pixels; } Code sample copied from