protected override IEnumerable <object> GetValidMembers() { var type = Options.EnclosingType; if (type == null || Options.EnclosingMember != null) { yield break; } foreach (var t in type.GetBaseTypes()) { string name; if (!ProtocolMemberContextHandler.HasProtocolAttribute(t, out name)) { continue; } var protocolType = Options.CurrentState.Compilation.GetTypeByMetadataName(t.ContainingNamespace.GetFullName() + "." + name); if (protocolType == null) { break; } foreach (var member in protocolType.GetMembers().OfType <IMethodSymbol>()) { if (member.ExplicitInterfaceImplementations.Length > 0) { continue; } if (!cg.IsValidMember(member)) { continue; } if (IsImplemented(type, member)) { continue; } if (member.GetAttributes().Any(a => a.AttributeClass.Name == "ExportAttribute" && ProtocolMemberContextHandler.IsFoundationNamespace(a.AttributeClass.ContainingNamespace))) { yield return(member); } } foreach (var member in protocolType.GetMembers().OfType <IPropertySymbol>()) { if (member.ExplicitInterfaceImplementations.Length > 0) { continue; } if (!cg.IsValidMember(member)) { continue; } if (IsImplemented(type, member)) { continue; } if (member.GetMethod != null && member.GetMethod.GetAttributes().Any(a => a.AttributeClass.Name == "ExportAttribute" && ProtocolMemberContextHandler.IsFoundationNamespace(a.AttributeClass.ContainingNamespace)) || member.SetMethod != null && member.SetMethod.GetAttributes().Any(a => a.AttributeClass.Name == "ExportAttribute" && ProtocolMemberContextHandler.IsFoundationNamespace(a.AttributeClass.ContainingNamespace))) { yield return(member); } } } }
// public static Attribute GenerateExportAttribute (RefactoringContext ctx, IMember member) // { // if (member == null) // return null; // // bool useMonoTouchNamespace = false; // var exportAttribute = member.GetAttribute (new FullTypeName (new TopLevelTypeName ("Foundation", "ExportAttribute"))); // if (exportAttribute == null) { // useMonoTouchNamespace = true; // exportAttribute = member.GetAttribute (new FullTypeName (new TopLevelTypeName ("MonoTouch.Foundation", "ExportAttribute"))); // } // // if (exportAttribute == null || exportAttribute.PositionalArguments.Count == 0) // return null; // // var astType = useMonoTouchNamespace // ? CreateMonoTouchExportAttributeAst (ctx) // : CreateUnifiedExportAttributeAst (ctx); // // var attr = new Attribute { // Type = astType, // }; // // attr.Arguments.Add (new PrimitiveExpression (exportAttribute.PositionalArguments [0].ConstantValue)); // return attr; // } // // static AstType CreateUnifiedExportAttributeAst (RefactoringContext ctx) // { // var astType = ctx.CreateShortType ("Foundation", "ExportAttribute"); // if (astType is SimpleType) { // astType = new SimpleType ("Export"); // } else { // astType = new MemberType (new SimpleType ("Foundation"), "Export"); // } // return astType; // } // // static AstType CreateMonoTouchExportAttributeAst (RefactoringContext ctx) // { // var astType = ctx.CreateShortType ("MonoTouch.Foundation", "ExportAttribute"); // if (astType is SimpleType) { // astType = new SimpleType ("Export"); // } else { // astType = new MemberType (new MemberType (new SimpleType ("MonoTouch"), "Foundation"), "Export"); // } // return astType; // } // // static IMember GetProtocolMember (RefactoringContext ctx, IType protocolType, IMember member) // { // foreach (var m in protocolType.GetMembers (m => m.SymbolKind == member.SymbolKind && m.Name == member.Name)) { // if (!SignatureComparer.Ordinal.Equals (m, member)) // return null; // var prop = m as IProperty; // if (prop != null) { // if (prop.CanGet && GenerateExportAttribute (ctx, prop.Getter) != null || // prop.CanSet && GenerateExportAttribute (ctx, prop.Setter) != null) // return m; // } else { // if (GenerateExportAttribute (ctx, m) != null) // return m; // } // } // return null; // } // static string GetProtocol(ISymbol member) { var attr = member.GetAttributes().FirstOrDefault(a => a.AttributeClass.Name == "ExportAttribute" && ProtocolMemberContextHandler.IsFoundationNamespace(a.AttributeClass.ContainingNamespace)); if (attr == null || attr.ConstructorArguments.Length == 0) { return(null); } return(attr.ConstructorArguments.First().Value.ToString()); }