private TypeDefTreatment GetTypeDefTreatment( TypeHandle typeDef, TypeAttributes flags, string name, string namespaceName, MetadataToken extends) { TypeDefTreatment treatment; // Does the type def have the WindowsRuntime bit set? if (flags.IsWindowsRuntime()) { if (scenario == WinMDScenario.NormalWinMD) { treatment = WinRTProjectedTypes.GetTypeDefinitionTreatment(name, namespaceName); if (treatment != TypeDefTreatment.None) { return(treatment); } // Is this an attribute? if (extends.HandleType == HandleType.TypeReference && GetTypeRefTreatment((TypeReferenceHandle)extends) == TypeRefTreatment.SystemAttribute) { treatment = TypeDefTreatment.NormalAttribute; } else { treatment = TypeDefTreatment.NormalNonAttribute; } } else if (scenario == WinMDScenario.WinMDExp && !flags.IsNested() && flags.IsPublic() && flags.IsSpecialName()) { treatment = TypeDefTreatment.PrefixWinRTName; } else { treatment = TypeDefTreatment.None; } // Scan through Custom Attributes on type, looking for interesting bits. We only // need to do this for RuntimeClasses if (treatment == TypeDefTreatment.PrefixWinRTName || treatment == TypeDefTreatment.NormalNonAttribute) { if (!flags.IsInterface() && HasAttribute(typeDef, "Windows.UI.Xaml", "TreatAsAbstractComposableClassAttribute")) { treatment |= TypeDefTreatment.MarkAbstractFlag; } } } else if (this.scenario == WinMDScenario.WinMDExp && IsClrImplementationType(name, flags)) { treatment = TypeDefTreatment.UnmangleWinRTName; } else { treatment = TypeDefTreatment.None; } return(treatment); }
private MethodDefTreatment ComputeMethodDefTreatment(MethodHandle methodDef) { MethodDefTreatment treatment = MethodDefTreatment.Implementation; TypeDefinition parentType = peFileReader.GetTypeDefinition(peFileReader.FindMethodContainer(methodDef)); TypeAttributes parentFlags = parentType.Flags; if (parentFlags.IsWindowsRuntime()) { if (IsClrImplementationType(peFileReader.StringStream[parentType.Name], parentFlags)) { treatment = MethodDefTreatment.Implementation; } else if (parentFlags.IsNested()) { treatment = MethodDefTreatment.Implementation; } else if (parentFlags.IsInterface()) { treatment = MethodDefTreatment.Interface; } else if (scenario == WinMDScenario.WinMDExp && !parentFlags.IsPublic()) { treatment = MethodDefTreatment.Implementation; } else { treatment = MethodDefTreatment.Other; var parentBaseType = parentType.BaseType; if (HandleType.TypeReference == parentBaseType.HandleType) { switch (GetTypeRefTreatment((TypeReferenceHandle)parentBaseType)) { case TypeRefTreatment.SystemAttribute: treatment = MethodDefTreatment.Attribute; break; case TypeRefTreatment.SystemDelegate: treatment = MethodDefTreatment.Delegate; break; } } } } if (treatment == MethodDefTreatment.Other) { // we want to hide the method if it implements // only redirected interfaces // We also want to check if the methodImpl is IClosable.Close, // so we can change the name bool seenRedirectedInterfaces = false; bool seenNonRedirectedInterfaces = false; bool isIClosableClose = false; foreach (var methodImplHandle in parentType.GetMethodImplementations()) { MethodImpl methodImpl = peFileReader.GetMethodImplementation(methodImplHandle); if (methodImpl.MethodBody == methodDef) { MetadataToken declaration = methodImpl.MethodDeclaration; // See if this MethodImpl implements a redirected interface // In WinMD, MethodImpl will always use MemberRef and TypeRefs to refer to redirected interfaces, // even if they are in the same module. if (declaration.HandleType == HandleType.MemberReference && ImplementsRedirectedInterface((MemberReferenceHandle)declaration, out isIClosableClose)) { seenRedirectedInterfaces = true; if (isIClosableClose) { // This method implements IClosable.Close // Let's rename to IDisposable later // Once we know this implements IClosable.Close, we are done // looking break; } } else { // Now we know this implements a non-redirected interface // But we need to keep looking, just in case we got a methodimpl that // implements the IClosable.Close method and needs to be renamed seenNonRedirectedInterfaces = true; } } } if (isIClosableClose) { treatment = MethodDefTreatment.RenameToDisposeMethod; } else if (seenRedirectedInterfaces && !seenNonRedirectedInterfaces) { // Only hide if all the interfaces implemented are redirected treatment = MethodDefTreatment.HiddenImpl; } } // If treatment is other, then this is a non-managed WinRT runtime class definition // Find out about various bits that we apply via attributes and name parsing if (treatment == MethodDefTreatment.Other) { treatment |= GetMethodTreatmentFromCustomAttributes(methodDef); Method method = peFileReader.GetMethod(methodDef); if (method.Flags != MethodAttributes.SpecialName) { StringHandle methodName = method.Name; if (peFileReader.StringStream.StartsWith(methodName, OperatorPrefixUtf8)) { // TODO (tomat): consider avoiding name allocation by encoding the operator names in UTF8 string nameAfterOp = peFileReader.StringStream.GetSuffix(methodName, OperatorPrefixUtf8.Length); if (Array.BinarySearch <string>(operatorNames, nameAfterOp) < 0) { treatment |= MethodDefTreatment.MarkSpecialName; } } } } return(treatment); }
private TypeDefTreatment GetTypeDefTreatment( TypeHandle typeDef, TypeAttributes flags, string name, string namespaceName, MetadataToken extends) { TypeDefTreatment treatment; // Does the type def have the WindowsRuntime bit set? if (flags.IsWindowsRuntime()) { if (scenario == WinMDScenario.NormalWinMD) { treatment = WinRTProjectedTypes.GetTypeDefinitionTreatment(name, namespaceName); if (treatment != TypeDefTreatment.None) { return treatment; } // Is this an attribute? if (extends.HandleType == HandleType.TypeReference && GetTypeRefTreatment((TypeReferenceHandle)extends) == TypeRefTreatment.SystemAttribute) { treatment = TypeDefTreatment.NormalAttribute; } else { treatment = TypeDefTreatment.NormalNonAttribute; } } else if (scenario == WinMDScenario.WinMDExp && !flags.IsNested() && flags.IsPublic() && flags.IsSpecialName()) { treatment = TypeDefTreatment.PrefixWinRTName; } else { treatment = TypeDefTreatment.None; } // Scan through Custom Attributes on type, looking for interesting bits. We only // need to do this for RuntimeClasses if (treatment == TypeDefTreatment.PrefixWinRTName || treatment == TypeDefTreatment.NormalNonAttribute) { if (!flags.IsInterface() && HasAttribute(typeDef, "Windows.UI.Xaml", "TreatAsAbstractComposableClassAttribute")) { treatment |= TypeDefTreatment.MarkAbstractFlag; } } } else if (this.scenario == WinMDScenario.WinMDExp && IsClrImplementationType(name, flags)) { treatment = TypeDefTreatment.UnmangleWinRTName; } else { treatment = TypeDefTreatment.None; } return treatment; }