Existen algunas formas de hacerlo, acá les dejo un par.

Primera forma:

//list es del tipo IList
ArrayList arr = new ArrayList(list);
Item[] items = (Item[])arr.ToArray(typeof(Item));

Otra forma:

Item[] items = new Item[list.Count];
list.CopyTo(items, 0);

Tags: , ,

I’m using the new SQL Server 2005’s data type nvarchar(max) on a .Net project (ntext has been deprecated in this version) in conjuction with Castle ActiveRecord. For a complete integration (including schema creation), ActiveRecord property should looks like this:

[Property("description", ColumnType = "StringClob", SqlType = "nvarchar(MAX)")]

ColumnType = “StringClob” avoids text to be truncated if it gets too long. SqlType = “nvarchar(MAX)” forces the field to be created as that data type, otherwise, it will be created as nvarchar(255).

A more detailed explanation can be found here and here.

Tags: , , , , , ,

Para convertir en C# un objecto ArrayList, definido como:

ArrayList arrayList = new ArrayList();

en un arreglo de strings (string[]), solo se necesita:

string[] stringArray = (string[])arrayList.ToArray(typeof(string));

Tags: ,

Los elementos dentro de un ICollection (para ser más exactos, los elementos dentro de una clase que implemente una interfaz ICollection) no tienen un orden específico. En un momento pueden estar ordenados de una manera, y en otro, sin alguna razón aparente, ordenados de otra forma.

En cambio, los elementos de un IList si tienen un orden establecido y relevante, como un arreglo. Esto permite agregar elementos en una ubicación específica. Además, los elementos van a permanecer en la posición asignada hasta que decidamos moverlos.

Además de estas dos interfaces, existe también IDictionary, que exitiende a ICollection. Este permite almacenar parejas de elementos (clave, valor), similar a como lo hace un diccionario de palabras (cada palabra tiene un significado). Al igual que en el ICollection, estos elementos no tienen un orden específico.

Tags: , , , ,

No he encontrado una manera directa de hacerlo, pero encontré esta función que busca la extensión del archivo en el registro de windows y si está registrada, obtiene su tipo mime.

1
2
3
4
5
6
7
8
9
private string getMimeType(string fileName)
{
    string mimeType = "application/unknown";
    string ext = System.IO.Path.GetExtension(fileName).ToLower();
    Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
    if (regKey != null && regKey.GetValue("Content Type") != null)
        mimeType = regKey.GetValue("Content Type").ToString();
    return mimeType;
}

Aún no la pruebo, pero según loque leí, funciona bien. Los post originales están acá y acá.

Tags: , ,