/// <summary> /// Gets the set of all fields that should not participate in Equals and GetHashCode generated because they're /// the target of [IgnoreDuringEquals]. /// </summary> public static ISet <FieldDefDeclaration> GetIgnoredFields(IAnnotationRepositoryService annotations, ICompilerAdapterService compilerAdapterService) { HashSet <FieldDefDeclaration> fields = new HashSet <FieldDefDeclaration>(); IEnumerator <IAnnotationInstance> ignoredFieldsAnnotations = annotations.GetAnnotationsOfType(typeof(IgnoreDuringEqualsAttribute), false, false); while (ignoredFieldsAnnotations.MoveNext()) { IAnnotationInstance annotationInstance = ignoredFieldsAnnotations.Current; MetadataDeclaration targetElement = annotationInstance.TargetElement; if (targetElement is FieldDefDeclaration field) { fields.Add(field); } else if (targetElement is PropertyDeclaration propertyDeclaration) { FieldDefDeclaration backingField = compilerAdapterService.GetBackingField(propertyDeclaration); if (backingField != null) { fields.Add(backingField); } else { // The property is not an automatic property. // It's ignored, because there is no backing field and we make equality by fields. // We could emit a warning but I don't think that's a great idea. Like, yeah, ignoring a // non-automatic property has no effect but so what: it's ignored, just like the user wanted. } } } return(fields); }
private void UpdateMsil() { if (this.currentObject == this.msilRenderedObject) { return; } MetadataDeclaration declaration = this.currentObject as MetadataDeclaration; if (declaration != null && MsilWriterUtility.CanWriteMsil(declaration)) { if (this.currentObject is ModuleDeclaration) { if (MessageBox.Show(this, "This may take a very long time to display. " + "Do you want to see the MSIL code of the whole module?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { this.tabControl.SelectedTab = this.tabPageProperties; return; } } StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture); MsilWriterUtility.WriteMsil(declaration, stringWriter); this.textBoxMsil.Text = stringWriter.ToString(); this.msilRenderedObject = this.currentObject; } else { this.textBoxMsil.Text = "Disassembly not available for the current element."; } }
public virtual void OnPopulateContextMenu(ContextMenu contextMenu) { MetadataDeclaration declaration = this.Tag as MetadataDeclaration; if (declaration != null && PostSharp.Sdk.Utilities.MsilWriterUtility.CanWriteMsil(declaration)) { contextMenu.MenuItems.Add(new MenuItem("Save MSIL...", this.OnContextMenuSaveMsilClicked)); } }
public override void OnPopulateDefinitionTree(TreeNodeCollection rootNodes) { MetadataDeclaration target = this.Declaration as MetadataDeclaration; if (target != null) { foreach (CustomAttributeDeclaration customAttribute in target.CustomAttributes) { rootNodes.Add(new CustomAttributeTreeNode(customAttribute)); } } }
public void SaveMsil(MetadataDeclaration writeILDefinition) { if (this.saveMsilFileDialog.ShowDialog(this) == DialogResult.OK) { SaveMsilParameter parameter = new SaveMsilParameter(); parameter.Declaration = writeILDefinition; parameter.FileName = this.saveMsilFileDialog.FileName; WaitForm waitForm = new WaitForm(this.SaveMsil, parameter); waitForm.ShowDialog(this); } }
/// <summary> /// Method invoked after aspects have been implemented for each target declaration. /// </summary> /// <param name="targetDeclaration">Declaration on which targets have been applied.</param> /// <param name="aspectWeavers">Ordered list of aspect weavers applied to this declaration.</param> public void AfterImplementAspects( MetadataDeclaration targetDeclaration, LaosAspectWeaver[] aspectWeavers ) { // We only remember a list of the types that have been enhanced. TypeDefDeclaration typeDef = targetDeclaration as TypeDefDeclaration; if ( typeDef == null ) { if ( targetDeclaration is FieldDefDeclaration ) typeDef = ((FieldDefDeclaration) targetDeclaration).DeclaringType; else if ( targetDeclaration is MethodDefDeclaration ) typeDef = ((MethodDefDeclaration) targetDeclaration).DeclaringType; } if (typeDef != null) this.types.AddIfAbsent( typeDef ); }
public override bool Execute() { var consoleWriteLine = FindConsoleWriteLine(); var enumerator = annotationRepositoryService.GetAnnotationsOfType(typeof(HelloWorldAttribute), false, false); while (enumerator.MoveNext()) { // Iterates over declarations to which our attribute has been applied. If the attribute weren't // a MulticastAttribute, that would be just the declarations that it annotates. With multicasting, it // can be far more declarations. MetadataDeclaration targetDeclaration = enumerator.Current.TargetElement; // Multicasting ensures that our attribute is only applied to methods, so there is little chance of // a class cast error here: MethodDefDeclaration targetMethod = (MethodDefDeclaration)targetDeclaration; AddHelloWorldToMethod(targetMethod, consoleWriteLine); } return(true); }
public override MethodBodyTransformationOptions GetOptions(MetadataDeclaration originalTargetElement, MethodSemantics semantic) { return MethodBodyTransformationOptions.None; }
public override MethodBodyTransformationOptions GetOptions(MetadataDeclaration originalTargetElement, MethodSemantics semantic) { return(MethodBodyTransformationOptions.None); }
void ILaosAwareness.ValidateAspects(MetadataDeclaration targetDeclaration, LaosAspectWeaver[] aspectWeavers) { }
void ILaosAwareness.BeforeImplementAspects(MetadataDeclaration targetDeclaration, LaosAspectWeaver[] aspectWeavers) { }
public void SaveMsil( MetadataDeclaration writeILDefinition ) { if ( this.saveMsilFileDialog.ShowDialog( this ) == DialogResult.OK ) { SaveMsilParameter parameter = new SaveMsilParameter(); parameter.Declaration = writeILDefinition; parameter.FileName = this.saveMsilFileDialog.FileName; WaitForm waitForm = new WaitForm( this.SaveMsil, parameter ); waitForm.ShowDialog( this ); } }