public void AddOptions(OptionSet options) { ArgumentUtility.CheckNotNull("options", options); options.Add( "att|attribute=", "Mark affected methods with custom attribute [None | Generated | Custom] (default = Generated)", att => _mode = (AttributeMode)Enum.Parse(typeof(AttributeMode), att)); options.Add( "attPrefix=", "The unspeakable prefix for the virtual method. (default value: '<>virtualized_')", prefix => _unspeakablePrefix = prefix); options.Add( "attFullName=", "Fullname of the attribute type (default value: 'NonVirtualAttributeNonVirtualAttribute').", at => { _attName = at.Substring(at.LastIndexOf(".") + 1, at.Length - at.LastIndexOf(".") - 1); _attNamespace = at.Substring(0, at.LastIndexOf(".")); }); options.Add( "attFile|attributeFile=", "Assembly containing the custom attribute (dll or exe). ONLY applicable in 'Custom' attribute mode!", custAtt => _attributeAssembly = custAtt); _selectionFactory = new TargetSelectorFactory(); _selectionFactory.AddOptions(options); }
public void AddOptions(OptionSet options) { ArgumentUtility.CheckNotNull ("options", options); options.Add ( "att|attribute=", "Mark affected methods with custom attribute [None | Generated | Custom] (default = Generated)", att => _mode = (AttributeMode) Enum.Parse (typeof (AttributeMode), att)); options.Add ( "attPrefix=", "The unspeakable prefix for the virtual method. (default value: '<>virtualized_')", prefix => _unspeakablePrefix = prefix); options.Add ( "attFullName=", "Fullname of the attribute type (default value: 'NonVirtualAttributeNonVirtualAttribute').", at => { _attName = at.Substring (at.LastIndexOf (".") + 1, at.Length - at.LastIndexOf (".") - 1); _attNamespace = at.Substring (0, at.LastIndexOf (".")); } ); options.Add ( "attFile|attributeFile=", "Assembly containing the custom attribute (dll or exe). ONLY applicable in 'Custom' attribute mode!", custAtt => _attributeAssembly = custAtt); _selectionFactory = new TargetSelectorFactory (); _selectionFactory.AddOptions (options); }
private IMarkingAttributeStrategy CreateMarkingStrategy(AttributeMode attributeMode) { switch (attributeMode) { case AttributeMode.None: Console.WriteLine("MethodVirtualizer: Using no marking attribute!"); return(new NoneMarkingAttributeStrategy()); case AttributeMode.Custom: ModuleDefinition customAttributeModule = null; try { foreach (var module in _fileSystem.ReadAssembly(_attributeAssembly, new ReaderParameters { ReadSymbols = false }).Modules) { foreach (var attType in module.Types) { if (attType.Namespace == _attNamespace && attType.Name == _attName) { customAttributeModule = module; } } } if (customAttributeModule == null) { throw new ProgramArgumentException("MethodVirtualizer: The given custom attribute is not available in the given assembly!"); } } catch (BadImageFormatException e) { throw new ArgumentException("MethodVirtualizer: The given custom attribute file could not be opened!", e); } Console.WriteLine("MethodVirtualizer: Using the custom attribute: " + _attNamespace + "." + _attName + " in " + _attributeAssembly + "."); return(new CustomMarkingAttributeStrategy(_attNamespace, _attName, customAttributeModule, _unspeakablePrefix)); default: Console.WriteLine("MethodVirtualizer: Using default attribute mechanism, generating attribute: " + _attNamespace + "." + _attName + " in main module."); return(new GeneratedMarkingAttributeStrategy(_attNamespace, _attName)); } }
private void attributeTextbox_KeyDown(object sender, KeyEventArgs e) { if (MediaManager.getActiveMediaManager() == null) { return; } if (e.KeyCode == Keys.Up) { tagTextbox.Focus(); } else if (e.KeyCode == Keys.Enter) { if (m_taggingMode == AttributeMode.SpecifyAttribute) { if (attributeTextbox.Text.Length == 0) { ActiveItemIndex++; tagTextbox.Focus(); RefreshTags(); RefreshAttributes(); } else { string attribute=attributeTextbox.Text; if (!MediaManager.getActiveMediaManager().hasAttribute(attribute)) { MediaManager.getActiveMediaManager().addAttribute(attribute); } RefreshAttributes(); attributeNameListBox.SelectedItem = attribute; attributeTextbox.Text = ""; lblAttributes.Text = "Enter value for selected attribute:"; m_taggingMode = AttributeMode.SpecifyAttributeValue; RefreshAttributes(); } } else // m_taggingMode==AttributeMode.SpecifyAttributeValue { if (attributeTextbox.Text.Length == 0) { attributeTextbox.Text = ""; attributeNameListBox.SelectedIndex = -1; attributeNameListBox.SelectedIndex = -1; attributeTextbox.Text = ""; lblAttributes.Text = "Select Attribute:"; m_taggingMode = AttributeMode.SpecifyAttribute; RefreshAttributes(); } else { if (attributeNameListBox.SelectedIndex != -1) { ActiveItem.appendAttribute((string)attributeNameListBox.SelectedItem, attributeTextbox.Text); attributeTextbox.Text = ""; RefreshTags(); RefreshAttributes(); } else { attributeTextbox.Text = ""; RefreshTags(); RefreshAttributes(); lblAttributes.Text = "Select Attribute:"; m_taggingMode = AttributeMode.SpecifyAttribute; } } } } }
private IMarkingAttributeStrategy CreateMarkingStrategy(AttributeMode attributeMode) { switch (attributeMode) { case AttributeMode.None: Console.WriteLine ("MethodVirtualizer: Using no marking attribute!"); return new NoneMarkingAttributeStrategy (); case AttributeMode.Custom: ModuleDefinition customAttributeModule = null; try { foreach (var module in _fileSystem.ReadAssembly (_attributeAssembly, new ReaderParameters {ReadSymbols = false}).Modules) { foreach (var attType in module.Types) { if (attType.Namespace == _attNamespace && attType.Name == _attName) customAttributeModule = module; } } if (customAttributeModule == null) throw new ProgramArgumentException ("MethodVirtualizer: The given custom attribute is not available in the given assembly!"); } catch (BadImageFormatException e) { throw new ArgumentException ("MethodVirtualizer: The given custom attribute file could not be opened!", e); } Console.WriteLine ("MethodVirtualizer: Using the custom attribute: " + _attNamespace + "." + _attName + " in " + _attributeAssembly + "."); return new CustomMarkingAttributeStrategy (_attNamespace, _attName, customAttributeModule, _unspeakablePrefix); default: Console.WriteLine ("MethodVirtualizer: Using default attribute mechanism, generating attribute: " + _attNamespace + "." + _attName + " in main module."); return new GeneratedMarkingAttributeStrategy (_attNamespace, _attName); } }
internal static extern void Urho3D_Serializable_RegisterAttribute(IntPtr context, uint typeHash, VariantType type, [param: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StringUtf8))] string name, IntPtr defaultValue, AttributeMode mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StringUtf8ArrayMarshaller))] string[] enumNames, IntPtr getter, IntPtr setter);
public virtual void DrawContext(AttributeData data, bool showRemove = false, bool isRoot = true) { if (this.labelRect.AddWidth(20).Clicked(1)) { this.contextOpen = true; GenericMenu menu = new GenericMenu(); AttributeMode mode = this.attribute.info.mode; AttributeUsage usage = data.usage; bool advanced = EditorPref.Get <bool>(data.path + "Advanced"); MenuFunction toggleAdvanced = () => { EditorPref.Set <bool>(data.path + "Advanced", !advanced); }; MenuFunction removeAttribute = () => { this.attribute.Remove(data); }; MenuFunction modeNormal = () => { this.attribute.info.mode = AttributeMode.Normal; }; MenuFunction modeLinked = () => { this.attribute.info.mode = AttributeMode.Linked; }; MenuFunction modeFormula = () => { this.attribute.info.mode = AttributeMode.Formula; }; MenuFunction modeGroup = () => { this.attribute.info.mode = AttributeMode.Group; }; MenuFunction usageDirect = () => { data.usage = AttributeUsage.Direct; data.referencePath = ""; data.referenceID = ""; data.reference = null; }; MenuFunction usageShaped = () => { data.usage = AttributeUsage.Shaped; }; MenuFunction fixType = () => { this.SwapType(0, typeof(DataType), this.attribute.defaultSet); }; bool normal = this.attribute.info.mode == AttributeMode.Normal; if (this.attribute.locked) { menu.AddDisabledItem(new GUIContent("Attribute Locked")); menu.ShowAsContext(); return; } if (isRoot || mode.Matches("Normal", "Linked")) { if (mode.Matches("Normal", "Linked") && usage.Matches("Shaped") && this.attribute.canAdvanced) { menu.AddItem(new GUIContent("Advanced"), advanced, toggleAdvanced); menu.AddSeparator("/"); } if (this.attribute.canDirect) { menu.AddItem(new GUIContent("Direct"), normal && (usage == AttributeUsage.Direct), fixType + modeNormal + usageDirect); } if (this.attribute.canShape) { menu.AddItem(new GUIContent("Shaped"), normal && (usage == AttributeUsage.Shaped), fixType + modeNormal + usageShaped); } if (this.attribute.canLink) { menu.AddItem(new GUIContent("Linked"), (mode == AttributeMode.Linked), fixType + modeLinked + usageShaped); } menu.AddSeparator("/"); if (this.attribute.canFormula) { menu.AddItem(new GUIContent("Formula"), (mode == AttributeMode.Formula), modeFormula); } if (this.attribute.canGroup) { menu.AddItem(new GUIContent("Group"), (mode == AttributeMode.Group), modeGroup); } } else if (mode.Matches("Formula")) { menu.AddItem(new GUIContent("Advanced"), advanced, toggleAdvanced); this.DrawTypeMenu(data, menu); menu.AddSeparator("/"); if (this.attribute.canDirect) { menu.AddItem(new GUIContent("Direct"), usage == AttributeUsage.Direct, usageDirect); } if (this.attribute.canShape) { menu.AddItem(new GUIContent("Shaped"), usage == AttributeUsage.Shaped, usageShaped); } } if (showRemove) { if (!mode.Matches("Group")) { menu.AddSeparator("/"); } menu.AddItem(new GUIContent("Remove"), false, removeAttribute); } menu.ShowAsContext(); } if (this.contextOpen && Event.current.button == 0) { this.dirty = true; this.contextOpen = false; } }