private static void DumpParameter(Parameter p, IntPtr handle) { object val = ParameterInfoAttribute.Get(p, handle); if (val == null) { return; } if (val is int[]) { string[] data = new string[((int[])val).Length]; for (int i = 0; i < data.Length; i++) { data[i] = "0x" + ((int[])val)[i].ToString("X"); } val = "{" + string.Join(", ", data) + "}"; } else if (val is float[]) { val = "{" + string.Join(", ", (float[])val) + "}"; } System.Diagnostics.Debug.WriteLine("Parameter: " + p + " value: " + val); }
public static object Get(Parameter p, IntPtr handle) { object[] attrs = typeof(Parameter).GetField(typeof(Parameter).GetEnumName(p)).GetCustomAttributes(typeof(ParameterInfoAttribute), false); ParameterInfoAttribute item; if (attrs.Length > 0) { item = (ParameterInfoAttribute)attrs[0]; } else { item = new ParameterInfoAttribute(ParameterAccessor.Int); } int size; object ret; switch (item.Access) { case ParameterAccessor.Int: if (handle == IntPtr.Zero) { ret = VG.vgGeti(p); } else { ret = VG.vgGeti(handle, p); } break; case ParameterAccessor.Float: if (handle == IntPtr.Zero) { ret = VG.vgGetf(p); } else { ret = VG.vgGetf(handle, p); } break; case ParameterAccessor.IntArray: if (handle == IntPtr.Zero) { size = VG.vgGetArraySize(p); } else { size = VG.vgGetArraySize(handle, p); } if (VG.vgGetError() == ErrorCode.NoError) { ret = new int[size]; if (size > 0) { if (handle == IntPtr.Zero) { VG.vgGet(p, size, (int[])ret); } else { VG.vgGet(handle, p, size, (int[])ret); } } } else { ret = null; } break; case ParameterAccessor.FloatArray: if (handle == IntPtr.Zero) { size = VG.vgGetArraySize(p); } else { size = VG.vgGetArraySize(handle, p); } if (VG.vgGetError() == ErrorCode.NoError) { ret = new float[size]; if (size > 0) { if (handle == IntPtr.Zero) { VG.vgGet(p, size, (float[])ret); } else { VG.vgGet(handle, p, size, (float[])ret); } } } else { ret = null; } break; default: return(null); } if (VG.vgGetError() != ErrorCode.NoError) { ret = null; } if (ret != null && ret.GetType() != item.Type) { if (item.Type.IsEnum) { ret = Enum.ToObject(item.Type, ret); } else { ret = Convert.ChangeType(ret, item.Type); } } return(ret); }