示例#1
0
        /// <summary>
        /// Gets the parameters for this method from the test data.
        /// </summary>
        /// <param name="testData">The test data.</param>
        /// <param name="test">The test.</param>
        /// <returns></returns>
        public object[] GetParameters(byte[] testData, int test)
        {
            // TODO I suspect this can all be done a lot easier with Span<T> once upgraded to .Net Core 2.1

            // Grab test data
            object[] parameters = new object[ParameterFields.Count];
            GCHandle handle     = GCHandle.Alloc(testData, GCHandleType.Pinned);

            try
            {
                foreach (KeyValuePair <ParameterInfo, PaddedStructCreator.Field> kvp in ParameterFields)
                {
                    ParameterInfo             pInfo = kvp.Key;
                    PaddedStructCreator.Field field = kvp.Value;

                    // Create object of correct type
                    IntPtr ptr = Marshal.AllocCoTaskMem(field.AlignmentInfo.CSharpSize);
                    Marshal.Copy(
                        testData,
                        FieldOffset(field, test),
                        ptr,
                        field.AlignmentInfo.CSharpSize);

                    // Assign parameter
                    parameters[pInfo.Position] = Marshal.PtrToStructure(ptr, field.Type);
                }

                return(parameters);
            }
            finally
            {
                handle.Free();
            }
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MethodMap" /> class.
 /// </summary>
 /// <param name="mappings">The mappings.</param>
 /// <param name="index">The index.</param>
 /// <param name="method">The method.</param>
 /// <param name="parameterFields">The parameterFields.</param>
 /// <param name="resultField">The return field.</param>
 /// <param name="resultSetOffset">The result set offset.</param>
 public MethodMap(Mappings mappings, int index, MethodInfo method, IReadOnlyDictionary <ParameterInfo, PaddedStructCreator.Field> parameterFields, PaddedStructCreator.Field resultField, int resultSetOffset)
 {
     Mappings        = mappings;
     Index           = index;
     Method          = method;
     ParameterFields = parameterFields;
     ResultField     = resultField;
     ResultSetOffset = resultField == null ? -1 : resultSetOffset;
     Signature       =
         $"{method.ReturnType.Name} {method.DeclaringType.FullName}.{method.Name}({String.Join(", ", ParameterFields.Select(p => $"{p.Key.ParameterType.Name} {p.Key.Name}"))})";
 }
示例#3
0
 private int FieldOffset(PaddedStructCreator.Field field, int test) =>
 test * Mappings.BufferSize + Index * Mappings.StructSize + field.Position;