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,854 other subscribers

Archive for the ‘C#’ Category

StackOverflow C# question: Slight confusion over reference types and value types in the C# spec

Posted by jpluimers on 2011/06/23

Recently there was a nice Slight confusion over reference types and value types in the C# spec on StackOverflow.

Summary:

When structs are value types, but interfaces are reference types, how can a struct implement an interface and still be a value type?

The answer is boxing: when a reference to a struct is needed, a reference object is automatically created, and the value of the struct is box-wrapped into it.

This automatic boxing is really nice, but be aware that when frequently doing this, it can have a huge performance impact.

Thanks Abhina Basu for blogging about boxing structs having interfaces, and the many volunteers on StackOverflow explaining about boxing.

–jeroen

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

c# – Generics and nullable type – Stack Overflow

Posted by jpluimers on 2011/06/14

A while ago, I needed some generic way of parsing data that could result instancef of both regular ordinal and nullable ordinal types.

Luckily there was a nice question about this on StackOverflow, of which I liked this answer (source code below) much more than the accepted answer: concise, elegant, period.

    public static T? Parse(this string text) where T: struct
    {
        object o = null;
        try
        {
            var ttype = typeof(T);
            if (ttype.IsEnum)
            {
                T n = default(T);
                if (Enum.TryParse(text, true, out n))
                    return n;
            }
            else
                o = Convert.ChangeType(text, ttype);
        }
        catch { }

        if (o == null)
            return new Nullable();

        return new Nullable((T)o);
    }

–jeroen

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Software Development | 1 Comment »

mijnalbum.nl URLs and downloading pictures

Posted by jpluimers on 2011/05/24

MijnAlbum.nl is a popular site for storing and printing photos.

The UX of the site is far below what I’d like so I searched around for some scripts and wrote a bit of code for my own to make it easier.

First a few URL tricks for mijnalbum.nl (with the free demo album with Album ID TYEGMIMD):

  1. Album URLs follow this pattern:
    http://www.mijnalbum.nl/Album=TYEGMIMD
    where the letters after Album= contain the Album ID.
  2. When you click on a photo a new window opens with a URL like
    http://www.mijnalbum.nl/GroteFoto-3ANGJPWW.jpg
    where the letters after GroteFoto- contain the Photo ID and the .jpg extension.
    You don’t need to be logged in to download these photos.
  3. The album page includes a frame with thumbnails that has a URL like
    http://www.mijnalbum.nl/index.php?m=albumview&a=2&key=TYEGMIMD&selectedfoto=3ANGJPWW
    but a bit of experimentation reveals it can be condensed into
    http://www.mijnalbum.nl/?m=albumview&a=2&key=TYEGMIMD
    where the letters after key= contain the Album ID.
  4. The thumbnail frame contains photo’s that link to URLs like
    http://www.mijnalbum.nl/index.php?m=albumview&a=1&key=3ANGJPWW&album=TYEGMIMD
    that can be condensed into
    http://www.mijnalbum.nl/?m=albumview&a=1&key=3ANGJPWW&album=TYEGMIMD
    where you both need the Photo ID as key value, and Album ID as album value.
    The thumbnails are tiny, so not very convenient to browse.
  5. Download URLs look like this
    http://www.mijnalbum.nl/index.php?m=download&a=10&key=TYEGMIMD
    which can be condensed into
    http://www.mijnalbum.nl/?m=download&a=10&key=TYEGMIMD
    but you need to be logged in to download other albums than the demo album.

The thumbnails frame contains two lists of the photos in the album. Given the demo album, it first contains a this section inside a bunch of JavaScript code:

thumbs.push(new Array("http://www.mijnalbum.nl/MiniFoto-3ANGJPWW.jpg"));
thumbs.push(new Array("http://www.mijnalbum.nl/MiniFoto-6OKRE67M.jpg"));
thumbs.push(new Array("http://www.mijnalbum.nl/MiniFoto-4OSAXTJM.jpg"));
thumbs.push(new Array("http://www.mijnalbum.nl/MiniFoto-7MFJVO4F.jpg"));
thumbs.push(new Array("http://www.mijnalbum.nl/MiniFoto-YQ4BZ4AD.jpg"));
thumbs.push(new Array("http://www.mijnalbum.nl/MiniFoto-3LKQD6AG.jpg"));
thumbs.push(new Array("http://www.mijnalbum.nl/MiniFoto-O8RUL378.jpg"));
thumbs.push(new Array("http://www.mijnalbum.nl/MiniFoto-7TTFUUCG.jpg"));
thumbs.push(new Array("http://www.mijnalbum.nl/MiniFoto-L6SLLZHO.jpg"));
thumbs.push(new Array("http://www.mijnalbum.nl/MiniFoto-YLSWWFJI.jpg"));
thumbs.push(new Array("http://www.mijnalbum.nl/MiniFoto-CFWOY8KK.jpg"));

and further in the page source a HTML table with HTML fragements like these:

        <a onclick="resetScrollNextImg();" onfocus="this.blur();" href="index.php?m=albumview&a=1&key=3ANGJPWW&album=TYEGMIMD" target="fotoframe">
 <img id="thumb-3ANGJPWW" style="margin-bottom: -3px;" title="Eendjes in de wei" src="http://www.mijnalbum.nl/MiniFoto-3ANGJPWW.jpg" alt="Eendjes in de wei" width="90" height="90" border="0" />
 </a>

The HTML fragment has more context (Picture ID in both the a and img tags, Picture description in the alt attribute of the img tag).

You need to parse either of the two tables, depending on what information you are interested in.

I was interested in the thumbnail URL, and the Photo IDs and GroteFoto download URLs because it is way easier to select photos that are bigger. Something like this list:

Thumbnail URL for Album TYEGMIMD
http://www.mijnalbum.nl/index.php?m=albumview&a=2&key=TYEGMIMD
Photo URLs for Album TYEGMIMD











Since the thumbnail URL page is not xhtml, you have two options:

  • Force the page to become XHTML by some library
  • Use Regular Expressions

Though I am not a fan of using Regular Expressions for parsing general HTML, the thumbnail frame is generated in a very consistent way, so in this case I don’t mind using RegEx.

A complete console app is part of the bo.codeplex.com library.
This is the C# code I wrote as a base:

using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace MijnAlbum.NL.Download.ConsoleApplication
{
    public class MijnAlbumNl
    {
        protected const string ThumbnailPrefix = "http://www.mijnalbum.nl/index.php?m=albumview&a=2&key=";
        protected const string BigJpegUrlMask = "http://www.mijnalbum.nl/GroteFoto-{0}.jpg";

        private static string DownloadString(string url)
        {
            var html = string.Empty;
            using (var webClient = new System.Net.WebClient())
            {
                html = webClient.DownloadString(url);
            }
            return html;
        }

        protected static string DownloadThumbnailsHtml(string AlbumID)
        {
            string url = GetThumbnailsUrl(AlbumID);
            string html = DownloadString(url);
            return html;
        }

        protected static string GetThumbnailsUrl(string AlbumID)
        {
            string url = ThumbnailPrefix + AlbumID;
            return url;
        }

        protected static List getPhotoIds(bool dumpGroups, string html)
        {
            List photoIds = new List();
            /* find strings like these:
            thumbs.push(new Array("http://www.mijnalbum.nl/MiniFoto-3ANGJPWW.jpg"));
            thumbs.push(new Array("http://www.mijnalbum.nl/MiniFoto-6OKRE67M.jpg"));
                         * RegEx string:
            thumbs\.push\(new\ Array\("http://www.mijnalbum.nl/MiniFoto-(?.*?)\.jpg"\)\);
                         */
            // With @, you only have to escape the double quotes with another double quote: http://weblogs.asp.net/lorenh/archive/2004/09/30/236134.aspx
            const string RegExPattern = @"thumbs\.push\(new\ Array\(""http://www.mijnalbum.nl/MiniFoto-(?.*?)\.jpg\""\)\);";
            const string PhotoIdRegExCaptureGroupName = "PhotoId";
            //const string RegExReplacement = @"${PhotoId}";
            MatchCollection matchCollection = Regex.Matches(html, RegExPattern);
            // Matches uses lazy evaluation, so each match will be evaluated when it is accessed in the loop
            foreach (Match match in matchCollection)
            {
                Group positionIdGroup = match.Groups[PhotoIdRegExCaptureGroupName];
                if (dumpGroups)
                    Console.WriteLine(positionIdGroup.Value);
                photoIds.Add(positionIdGroup.Value);
            }
            return photoIds;
        }

        protected static string GetBigJpegUrl(string photoId)
        {
            string bigJpegUrl = string.Format(BigJpegUrlMask, photoId);
            return bigJpegUrl;
        }

    }

}

Note that others wrote some scripts too, so for instance Kees Hink  wrote on Foto’s downloaden van mijnalbum.nl and there is the MijnAlbumDownloader app.

Note 2: The free RegEx Expresso tool is very nice for building and testing Regular Expressions.

–jeroen

Posted in .NET, C#, Development, Software Development | 3 Comments »

Better solution for C# Warning CS0067 than “#pragma warning disable 0067”: The event ‘event’ is never used – Trevor’s Dev Blog – Site Home – MSDN Blogs

Posted by jpluimers on 2011/05/19

When you get a C# Warning CS0067, the MSDN documentation tell you to insert a “#pragma warning disable 0067”, but Trevor Robinson has a better solution at C# Warning CS0067: The event ‘event’ is never used – Trevor’s Dev Blog – Site Home – MSDN Blogs:

Since the event is never used, make the event explicit, or even throw an exception in the add clause of the event.

–jeroen

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

Simple example to show DateTime.Now in ISO 8601 format on ideone.com | Online C# Compiler & Debugging Tool

Posted by jpluimers on 2011/05/17

I’m a fan of ISO 8601, as it is a universal way of expressing dates and times (no more MDY confusion ).

I wrote about using ISO 8601 in batch-files and with Google Calendar before.

Now it is time to give you a simple C# example.

When you realize that XML uses ISO 8601 for their date and time formats, the .NET conversion is very easy:

using System;
using System.Xml;

public class Test
{
    public static void Main()
    {
        string Iso8601DateTime =
            XmlConvert.ToString(DateTime.Now, XmlDateTimeSerializationMode.Local);
        Console.WriteLine(Iso8601DateTime);
    }
}

I wrote about ideone.com before: it is an excellent place to run sample C# code (and other languages).

When running this on ideone.com, you can see their local server time in ISO 8601 format.
Cute :-)

BTW: There are more ways to run your C# code online.

–jeroen

via: Simple example to show DateTime.Now in ISO 8601 format on Ideone.com | Online C# Compiler & Debugging Tool.

Posted in .NET, C#, Development, ISO 8601, Power User, Software Development | 1 Comment »

Martin Kulov’s Blog: Any CPU vs. x86 vs. x64

Posted by jpluimers on 2011/05/11

Thanks to Martin Kulov’s Blog: Any CPU vs. x86 vs. x64 I got a reference to a great article explaining this in more detail.

The obvious points are 1., 2. and 3., but it is 4..7 that makes the article really worth reading.

–jeroen

PS: a few more relevant links

http://stackoverflow.com/questions/247098/x64-net-compilation-process-explorer-oddity

http://stackoverflow.com/questions/311158/why-doesnt-the-corflags-utility-warn-when-marking-x64-assemblies-as-x86

Posted in .NET, ASP.NET, C#, Development, 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 »

Don’t sleep when you use your Entity Framework model from a separate assembly

Posted by jpluimers on 2011/05/05

The Entity Framework needs you to have a connection string in your App.Config.

It is good practice having your Entity Framework model in a separate assembly.

When using it in your main app, be aware that the connection string that belongs to your model needs to be in the App.config of your main app.

If not, you get an exception like this:

System.ArgumentException was unhandled
Message=The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
Source=System.Data.Entity
StackTrace:
at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
at System.Data.EntityClient.EntityConnection..ctor(String connectionString)
at System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString)
at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)

The clue is the contents of the defaultContainerName parameter: you will see that in the App.config of your Entity Framework assembly.

Copy that over to the App.config of your main assembly, then make sure it points to your right database (if you use OTAP), then go :-)

Your App.config then looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="MyEntities" connectionString="metadata=res://*/My_EntityModel.csdl|res://*/My_EntityModel.ssdl|res://*/My_EntityModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=my-sql-server;initial catalog=my-database;persist security info=True;user id=my-user;password=my-password;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

–jeroen

Posted in .NET, C#, Database Development, Development, EF Entity Framework, Software Development, SQL Server | Leave a Comment »

DealExtreme uses ASP.NET

Posted by jpluimers on 2011/05/03

It is always fun to see error messages on web-sites; they reveal a lot about the technology they use.

For instance, DealExtreme – a very popular site to order electronics and gadgets from the far east – uses ASP.NET.

They have verbose logging enabled, which even includes a warning to turn it off in production sits, as per this comment in the page source:

This error page might contain sensitive information because ASP.NET is configured to show verbose error messages using <customErrors mode=”Off”/>. Consider using <customErrors mode=”On”/> or <customErrors mode=”RemoteOnly”/> in production environments.

This is the full text, indicating they use .NET 2.0 and SQL Server with connection pooling (which is a good thing), and the BLToolkit extensions, Callbacks, a separation of Business Logic and Data Abstraction (BLL, DAL/DAO) probably using Spring.net and Data Binding by calling BindData() in stead of DataBind().

Server Error in ‘/’ Application.


A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +578
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +88
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6265031
   System.Data.SqlClient.SqlConnection.Open() +258
   BLToolkit.Data.DbManager.ExecuteOperation(OperationType operationType, Action operation) +64
[DataException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
   BLToolkit.Data.DbManager.OnOperationException(OperationType op, DataException ex) +176
   BLToolkit.Data.DbManager.ExecuteOperation(OperationType operationType, Action operation) +135
   BLToolkit.Data.DbManager.OpenConnection() +91
   BLToolkit.Data.DbManager.get_Connection() +42
   BLToolkit.Data.DbManager.OnInitCommand(IDbCommand command) +31
   BLToolkit.Data.DbManager.get_SelectCommand() +28
   BLToolkit.Data.DbManager.GetCommand(CommandAction commandAction, CommandType commandType, String sql) +18
   BLToolkit.Data.DbManager.PrepareCommand(CommandAction commandAction, CommandType commandType, String commandText, IDbDataParameter[] commandParameters) +91
   BLToolkit.Data.DbManager.SetCommand(CommandAction commandAction, CommandType commandType, String commandText, IDbDataParameter[] commandParameters) +51
   BLToolkit.Data.DbManager.SetCommand(String commandText, IDbDataParameter[] commandParameters) +25
   DealExtreme.Mall.Common.DAL.DAO.BLToolkitExtension.CategoryAccessor.GetAll() +168
   DealExtreme.Mall.Common.BLL.CategoryBL.CategoryLogic.GetAllCategory() +53
   DealExtreme.Mall.Common.Caching.ProductCaching.CategoryCache.GetAllCategories() +9
   DealExtreme.Mall.Common.Caching.ProductCaching.BLToolkitExtension.CategoryCache.GetAllCategories() +433
   DealExtreme.Mall.Search.BLL.SearchLogic.GetSearchedCategory(String request) +255
   DealExtreme.Mall.Search.Web.Search.BindData() +416
   DealExtreme.Mall.Search.Web.Search.Page_Load(Object sender, EventArgs e) +16
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
   System.Web.UI.Control.OnLoad(EventArgs e) +132
   System.Web.UI.Control.LoadRecursive() +66
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428


[SqlException]: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at BLToolkit.Data.DbManager.ExecuteOperation(OperationType operationType, Action operation)
[DataException]: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
at BLToolkit.Data.DbManager.OnOperationException(OperationType op, DataException ex)
at BLToolkit.Data.DbManager.ExecuteOperation(OperationType operationType, Action operation)
at BLToolkit.Data.DbManager.OpenConnection()
at BLToolkit.Data.DbManager.get_Connection()
at BLToolkit.Data.DbManager.OnInitCommand(IDbCommand command)
at BLToolkit.Data.DbManager.get_SelectCommand()
at BLToolkit.Data.DbManager.GetCommand(CommandAction commandAction, CommandType commandType, String sql)
at BLToolkit.Data.DbManager.PrepareCommand(CommandAction commandAction, CommandType commandType, String commandText, IDbDataParameter[] commandParameters)
at BLToolkit.Data.DbManager.SetCommand(CommandAction commandAction, CommandType commandType, String commandText, IDbDataParameter[] commandParameters)
at BLToolkit.Data.DbManager.SetCommand(String commandText, IDbDataParameter[] commandParameters)
at DealExtreme.Mall.Common.DAL.DAO.BLToolkitExtension.CategoryAccessor.GetAll()
at DealExtreme.Mall.Common.BLL.CategoryBL.CategoryLogic.GetAllCategory()
at DealExtreme.Mall.Common.Caching.ProductCaching.CategoryCache.GetAllCategories()
at DealExtreme.Mall.Common.Caching.ProductCaching.BLToolkitExtension.CategoryCache.GetAllCategories()
at DealExtreme.Mall.Search.BLL.SearchLogic.GetSearchedCategory(String request)
at DealExtreme.Mall.Search.Web.Search.BindData()
at DealExtreme.Mall.Search.Web.Search.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
[HttpUnhandledException]: Exception of type 'System.Web.HttpUnhandledException' was thrown.
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.search_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4955

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

Delphi Constraints in Generics – RAD Studio XE documentation wiki

Posted by jpluimers on 2011/04/21

Quite a few things are similar when doing Generics in both Delphi and C#.

But constraints are a bit different.

To quote the Delphi Wiki page on Constraints in Generics – RAD Studio XE:

Constraints can be associated with a type parameter of a generic. Constraints declare items that must be supported by any particular type passed to that parameter in a construction of the generic type

Constraint items include:

  • Zero, one, or multiple interface types
  • Zero or one class type
  • The reserved word “constructor“, “class“, or “record

You can specify both “constructor” and “class” for a constraint. However, “record” cannot be combined with other reserved words.
Multiple constraints act as an additive union (“AND” logic).

A few other differences are these:

  • In .NET, there is a unified typing system: everything descends from System.Object, including both value types and reference types. In Delphi this is not the case. In .NET, when you don’t specify a constraint, but use the type in a reference way, it will do automatic boxing. Delphi has no concept of automatic boxing, so you cannot use a non-constrained type as a reference
  • In both .NET and Delphi, you cannot specify a constraint on an enumeration type. In .NET you can work around this by constraining on the underlying interfaces. In Delphi you cannot do that because enumeration types are ordinal types that do not implement interfaces.
  • In Delphi you cannot constrain on ordinal types.

Note that – like the Delphi documentation – the C# constraints on type parameters documentation is not complete on those either.

Related: a great post [WayBack] Using Generics in Delphi – Phil Gilmore covering the comparison between C# and Delphi in more depth.

–jeroen

via: Constraints in Generics – RAD Studio XE.

Posted in C#, Delphi, Development, Software Development | 10 Comments »