public static XmlElement GetXmlFromMember(MethodBase method, bool throwError = true)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            // Calculate the parameter string as this is in the member name in the XML
            var parameters = new List <string>();

            foreach (var parameterInfo in method.GetParameters())
            {
                parameters.Add(DocsTypeService.GetTypeFullNameForXmlDoc(parameterInfo.ParameterType, parameterInfo.IsOut | parameterInfo.ParameterType.IsByRef, true));
            }

            //AL: 15.04.2008 ==> BUG-FIX remove “()” if parametersString is empty
            if (parameters.Count > 0)
            {
                //JA: 11.8.2016 Add ``1 to end of the resulting name if the method is a generic method
                var result = DocsTypeService.GetXmlFromName(method.DeclaringType, 'M', string.Format("{0}{1}{2}", method.Name, method.IsGenericMethod ? "``1" : string.Empty, string.Format("({0})", string.Join(",", parameters))), false);

                // Try a fallback for case where a method with generic parameters is defined on base class.
                if (result == null)
                {
                    var typedParameters = new List <string>();

                    for (var i = 1; i <= parameters.Count; i++)
                    {
                        typedParameters.Add(string.Format("`{0}", i));
                    }

                    return(DocsTypeService.GetXmlFromName(method.DeclaringType, 'M', string.Format(method.Name + "({0})", string.Join(",", typedParameters)), throwError));
                }

                if (result == null && throwError)
                {
                    ThrowHelper.ThrowDocNotFound();
                }

                return(result);
            }
            else
            {
                return(DocsTypeService.GetXmlFromName(method.DeclaringType, 'M', method.Name, throwError));
            }
        }
Ejemplo n.º 2
0
        public static XmlElement GetXmlFromMember(MemberInfo member, bool throwError = true)
        {
            if (member == null)
            {
                throw new ArgumentNullException(nameof(member));
            }

            // First character [0] of member type is prefix character in the name in the XML.
            var prefix = member.MemberType.ToString()[0];

            ParameterInfo[] parameters   = null;
            var             propertyInfo = member as PropertyInfo;

            if (propertyInfo != null && propertyInfo.CanRead)
            {
                parameters = propertyInfo.GetGetMethod().GetParameters();
            }

            var strParameters = new List <string>();

            // Handles getter/setter style properties.
            if (parameters != null && parameters.Length > 0)
            {
                foreach (ParameterInfo parameterInfo in parameters)
                {
                    strParameters.Add(DocsTypeService.GetTypeFullNameForXmlDoc(parameterInfo.ParameterType, parameterInfo.IsOut | parameterInfo.ParameterType.IsByRef, true));
                }

                return(DocsTypeService.GetXmlFromName(member.ReflectedType, prefix, string.Format(member.Name + "({0})", string.Join(",", strParameters)), throwError));
            }
            //handles regular properties
            else
            {
                return(DocsTypeService.GetXmlFromName(member.DeclaringType, member.MemberType.ToString()[0], member.Name, throwError));
            }
        }
Ejemplo n.º 3
0
        public static XmlElement GetXmlForConstructor(ConstructorInfo constructoriInfo, bool throwError = true)
        {
            if (constructoriInfo == null)
            {
                throw new ArgumentNullException(nameof(constructoriInfo));
            }

            // First character [0] of member type is prefix character in the name in the XML.
            var prefix = constructoriInfo.MemberType.ToString()[0];

            var fullNameInDoc = constructoriInfo.ToString().Replace("Void .", String.Empty).Replace("ctor()", "ctor");

            string fullName = fullName = String.Format(CultureInfo.InvariantCulture, "M:{0}.#{1}", constructoriInfo.DeclaringType, fullNameInDoc)
                                         .Replace(" ", string.Empty)
                                         .Replace("Boolean", "System.Boolean")
                                         .Replace("Int32", "System.Int32").Replace("System.System.Int32", "System.Int32")
                                         .Replace("Int64", "System.Int64").Replace("System.System.Int64", "System.Int64")
                                         .Replace("[", "{")
                                         .Replace("]", "}")
                                         .Replace("Int32{}", "Int32[]")
                                         .Replace("Int64{}", "Int64[]")
                                         .Replace("`1", string.Empty);

            ParameterInfo[] parameters = constructoriInfo.GetParameters();
            StringBuilder   sb         = new StringBuilder();

            for (int i = 0; i < parameters.Length; i++)
            {
                var p     = parameters[i];
                var pName = p.ParameterType.FullName
                            .Replace("+", ".")
                            .Replace("[", "{")
                            .Replace("]", "}")
                            .Replace("`1", string.Empty);

                if (Nullable.GetUnderlyingType(p.ParameterType) != null)
                {
                    var underType = Nullable.GetUnderlyingType(p.ParameterType);
                    pName = "System.Nullable{" + underType + "}";
                }
                else if (p.ParameterType.IsArray)
                {
                    pName = p.ParameterType.FullName
                            .Replace("{", "[")
                            .Replace("}", "]");
                }
                else if (p.ParameterType.IsGenericType)
                {
                    pName = string.Format("{0}.{1}", p.ParameterType.Namespace, p.ParameterType.Name).Replace("`1", "") + "{" +
                            p.ParameterType.GenericTypeArguments[0] + "}";
                }

                if (i < parameters.Length - 1)
                {
                    sb.AppendFormat("{0},", pName);
                }
                else
                {
                    sb.AppendFormat("{0}", pName);
                }
            }

            var testConstructorName = string.Format("M:{0}.#ctor({1})", constructoriInfo.DeclaringType.FullName, sb.ToString());

            // return DocsTypeService.GetXmlForConstructor(constructoriInfo.DeclaringType, fullName, throwError);

            return(DocsTypeService.GetXmlForConstructor(constructoriInfo.DeclaringType, testConstructorName, throwError));
        }
Ejemplo n.º 4
0
 public static XmlElement GetXmlForNamespace(string nameSpace, Type someAssemblyType, bool throwError = true)
 {
     // Prefix in type names is T
     return(DocsTypeService.GetXmlForNamepace(nameSpace, someAssemblyType, throwError));
 }
Ejemplo n.º 5
0
 public static XmlElement GetXmlFromType(Type type, bool throwError = true)
 {
     // Prefix in type names is T
     return(DocsTypeService.GetXmlFromName(type, 'T', "", throwError));
 }