public static PackerAttribute Read(IAnnotationInstance annotation) { PackerAttribute config = new PackerAttribute(); MemberValuePairCollection namedArguments = annotation.Value.NamedArguments; config.DisableCleanup = namedArguments.GetSafeBool(nameof(PackerAttribute.DisableCleanup), false); config.DisableCompression = namedArguments.GetSafeBool(nameof(PackerAttribute.DisableCompression), false); config.IncludeDebugSymbols = namedArguments.GetSafeBool(nameof(PackerAttribute.IncludeDebugSymbols), true); config.LoadAtModuleInit = namedArguments.GetSafeBool(nameof(PackerAttribute.LoadAtModuleInit), true); config.CreateTemporaryAssemblies = namedArguments.GetSafeBool(nameof(PackerAttribute.CreateTemporaryAssemblies), false); config.IgnoreSatelliteAssemblies = namedArguments.GetSafeBool(nameof(PackerAttribute.IgnoreSatelliteAssemblies), false); config.IncludeAssemblies = namedArguments.GetSafeStringArray(nameof(PackerAttribute.IncludeAssemblies)); config.ExcludeAssemblies = namedArguments.GetSafeStringArray(nameof(PackerAttribute.ExcludeAssemblies)); config.PreloadOrder = namedArguments.GetSafeStringArray(nameof(PackerAttribute.PreloadOrder)); config.Unmanaged32Assemblies = namedArguments.GetSafeStringArray(nameof(PackerAttribute.Unmanaged32Assemblies)); config.Unmanaged64Assemblies = namedArguments.GetSafeStringArray(nameof(PackerAttribute.Unmanaged64Assemblies)); if (config.IncludeAssemblies != null && config.IncludeAssemblies.Length > 0 && config.ExcludeAssemblies != null && config.ExcludeAssemblies.Length > 0) { Message.Write(annotation.TargetElement, SeverityType.Error, "JOE01", "Set IncludeAssemblies, or ExcludeAssemblies, but not both."); } return(config); }
/// <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); }
public override bool Execute() { IEnumerator <IAnnotationInstance> annotations = annotationService.GetAnnotationsOfType(typeof(DeepSerializableAttribute), false, true); while (annotations.MoveNext()) { IAnnotationInstance annotation = annotations.Current; MakeSerializableRecursively(annotation.TargetElement as TypeDefDeclaration); } return(base.Execute()); }
/// <summary> /// Gets types for which Equals or GetHashCode should be synthesized, in such an order that base classes come before /// derived classes. This way, when Equals for a derived class is being created, you can be already sure that /// the Equals for the base class was already created (if the base class was target of [StructuralEquality]. /// </summary> private List <EqualsType> GetTypesToEnhance() { IEnumerator <IAnnotationInstance> annotationsOfType = annotationRepositoryService.GetAnnotationsOfType(typeof(StructuralEqualityAttribute), false, false); // TODO: Change the List into a StructuredDeclarationDictionary, because then Visit takes the order of inheritance into // account. But first we would need to make that public in PostSharp.Compiler.Engine. List <EqualsType> toEnhance = new List <EqualsType>(); while (annotationsOfType.MoveNext()) { IAnnotationInstance annotation = annotationsOfType.Current; if (annotation?.TargetElement is TypeDefDeclaration enhancedType) { StructuralEqualityAttribute config = EqualityConfiguration.ExtractFrom(annotation.Value); EqualsType newType = new EqualsType(enhancedType, config); toEnhance.Add(newType); } } toEnhance.Sort((first, second) => { if (first.EnhancedType.IsAssignableTo(second.EnhancedType)) { if (second.EnhancedType.IsAssignableTo(first.EnhancedType)) { return(0); } return(1); } return(-1); }); return(toEnhance); }
protected override AdviceGroupingKey GetGroupingKey(IAnnotationInstance adviseAnnotation) { var key = base.GetGroupingKey(adviseAnnotation); return key; }
public override bool ValidateAdvice(IAnnotationInstance adviseAnnotation) { if (adviseAnnotation.TargetElement.GetTokenType() != TokenType.TypeDef) return false; return base.ValidateAdvice(adviseAnnotation); }