void ApplyPreserveInfo(TypeDefinition type) { ApplyPreserveMethods(type); if (!Annotations.IsPreserved(type)) { return; } switch (Annotations.GetPreserve(type)) { case TypePreserve.All: MarkFields(type); MarkMethods(type); break; case TypePreserve.Fields: MarkFields(type); break; case TypePreserve.Methods: MarkMethods(type); break; } }
protected virtual void ProcessType(TypeDefinition type, XPathNavigator nav) { if (IsExcluded(nav)) { return; } TypePreserve preserve = GetTypePreserve(nav); if (!IsRequired(nav)) { Annotations.SetPreserve(type, preserve); return; } if (Annotations.IsMarked(type)) { var existingLevel = Annotations.IsPreserved(type) ? Annotations.GetPreserve(type) : TypePreserve.Nothing; var duplicateLevel = preserve != TypePreserve.Nothing ? preserve : nav.HasChildren ? TypePreserve.Nothing : TypePreserve.All; Context.LogMessage($"Duplicate preserve in {_xmlDocumentLocation} of {type.FullName} ({existingLevel}). Duplicate uses ({duplicateLevel})"); } Annotations.MarkAndPush(type); Tracer.AddDirectDependency(this, type); if (type.IsNested) { var parent = type; while (parent.IsNested) { parent = parent.DeclaringType; Annotations.Mark(parent); } } if (preserve != TypePreserve.Nothing) { Annotations.SetPreserve(type, preserve); } if (nav.HasChildren) { MarkSelectedFields(nav, type); MarkSelectedMethods(nav, type); MarkSelectedEvents(nav, type); MarkSelectedProperties(nav, type); } Tracer.Pop(); }
bool IsCustomAttributeExcluded(CustomAttribute attr) { var type = attr.AttributeType; switch (type.Name) { default: return(false); case "ComDefaultInterfaceAttribute": case "ComVisibleAttribute": case "ClassInterfaceAttribute": case "InterfaceTypeAttribute": case "DispIdAttribute": case "TypeLibImportClassAttribute": case "ComRegisterFunctionAttribute": case "ComUnregisterFunctionAttribute": case "ProgIdAttribute": case "ImportedFromTypeLibAttribute": case "IDispatchImplAttribute": case "ComSourceInterfacesAttribute": case "ComConversionLossAttribute": case "TypeLibTypeAttribute": case "TypeLibFuncAttribute": case "TypeLibVarAttribute": case "ComImportAttribute": case "GuidAttribute": case "ComAliasNameAttribute": case "AutomationProxyAttribute": case "PrimaryInteropAssemblyAttribute": case "CoClassAttribute": case "ComEventInterfaceAttribute": case "TypeLibVersionAttribute": case "ComCompatibleVersionAttribute": case "SetWin32ContextInIDispatchAttribute": case "ManagedToNativeComInteropStubAttribute": if (!FeatureCOM || type.Namespace != "System.Runtime.InteropServices") { return(false); } break; case "EventSourceAttribute": case "EventAttribute": case "EventDataAttribute": case "EventFieldAttribute": case "EventIgnoreAttribute": case "NonEventAttribute": if (!FeatureETW || type.Namespace != "System.Diagnostics.Tracing") { return(false); } break; } var definition = type.Resolve(); if (!Annotations.IsPreserved(definition)) { return(true); } // // We allow xml descriptor to override feature attributes which should be // removed // return(Annotations.GetPreserve(definition) != TypePreserve.All); }