The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,861 other subscribers

Archive for the ‘Prism’ Category

.NET/C# InternalsVisibleTo Attribute via: Salvo(z)

Posted by jpluimers on 2012/07/12

Didn’t need it until now, as now I wrote my first unit test on an internal class, with the unit test in a separate assembly.

Visual Studio 2010 suggested adding the InternalsVisibleTo Attribute to the assembly containing the internal class specifying that the unit test assembly would have access to it.

For me that felt up-side-down, but thinking again it is logical, but still doesn’t feel well.

This is what it does:

The InternalVisibleToAttribute was added in .Net 2.0 and most people seem to be using it in order expose internal methods to external unit test classes. However, there is nothing to prevent you from using it in non-testing situations., although I have not seen a good reason other then unit testing to use it.

–jeroen

via: C# InternalVisibleTo Attribute | Salvo(z).

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Prism, Software Development, VB.NET | Leave a Comment »

.NET Enums enumerated: System.ArgumentException was unhandled by user code Message=An item with the same key has already been added.

Posted by jpluimers on 2012/06/13

All .NET languages have a cool feature: enumerated types, for instance enum in C#Enum in VB.NET, or the enum in the  Oxygene language of Delphi Prism. You can even specify the underlying integral type.

It allows you to name values, which can make your code very readable.

It also allows you to assign an integer to each of those values, which allows you to map them to existing integers in the ‘real’ world. This is both a powerful and potentially uncool feature of enums (the other uncool feature is that though you can have bitflags in Enums, most .NET languages don’t have a Set type. You need Set Extensions to do things like Set operations on Card Suit bitflags using C# extension methods).

Because of my background in the 80s in MuSimp and Turbo Pascal, I’ve done quite a bit of enums and sets in the past, hence the mentioned C# enum extension methods mentioned above. While writing this article I also found out Extending’ the Enum Class to Validate the Enum Values with the Flags Attribute that mentions quite a bit of stuff that is complementary to my code and what you will see below.

The risk of assigning integer values on C# enum is that you can assign the same integer value to multiple enum elements.

For instance, this code will fail: Read the rest of this entry »

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Prism, Software Development, VB.NET | Leave a Comment »

P/Invoke: usually you need CharSet.Auto (via: .NET Column: Calling Win32 DLLs in C# with P/Invoke)

Posted by jpluimers on 2012/02/28

I don’t do P/Invoke often, and somehow I have trouble remembering the value of CharSet to pass with DllImport.

In short, pass CharSet.Auto unless you P/Invoke a function that is specific to CharSet.Ansi or CharSet.Unicode. The default is CharSet.Ansi, which you usually don’t want:

when Char or String data is part of the equation, set the CharSet property to CharSet.Auto. This causes the CLR to use the appropriate character set based on the host OS. If you don’t explicitly set the CharSet property, then its default is CharSet.Ansi. This default is unfortunate because it negatively affects the performance of text parameter marshaling for interop calls made on Windows 2000, Windows XP, and Windows NT®.

The only time you should explicitly select a CharSet value of CharSet.Ansi or CharSet.Unicode, rather than going with CharSet.Auto, is when you are explicitly naming an exported function that is specific to one or the other of the two flavors of Win32 OS. An example of this is the ReadDirectoryChangesW API function, which exists only in Windows NT-based operating systems and supports Unicode only; in this case you should use CharSet.Unicode explicitly.

–jeroen

via: .NET Column: Calling Win32 DLLs in C# with P/Invoke.

Posted in .NET, Ansi, C#, Delphi, Development, Encoding, Prism, Software Development, Unicode | 3 Comments »

Source Code Pretty Printing in various languages

Posted by jpluimers on 2011/12/05

Totally forgot about this: YAPP – yet another pretty printer.

–jeroen

via: delphi – Save source code with formatting syntax highlight – Stack Overflow.

Posted in .NET, C#, Development, Prism, Software Development | Leave a Comment »

FM USB Library

Posted by jpluimers on 2011/05/10

The FM USB Library is on my research list.

–jeroen

PS: a few raw links that might fit in:

http://www.silabs.com/usbradiohttp://www.silabs.com/products/mcu/Pages/USBFMRadioRD.aspx

http://code.google.com/p/silabsradiodll/

http://parts.digikey.nl/1/1/543483-usb-fm-radio-stick-usbfmradio-rd.html

http://www.mouser.com/ProductDetail/Silicon-Laboratories/USBFMRADIO-RD/?qs=42TdBvIR%2fY7X5XVJkFBvBg%3d%3d

http://nl.farnell.com/jsp/search/productdetail.jsp?sku=1186925

http://www.newark.com/jsp/Non-Stocked/All+Non-Stocked+Products/SILICON+LABORATORIES/USBFMRADIO-RD/displayProduct.jsp?sku=98K2140

http://www.mp3car.com/hardware-development/64550-usb-fm-rds-solution-with-sofware-40.html

http://www.mp3car.com/hardware-development/64550-usb-fm-rds-solution-with-sofware-41.html

http://usb.brando.com/prod_detail.php?prod_id=00136

http://usb.brando.com/usb-radio-ii_p1785c35d15.html

http://www.whitebream.com/p811.shtml?id=p811

http://khason.net/blog/read-and-use-fm-radio-or-any-other-usb-hid-device-from-c/

http://www.dealextreme.com/p/usb-digital-radio-receiver-dongle-fm-76-108mhz-1929

http://www.silabs.com/products/audiovideo/fmreceivers/Pages/default.aspx

http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=usb+fm+rds+site%3Amouser.com

http://www.mp3car.com/hardware-development/69493-hqct-module-new-thread-following-hu-rds-rdbs.html

http://www.mp3car.com/hardware-development/64550-usb-fm-rds-solution-with-sofware-2.html

http://www.cartft.com/catalog/il/1139

http://www.digital-car.co.uk/forum/showthread.php?12194-New-CarTFT-FM-(Automotive-USB-FM-RDS-tuner)

http://www.cartft.com/catalog/il/1017

http://btwincap.sourceforge.net/download.html

http://btwincap.sourceforge.net/supportedcards.html

http://www.alibri.it/RRMobile/Silab%20USB%20Radio.htm

http://www.mo-co-so.com/Car-TFT-FM-Tuner-with-RDS-p/mcs-tft-rad.htm

http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272

Posted in .NET, C#, Delphi, Development, Prism, Software Development | Leave a Comment »

Entity Framework 4 – security warning popup workaround: Do you trust all the T4 “text templates” on your system, even future ones?

Posted by jpluimers on 2011/04/13

When using Entity Framework 4, your transofmrations (model to classes, DB to model, etc) are performed by T4 Text Templates.

Those templates are executed all over the place (when saving your project, building your project, changing your model, etc).

Since anyone can insert a T4 Text Template into Visual Studio, and those are scripts, it is a potential vulnerability.

The default Visual Studio behaviour is to show you a dialog like this:

[Security Warning]

Running this text template can potentially harm your computer. Do not run it if you
obtain if rtom an untrusted source.

Click OK. to run the template.
Click Cancel top stop the process.

[X] Do not show this message again

[OK]  [Cancel]

Some blogs mention Just click OK and feel free to check “do not show this message again.”

I’m not sure I want that: it would indicate I always trust T4 Text Templates, even the ones added in the future (T4 Text Templates are executable content, malicious software could find it’s way into your development environment; anyone remember the virus that hooked itself into the run-time library sources of a development system so it would spread through anything compiled on that system?).

But I also don’t want to click OK on that dialog.

It would be so nice if the dialog:

  1. Showed which template is about to be executed
  2. Allowed me to skip only for that particular template

Anyone better thoughts on this?

–jeroen

via Customizing EDM Code Gen in EF4 : Don’t Be Iffy.

Posted in .NET, C#, Delphi, Development, EF Entity Framework, Prism, Software Development | 4 Comments »

“Try to avoid foreach/for loops”–Over my Dead Body! | Visual Studio Feeds

Posted by jpluimers on 2011/03/16

Zack Owens wrote a nice article comparing various loop constructs.

Summary:
If the semantics are the same, it does not matter if you use foreach, for, while or do while: they all  have equal speed.

So: choose the loop construct that best fits the problem you are trying to solve.

–jeroen

via: “Try to avoid foreach/for loops”–Over my Dead Body! | Visual Studio Feeds.

Posted in .NET, C#, Delphi, Prism, Software Development | 12 Comments »

Supporting Office 2003 from .NET: getting the Office 2003 Primary Interop Assemblies

Posted by jpluimers on 2011/02/22

Often you work with projects not having the latest stuff.
Sometimes that is a good thing: latest stuff is not always best :-)

In this case, the client had Office 2003, and needed to do some Excel automation from .NET.
The development systems however had Office 2007 on it, so importing Excel defaults to the Office 2007 Primary Interop Assembly: Office version 12 in stead of 11. Read the rest of this entry »

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Delphi, Development, Prism, Software Development, Visual Studio 2005, Visual Studio 2008, Visual Studio 2010, Visual Studio and tools | Leave a Comment »

The #reflector licensing debacle

Posted by jpluimers on 2011/02/06

Earlier this week, Red Gate announced that the new Reflector version 7 would cost USD 35, as of March 2011, and the current free version 6.6 will expire on May 30th, 2011.

That caused a lot of stir, on their forum, twitter, reddit and a lot of other places. Even an old thread at StackOverflow got a new boost. It seems Red Gate did not read Social media judo: How to turn a fight into a brand-building moment.

Here is a summary of the past, present and future of things happening around reflector, including some workarounds and alternative products.

First a bit of history.

Lutz Roeder over the years developed .NET Reflector as a free tool. A few hightlights: Read the rest of this entry »

Posted in .NET, C#, Delphi, Development, Prism, Software Development | 4 Comments »

Free ebook: Programming Windows Phone 7, by Charles Petzold – Microsoft Press – Site Home – MSDN Blogs

Posted by jpluimers on 2010/11/10

If you want to do Windows Phone 7 development, then get this book: Programming Windows Phone 7 by Charles Petzod.
The eBook and source code are free:

This book is a gift from the Windows Phone 7 team at Microsoft to the programming community, and I am proud to have been a part of it. Within the pages that follow, I show you the basics of writing applications for Windows Phone 7 using the C# programming language with the Silverlight and XNA 2D frameworks.

Yes, Programming Windows Phone 7 is truly a free download, but for those readers who still love paper—as I certainly do—this book will also be available (for sale)

In addition to C# and VB.NET, you can also do this in Delphi Prism.

Cool times ahead, because now there are 4 major competitors (in no particular order):

  • iPhone
  • Android
  • Windows Phone 7
  • Symbian

I left out the competitors of the past, as they soon will be deprecated.

–jeroen

via Free ebook: Programming Windows Phone 7, by Charles Petzold – Microsoft Press – Site Home – MSDN Blogs.

Posted in .NET, C#, Delphi, Development, Prism, Software Development | 1 Comment »