Пример #1
0
        public static void Usar(byte[] array, MetodoUnsafeArray metodo)
        {
            if (array == null || metodo == null)
            {
                throw new ArgumentNullException();
            }
            Exception exAux = null;

            unsafe
            {
                fixed(byte *ptrArray = array)
                {
                    try
                    {
                        metodo(new UnsafeArray(ptrArray, array.Length));
                    }
                    catch (Exception ex)
                    {
                        exAux = ex;
                    }
                }

                //lanzo la excepcion en un contexto seguro :D asi no hay problemas con los pointers
                if (exAux != null)
                {
                    throw exAux;
                }
            }
        }
Пример #2
0
 public static void UnsafeMethod <T>(this T[] array, MetodoUnsafeArray <T> mathod) where T : unmanaged
 {
     if (Equals(mathod, default))
     {
         throw new ArgumentNullException("metodo");
     }
     UnsafeArray <T> .Usar(array, mathod);
 }
Пример #3
0
 public static void Usar(byte[] array,MetodoUnsafeArray metodo)
 {
     if (array == null || metodo == null)
         throw new ArgumentNullException();
     Exception exAux = null;
     unsafe
     {
         fixed(byte * ptrArray=array)
         {
             try
             {
                 metodo(new UnsafeArray(ptrArray, array.Length));
             }
             catch(Exception ex)
             {
                 exAux = ex;
             }
     }
         //lanzo la excepcion en un contexto seguro :D asi no hay problemas con los pointers
         if (exAux != null)
             throw exAux;
     } }