public EntryMismatchError[] ToArray()
 {
     if (Buffer == IntPtr.Zero)
         return null;
     var buffer = new EntryMismatchError[Length];
     for (int i = 0; i < Length; i++)
     {
         unsafe
         {
             RawDependencyError* current = ((RawDependencyError*)Buffer) + i;
             buffer[i] = new EntryMismatchError(*current);
         }
     }
     return buffer;
 }
Exemple #2
0
        public        EntryMismatchError[] ToArray()
        {
            if (Buffer == IntPtr.Zero)
            {
                return(null);
            }
            var buffer = new EntryMismatchError[Length];

            for (int i = 0; i < Length; i++)
            {
                unsafe
                {
                    RawDependencyError *current = ((RawDependencyError *)Buffer) + i;
                    buffer[i] = new EntryMismatchError(*current);
                }
            }
            return(buffer);
        }
Exemple #3
0
        private string[] GetStringArray(string[] path, out EntryMismatchError error)
        {
            unsafe
            {
                var handles = new GCHandle[path.Length];
                var buffers = new Utf8String[path.Length];
                for (int i = 0; i < path.Length; i++)
                {
                    byte[] buffer = Encoding.UTF8.GetBytes(path[i]);
                    handles[i] = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                    buffers[i] = new Utf8String(handles[i].AddrOfPinnedObject(), buffer.Length);
                }
                string[] result;
                fixed(Utf8String *arr = buffers)
                {
                    using (StringArrayQueryResult ffiResult = Rust.Call(SafeNativeMethods.get_string_array, manifest, new RawSlice(arr, buffers.Length)))
                    {
                        result = ffiResult.Result.ToArray();
                        if (result == null && ffiResult.Error.Kind.Buffer != IntPtr.Zero)
                        {
                            int    length       = ffiResult.Error.Depth;
                            string expectedType = length < path.Length - 1 ? "table" : "string";
                            error = new EntryMismatchError(String.Join(".", path.Take(length + 1)), expectedType, ffiResult.Error.Kind.ToString());
                        }
                        else
                        {
                            error = default(EntryMismatchError);
                        }
                    }
                }

                for (int i = 0; i < handles.Length; i++)
                {
                    handles[i].Free();
                }
                return(result);
            }
        }