/// <summary> /// Constructs a new instance of the attribute. /// </summary> /// <param name="scope">The scope of the modification applied by this attribute.</param> protected MemberActionAttribute(ModificationScope scope) { Scope = scope; }
private static Func<CustomAttribute, bool> AttrFilter(ModificationScope scope) { Func<CustomAttribute, bool> onlyPwAttrs = x => x.AttributeType.Namespace == nameof(Patchwork); Func<CustomAttribute, bool> anyAttr = x => true; return scope.HasFlag(ModificationScope.CustomAttributes) ? anyAttr : onlyPwAttrs; }
/// <summary> /// Initializes a new instance of the <see cref="ModifiesMemberAttribute" /> class. /// </summary> /// <param name="memberName">Optionally, name of the member to be modified. If null, a member with the same name is used.</param> /// <param name="scope"> /// Can limit the scope of the modification. Everything is modified by default. Usually used to make /// things public, etc. /// </param> public ModifiesMemberAttribute(string memberName = null, ModificationScope scope = ModificationScope.All) { MemberName = memberName; Scope = scope; }
void DirtyMasterNode(ModificationScope scope) { m_Graph?.outputNode?.Dirty(scope); }
public void OnModified(ModificationScope scope) { UpdateTitle(); base.expanded = node.drawState.expanded; // Update slots to match node modification if (scope == ModificationScope.Topological) { var slots = node.GetSlots <NodeSlot>().ToList(); var inputPorts = inputContainer.Children().OfType <NodePort>().ToList(); foreach (var port in inputPorts) { var currentSlot = port.slot; var newSlot = slots.FirstOrDefault(s => s.id == currentSlot.id); if (newSlot == null) { // Slot doesn't exist anymore, remove it inputContainer.Remove(port); // We also need to remove the inline input var portInputView = m_PortInputContainer.Children().OfType <PortInputView>().FirstOrDefault(v => Equals(v.slot, port.slot)); portInputView?.RemoveFromHierarchy(); } else { port.slot = newSlot; var portInputView = m_PortInputContainer.Children().OfType <PortInputView>().FirstOrDefault(x => x.slot.id == currentSlot.id); if (newSlot.isConnected) { portInputView?.RemoveFromHierarchy(); } else { portInputView?.UpdateSlot(newSlot); } slots.Remove(newSlot); } } var outputPorts = outputContainer.Children().OfType <NodePort>().ToList(); foreach (var port in outputPorts) { var currentSlot = port.slot; var newSlot = slots.FirstOrDefault(s => s.id == currentSlot.id); if (newSlot == null) { outputContainer.Remove(port); } else { port.slot = newSlot; slots.Remove(newSlot); } } AddSlots(slots); slots.Clear(); slots.AddRange(node.GetSlots <NodeSlot>()); if (inputContainer.childCount > 0) { inputContainer.Sort((x, y) => slots.IndexOf(((NodePort)x).slot) - slots.IndexOf(((NodePort)y).slot)); } if (outputContainer.childCount > 0) { outputContainer.Sort((x, y) => slots.IndexOf(((NodePort)x).slot) - slots.IndexOf(((NodePort)y).slot)); } } else { m_PriorityField.visible = CalculatePriorityVisibility(node); } RefreshExpandedState(); //This should not be needed. GraphView needs to improve the extension api here UpdatePortInputs(); UpdatePortInputVisibilities(); foreach (var control in m_ControlItems.Children().OfType <INodeModificationListener>()) { control.OnNodeModified(scope); } }
public void OnModified(ModificationScope scope) { UpdateTitle(); if (node.hasPreview) { UpdatePreviewExpandedState(node.previewExpanded); } base.expanded = node.drawState.expanded; // Update slots to match node modification if (scope == ModificationScope.Topological) { var slots = node.GetSlots <MaterialSlot>().ToList(); var anchorsToRemove = inputContainer.Children().ToList(); foreach (var anchorElement in anchorsToRemove) { inputContainer.Remove(anchorElement); var attacher = m_Attachers.FirstOrDefault(a => a.target == anchorElement); if (attacher != null) { attacher.Detach(); attacher.element.parent.Remove(attacher.element); m_Attachers.Remove(attacher); } } anchorsToRemove = outputContainer.Children().ToList(); foreach (var ve in anchorsToRemove) { outputContainer.Remove(ve); } foreach (var port in inputContainer.Union(outputContainer).OfType <Port>()) { var slot = (MaterialSlot)port.userData; port.portName = slot.displayName; } AddSlots(slots); if (inputContainer.childCount > 0) { inputContainer.Sort((x, y) => slots.IndexOf(x.userData as MaterialSlot) - slots.IndexOf(y.userData as MaterialSlot)); } if (outputContainer.childCount > 0) { outputContainer.Sort((x, y) => slots.IndexOf(x.userData as MaterialSlot) - slots.IndexOf(y.userData as MaterialSlot)); } } UpdateControls(); RefreshExpandedState(); //This should not be needed. GraphView needs to improve the extension api here UpdateSlotAttachers(); UpdatePortInputVisibilities(); foreach (var control in m_ControlViews) { var listener = control as INodeModificationListener; if (listener != null) { listener.OnNodeModified(scope); } } }
/// <summary> /// Initializes a new instance of the <see cref="ModifiesMemberAttribute" /> class. /// </summary> /// <param name="memberName">Optionally, name of the member to be modified. If null, a member with the same name is used.</param> /// <param name="scope"> /// Can limit the scope of the modification. Everything is modified by default. Usually used to make /// things public, etc. /// </param> public ModifiesMemberAttribute(string memberName = null, ModificationScope scope = ModificationScope.All) : base(scope) { MemberName = memberName; }
public abstract void DirtyNodes(ModificationScope modificationScope = ModificationScope.Node);
public void OnModified(ModificationScope scope) { UpdateTitle(); if (node.hasPreview) { UpdatePreviewExpandedState(node.previewExpanded); } base.expanded = node.drawState.expanded; // Update slots to match node modification if (scope == ModificationScope.Topological) { var slots = node.GetSlots <MaterialSlot>().ToList(); var inputPorts = inputContainer.Children().OfType <ShaderPort>().ToList(); foreach (var port in inputPorts) { var currentSlot = port.slot; var newSlot = slots.FirstOrDefault(s => s.id == currentSlot.id); if (newSlot == null) { // Slot doesn't exist anymore, remove it inputContainer.Remove(port); // We also need to remove the attacher along with the element it's attaching var attacher = m_Attachers.FirstOrDefault(a => a.target == port); if (attacher != null) { attacher.Detach(); attacher.element.parent.Remove(attacher.element); m_Attachers.Remove(attacher); } } else { port.slot = newSlot; slots.Remove(newSlot); } } var outputPorts = outputContainer.Children().OfType <ShaderPort>().ToList(); foreach (var port in outputPorts) { var currentSlot = port.slot; var newSlot = slots.FirstOrDefault(s => s.id == currentSlot.id); if (newSlot == null) { outputContainer.Remove(port); } else { port.slot = newSlot; slots.Remove(newSlot); } } AddSlots(slots); slots.Clear(); slots.AddRange(node.GetSlots <MaterialSlot>()); if (inputContainer.childCount > 0) { inputContainer.Sort((x, y) => slots.IndexOf(((ShaderPort)x).slot) - slots.IndexOf(((ShaderPort)y).slot)); } if (outputContainer.childCount > 0) { outputContainer.Sort((x, y) => slots.IndexOf(((ShaderPort)x).slot) - slots.IndexOf(((ShaderPort)y).slot)); } } UpdateControls(); RefreshExpandedState(); //This should not be needed. GraphView needs to improve the extension api here UpdateSlotAttachers(); UpdatePortInputVisibilities(); foreach (var control in m_ControlViews) { var listener = control as INodeModificationListener; if (listener != null) { listener.OnNodeModified(scope); } } }
/// <summary> /// Patches the target method by overwriting some aspects with your method, such as: its body and accessibility. Also allows adding custom attributes. /// </summary> /// <param name="targetMethod">The target method.</param> /// <param name="yourMethod">Your method.</param> /// <param name="scope">The extent to which to modify the method..</param> private void ModifyMethod(MethodDefinition targetMethod, MethodDefinition yourMethod, ModificationScope scope, bool isNew) { if ((scope & ModificationScope.Accessibility) != 0) { targetMethod.SetAccessibility(yourMethod.GetAccessbility()); } if (isNew) { //There is absolutely no point allowing you to modify the explicit overrides of existing methods. //I thought of adding an enum value, but it will just cause confusion. targetMethod.Overrides.Clear(); foreach (var explicitOverride in yourMethod.Overrides) { targetMethod.Overrides.Add(FixMethodReference(explicitOverride)); } } if ((scope & ModificationScope.CustomAttributes) != 0) { CopyCustomAttributes(targetMethod, yourMethod); CopyCustomAttributes(targetMethod.MethodReturnType, yourMethod.MethodReturnType); for (int i = 0; i < yourMethod.Parameters.Count; i++) { CopyCustomAttributes(targetMethod.Parameters[i], yourMethod.Parameters[i]); } for (int i = 0; i < yourMethod.GenericParameters.Count; i++) { CopyCustomAttributes(targetMethod.GenericParameters[i], yourMethod.GenericParameters[i]); } } if ((scope & ModificationScope.Body) == 0) { return; } if (yourMethod.Body != null) { TransferMethodBody(targetMethod, yourMethod); } else { //this happens in abstract methods and some others. targetMethod.Body = null; } }