string CreateCref(MemberInfo member) { member = GetPropertyForMember(member) ?? member; var cref = new StringBuilder(); switch (member.GetMemberType()) { case "Constructor": cref.Append("C"); break; case "Event": cref.Append("E"); break; case "Field": cref.Append("F"); break; case "Method": cref.Append("M"); break; case "Property": cref.Append("P"); break; case "Type": cref.Append("T"); break; default: throw new InvalidOperationException("Unable to create cref for member: " + member + "."); } cref.Append(":"); AppendMemberRef(cref, member); return(cref.ToString()); }
static IEnumerable <XElement> GetMdocMembers(XElement mdoc, MemberInfo member, RegisterAttribute register, out PropertyInfo property) { MethodInfo method = member as MethodInfo; if (method != null && method.IsSpecialName && !method.IsConstructor) { // member is a get or set method for a property, and the property // won't have a [Register] attribute in the docs. property = method.DeclaringType.Properties // (DefaultBindingFlags) .Single(p => (p.GetMethod == method) || (p.SetMethod == method)); string name = property.Name; return(mdoc.XPathSelectElements("Members/Member") .Where(m => m.Attribute("MemberName").Value == name && m.Element("MemberType").Value == "Property")); } property = null; string attribute = string.IsNullOrEmpty(register.Signature) && string.IsNullOrEmpty(register.Connector) ? string.Format("Android.Runtime.Register(\"{0}\")", register.Name) : string.Format("Android.Runtime.Register(\"{0}\", \"{1}\", \"{2}\")", register.Name, register.Signature, register.Connector); return (from m in mdoc.XPathSelectElements("Members/Member") where m.Elements("Attributes") .Elements("Attribute") .Elements("AttributeName") // now n.Value may have ", ApiSince=xx" suffix, which requires partial matching... .Any(n => string.CompareOrdinal(n.Value, 0, attribute, 0, attribute.Length - 1) == 0) select m); }
public string CrefFromHref(string href) { var m = typeInHref.Match(href); if (!m.Success) { return(string.Format("!:BadHref:{0}", href)); } string jniTypeName = m.Groups ["type"].Value.Replace('.', '$'); if (jniTypeName.EndsWith("package-summary")) { return(CreateNamespaceCref(jniTypeName)); } Type type = GetAvailableTypes() .FirstOrDefault(t => { var r = (RegisterAttribute [])t.GetCustomAttributes <RegisterAttribute> (false); if (r.Length == 0) { return(false); } return(r [0].Name == jniTypeName); }); if (type == null) { return(string.Format("!:NoType:{0};Href={1}", jniTypeName, href)); } string member = m.Groups ["member"].Value; if (string.IsNullOrEmpty(member)) { return("T:" + type.FullName.Replace('/', '+')); } member = TypeUtilities.StripGenericArgument(member); var tregister = ((RegisterAttribute [])type.GetCustomAttributes <RegisterAttribute> (false)) [0]; MemberInfo mi = type.Fields.Cast <MemberInfo> ().Concat(type.Properties).Concat(type.Methods) .FirstOrDefault(x => { var ras = (RegisterAttribute [])x.GetCustomAttributes <RegisterAttribute> (false); return(ras.Any(ra => Application.GetAnchor(tregister, ra) == member)); }); if (mi != null) { return(CreateCref(mi)); } string enumRef; if (Application.EnumMappings != null && Application.EnumMappings.TryGetValue(jniTypeName + "." + member, out enumRef)) { return(enumRef); } return("!:" + type.FullName + "." + member); }
public void UpdateMemberDocs(XElement mdoc, IMemberDefinition member, RegisterAttribute tregister) { XElement jd = Element; RegisterAttribute mregister; string anchor; var section = GetSection(member, tregister); if (section == null) { return; } PropertyInfo property; IEnumerable <XElement> destinations = GetMdocMembers(mdoc, member, section.RegisterAttribute, out property); MemberInfo secondPropertyMember = null; DocumentSection secondSection = null; RegisterAttribute secondmregister; string prefix = null, secondPrefix = null; if (property != null) { MethodInfo mi = member as MethodInfo; if (mi == property.SetMethod) { return; } secondPropertyMember = property.SetMethod; if (secondPropertyMember != null) { secondSection = GetSection(secondPropertyMember, tregister); if (secondSection != null) { prefix = "Get"; secondPrefix = "Set"; } } } foreach (XElement dest in destinations) { section.UpdateMemberSection(member, tregister, dest, prefix, true); if (secondSection != null) { secondSection.UpdateMemberSection(secondPropertyMember, tregister, dest, secondPrefix, false); foreach (var e in dest.Descendants("format")) { foreach (var attr in e.Attributes("tmp").ToList()) { attr.Remove(); } } } } }
PropertyInfo GetPropertyForMember(MemberInfo member) { var method = member as MethodInfo; if (method == null || !method.IsSpecialName) { return(null); } foreach (var p in method.DeclaringType.Properties) { if (p.GetMethod == method || p.SetMethod == method) { return(p); } } return(null); }
/// <summary> /// Gets the names out of the given DexImport/JavaImport attribute. /// </summary> internal static void GetDexOrJavaImportNames(this CustomAttribute attr, IMemberDefinition member, out string memberName, out string descriptor, out string className) { if (attr.ConstructorArguments.Count == 3) { // class, member, descriptor className = (string)attr.ConstructorArguments[0].Value; memberName = (string)attr.ConstructorArguments[1].Value; descriptor = (string)attr.ConstructorArguments[2].Value; } else { // member, descriptor memberName = (string)attr.ConstructorArguments[0].Value; descriptor = (string)attr.ConstructorArguments[1].Value; // Get className from declaring type attr = member.DeclaringType.GetDexImportAttribute(false); attr = attr ?? member.DeclaringType.GetJavaImportAttribute(true); className = (string)attr.ConstructorArguments[0].Value; } }
StringBuilder AppendMemberRef(StringBuilder cref, MemberInfo member) { switch (member.GetMemberType()) { case "Type": { Type type = (Type)member; cref.Append(type.Namespace).Append('.').Append(type.Name); return(cref); } default: AppendMemberRef(cref, (MemberInfo)member.DeclaringType); break; } if (member.GetMemberType() != "Constructor") { cref.Append(".").Append(member.Name); } Mono.Collections.Generic.Collection <ParameterInfo> p = null; if (member is MethodDefinition) { p = ((MethodDefinition)member).Parameters; } else if (member is PropertyDefinition) { p = ((PropertyInfo)member).GetMethod.Parameters; } if (p != null && p.Count > 0) { cref.Append("("); AppendMemberRef(cref, p [0].ParameterType); for (int i = 1; i < p.Count; ++i) { cref.Append(", "); AppendMemberRef(cref, p [1].ParameterType); } cref.Append(")"); } return(cref); }
public DocumentSection GetSection(MemberInfo member, RegisterAttribute tregister) { XElement jd = Element; string anchor = null; var mattrs = (RegisterAttribute [])member.GetCustomAttributes <RegisterAttribute> (false); if (mattrs.Length == 0) { return(null); } var mregister = mattrs.Single(); if (member is MethodDefinition && ((MethodInfo)member).IsPrivate) { return(null); } if (member is TypeDefinition) { return(null); } anchor = Application.GetAnchor(tregister, mregister); if (Application.ProcessingContext.MessageLevel > 1) { Logger.Log(LoggingVerbosity.Debug, 0, "\tUpdating member anchor: {0}", anchor); } string localAnchor = anchor; XElement sectionAnchor = GetSectionAnchor(localAnchor); if (sectionAnchor == null) { Logger.Log(LoggingVerbosity.Warning, Errors.JavaDocSectionNotFound, "Could not find JavaDoc for member '{1}' - managed member is '{0}'", member, anchor); return(null); } return(CreateSection(sectionAnchor, anchor, mregister)); }
static IEnumerable <ExportAttribute> GetExportAttributes(Mono.Cecil.IMemberDefinition p) { return(GetAttributes <ExportAttribute> (p, a => ToExportAttribute(a, p))); }
public static T [] GetCustomAttributes <T> (this Mono.Cecil.IMemberDefinition m, bool dummy) { return(m.CustomAttributes.Where(ca => ca.AttributeType.FullName == typeof(T).FullName) .Select(ca => (T)ca.CreateInstance(typeof(T))).ToArray()); }