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; } } }
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); }
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; } }