/// <summary> /// Find length of required data based on type given /// </summary> /// <param name="type">Type to use</param> /// <param name="data">Data (in case type is of varying length like {Ansi|Wide|Var}String)</param> /// <param name="offset">Offset into data (in case type is of varying length like VarString)</param> /// <returns>Number of bytes for given type, or -1 if none found (or error occured)</returns> public static long LengthOf(Type type, IAccessor <byte> data, long offset) { if (data == null || data.LongCount == 0 || offset < 0 || offset >= data.LongCount) { return(-1); } if (type == null) { return(data.LongCount - offset); } try { IDatatype instance = Registry.Instance(type, data, offset); if (instance != null) { return(instance.LengthOf(data, offset)); } } catch { } throw new ArgumentException(string.Format("Unknown type {0}", type)); }
/// <summary> /// Converts data passed in into a string representation based on type given /// </summary> /// <param name="type">Type to use for conversion</param> /// <param name="data">Data used to form value</param> /// <param name="offset">Optional offset into data</param> /// <returns>String representation</returns> public static string ToString(Type type, IAccessor <byte> data, long offset = 0) { if (0 > offset || offset >= data.LongCount) { throw new IndexOutOfRangeException(); } if (type == null) { return(""); } if (data == null) { return("<NULL>"); } try { IDatatype instance = Registry.Instance(type, data, offset); if (instance != null) { return(instance.ToString()); } } catch { } throw new ArgumentException(string.Format("Unknown type {0}", type)); }
public DataField(string fieldName, string fieldLabel, IDatatype datatype, Guid guid, DataField parent, DataField root) { Id = guid; Datatype = datatype; FieldName = fieldName; FieldLabel = fieldLabel; Root = root; Parent = parent; }
internal static IDatatype Instance(Type type, IAccessor <byte> data, long offset, long length = 0) { if (type.GetInterface("IDatatype") == null) { // A base type was passed in, convert to wrapper Type org = type; type = Get(org.FullName); if (type == null) { type = Get(org.Name); } } IDatatype instance = null; try { // Favour static "FromData_" method MethodInfo method = type.GetMethod("FromData_", new Type[] { typeof(IAccessor <byte>), typeof(long) }); //, BindingFlags.Static); if (method != null) { if (method.GetParameters().Length == 2) { instance = method.Invoke(null, new object[] { data, offset }) as IDatatype; } else { instance = method.Invoke(null, new object[] { data, offset, length }) as IDatatype; } } else { // Favour static "Empty" field before creating temporary instance FieldInfo field = type.GetField("Empty"); //, BindingFlags.Static); if (field != null) { instance = field.GetValue(null) as IDatatype; } else { instance = Activator.CreateInstance(type) as IDatatype; } if (instance != null) { instance = instance.FromData(data, offset); } } } catch { instance = null; } return(instance); }
// PROPAGATION public void propagateTo(IDatatype data) { //_internalData.propagateTo(data); }
protected ConvertationObject(IDatatype type, IComparable data, IPresenter defaultPresentrt) { Data = data; DefaultPresentrt = defaultPresentrt; Datatype = type; }
internal static void AddToUI(MainWindow wnd) { _Wnd = wnd; bool resource_separator = true, view_separator = true, tool_separator = true; MenuItem menu, submenu; ToolBar toolbar; ContentControl tb_button; foreach (KeyValuePair <string, IPlugin> pair in Plugins) { string plugin_name = pair.Key.Replace('.', '_'); IPlugin plugin = pair.Value; toolbar = null; Type[] datatypes = plugin.GetSupportedDatatypes(); if (datatypes != null && datatypes.Length > 0) { menu = wnd.AddCustomMenuItem(wnd.Resource_Menu, plugin_name + "_Datatype", plugin.Name, plugin.Icon, false, null, resource_separator); menu.Tag = new Info(typeof(IPlugin), plugin); resource_separator = false; foreach (Type datatype in datatypes) { string dt_name = plugin_name + "_" + datatype.Name; string name = Attributes.Name.Get(datatype); ImageSource icon = Attributes.IconRef.Get(datatype); IDatatype dt_inst = Activator.CreateInstance(datatype) as IDatatype; if (dt_inst == null) { string msg = string.Format("Unable to create instance for {0}|{1}!", plugin.Name, datatype.FullName); Debug.Fail(msg); } else { Info info = new Info(typeof(IDatatype), datatype); submenu = wnd.AddCustomMenuItem(menu, dt_name, name /*dt_inst.Name*/, icon /*dt_inst.Icon*/, false, _OnMenuItem_Click, false); submenu.Tag = info; if (icon /*dt_inst.Icon*/ != null) { if (toolbar == null) { toolbar = wnd.AddCustomToolbar(plugin_name + "_TB"); } tb_button = wnd.AddCustomToolbarButton(toolbar, dt_name, name /*dt_inst.Name*/, icon /*dt_inst.Icon*/, false, _OnToolbar_Click, false); tb_button.Tag = info; } } } } Type[] panels = plugin.GetSupportedPanels(); if (panels != null && panels.Length > 0) { menu = wnd.AddCustomMenuItem(wnd.View_Menu, plugin_name + "_View", plugin.Name, plugin.Icon, false, null, view_separator); menu.Tag = plugin; view_separator = false; foreach (Type panel in panels) { //IDatatype dt_inst = Activator.CreateInstance(panel) as IDatatype; //if (dt_inst == null) //{ // string msg = string.Format("Unable to create instance for {0}|{1}!", // plugin.Name, datatype.FullName); // Debug.Fail(msg); //} //else //{ // Info info = new Info(typeof(IPanel), panel); // // wnd.AddCustomMenuItem(menu, datatype.Name, name/*dt_inst.Name*/, icon/*dt_inst.Icon*/, // false, _OnMenuItem_Click, false); // submenu.Tag = info; // // if (icon/*dt_inst.Icon*/ != null) // { // if (toolbar == null) // toolbar = wnd.AddCustomToolbar(name + "_TB"); // tb_button = wnd.AddCustomToolbarButton(toolbar, dt_name, name/*dt_inst.Name*/, icon/*dt_inst.Icon*/, // false, _OnToolbar_Click, false); // tb_button.Tag = info; // } // // _Panels.Add(panel.FullName, panel); //} } } Type[] tools = plugin.GetSupportedTools(); if (tools != null && tools.Length > 0) { menu = wnd.AddCustomMenuItem(wnd.Tools_Menu, plugin_name + "_Tool", plugin.Name, plugin.Icon, false, null, tool_separator); menu.Tag = plugin; tool_separator = false; foreach (Type tool in tools) { //IDatatype dt_inst = Activator.CreateInstance(panel) as IDatatype; //if (dt_inst == null) //{ // string msg = string.Format("Unable to create instance for {0}|{1}!", // plugin.Name, datatype.FullName); // Debug.Fail(msg); //} //else //{ // Info info = new Info(typeof(ITool), tool); // // wnd.AddCustomMenuItem(menu, datatype.Name, name/*dt_inst.Name*/, icon/*dt_inst.Icon*/, // false, _OnMenuItem_Click, false); // submenu.Tag = info; // // if (icon/*dt_inst.Icon*/ != null) // { // if (toolbar == null) // toolbar = wnd.AddCustomToolbar(name + "_TB"); // tb_button = wnd.AddCustomToolbarButton(toolbar, dt_name, name/*dt_inst.Name*/, icon/*dt_inst.Icon*/, // false, _OnToolbar_Click, false); // tb_button.Tag = info; // } // // _Tools.Add(tool.FullName, tool); //} } } //Type[] analyzers = plugin.GetSupportedAnalyzers(); //... } }
public AbstractDatatypeDebugger(IDatatype data) : base() { _internalData = data; }
public DatatypeDebuggerAbstract(IDatatype datatype) : base() { _internalDatatype = datatype; }
public bool TryGetDatatype(out IDatatype datatype, string nameKey) { datatype=Datatypes.FirstOrDefault(dt => dt.NameKey == nameKey); return datatype == null; }
public void RegisterTypeToDatatype(Type t, IDatatype datatype) { RegisteredConversions[t] = datatype; }