Exemplo n.º 1
0
        internal XElement GetDocComments(ParameterInfo parameter)
        {
            string sig;

            if (parameter.Member is ConstructorInfo)
            {
                sig = Naming.GetAssetId((ConstructorInfo)parameter.Member);
            }
            else if (parameter.Member is PropertyInfo)
            {
                sig = Naming.GetAssetId((PropertyInfo)parameter.Member);
            }
            else
            {
                sig = Naming.GetAssetId((MethodInfo)parameter.Member);
            }

            XElement elem = this.GetMemberElement(sig);

            if (elem != null)
            {
                return(elem.XPathSelectElement(string.Format("param[@name='{0}']", parameter.Name)));
            }
            return(null);
        }
Exemplo n.º 2
0
        private PropertyInfo ResolveProperty(AssetIdentifier assetId, Assembly hintAssembly)
        {
            string asset = assetId.AssetId.Substring(2);

            int  startIndex = 0;
            Type type       = this.GetDeclaringType(asset, ref startIndex, hintAssembly);

            PropertyInfo[] allProps =
                type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static |
                                   BindingFlags.Instance);
            PropertyInfo[] properties =
                allProps
                .Where(p => assetId.AssetId.Equals(Naming.GetAssetId(p), StringComparison.Ordinal))
                .ToArray();

            // if there is a "new" property on the type we'll find both it and the property it hides.
            if (properties.Length == 2 && properties[1].DeclaringType == type)
            {
                return(properties[1]);
            }

            Debug.Assert(properties.Length == 1 || properties.Length == 2,
                         string.Format("Found {0} properties, expected 1 or 2.", properties.Length));

            return(properties[0]);
        }
Exemplo n.º 3
0
        private MemberInfo ResolveMethod(AssetIdentifier assetId, Assembly hintAssembly)
        {
            string asset = assetId.AssetId.Substring(2);

            int  startIndex = 0;
            Type type       = this.GetDeclaringType(asset, ref startIndex, hintAssembly);

            const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance;
            var allMethods =
                type.GetMethods(bindingFlags)
                .Concat <MethodBase>(type.GetConstructors(bindingFlags));

            MethodBase[] methods =
                allMethods.Where(
                    m =>
                    (m is ConstructorInfo &&
                     assetId.AssetId.Equals(Naming.GetAssetId((ConstructorInfo)m),
                                            StringComparison.Ordinal)) ||
                    (m is MethodInfo &&
                     assetId.AssetId.Equals(Naming.GetAssetId((MethodInfo)m), StringComparison.Ordinal)))
                .ToArray();


            // if there is a "new" method on the type we'll find both it and the method it hides.
            if (methods.Length == 2 && methods[1].DeclaringType == type)
            {
                return(methods[1]);
            }

            Debug.Assert(methods.Length == 1 || methods.Length == 2,
                         string.Format("Found {0} methods, expected 1 or 2.", methods.Length));

            return(methods[0]);
        }
Exemplo n.º 4
0
        private object ResolveField(AssetIdentifier assetIdentifier, Assembly hintAssembly)
        {
            string asset = assetIdentifier.AssetId.Substring(assetIdentifier.TypeMarker.Length + 1);

            int  startIndex = 0;
            Type type       = this.GetDeclaringType(asset, ref startIndex, hintAssembly);

            if (type.IsEnum)
            {
                MemberInfo[] members =
                    type.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance |
                                    BindingFlags.Static);

                foreach (MemberInfo memberInfo in members)
                {
                    AssetIdentifier ret = AssetIdentifier.FromMemberInfo(memberInfo);
                    if (ret.AssetId == assetIdentifier.AssetId)
                    {
                        return(memberInfo);
                    }
                }

                return(null);
            }
            else
            {
                FieldInfo[] allFields =
                    type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static |
                                   BindingFlags.Instance);

                return(allFields.Single(f => Naming.GetAssetId(f).Equals(assetIdentifier.AssetId)));
            }
        }
Exemplo n.º 5
0
        internal XElement GetTypeParameterSummary(Type type, Type typeParameter)
        {
            string sig = Naming.GetAssetId(type);

            XElement elem = this.GetMemberElement(sig);

            if (elem != null)
            {
                return(elem.XPathSelectElement(string.Format("typeparam[@name='{0}']", typeParameter.Name)));
            }
            return(null);
        }
Exemplo n.º 6
0
        internal XElement GetDocCommentsReturnParameter(ParameterInfo parameter)
        {
            string sig = Naming.GetAssetId((MethodInfo)parameter.Member);

            XElement elem = this.GetMemberElement(sig);

            if (elem != null)
            {
                return(elem.XPathSelectElement("returns"));
            }
            return(null);
        }
Exemplo n.º 7
0
        private EventInfo ResolveEvent(AssetIdentifier assetIdentifier, Assembly hintAssembly)
        {
            string asset = assetIdentifier.AssetId.Substring(assetIdentifier.TypeMarker.Length + 1);

            int  startIndex = 0;
            Type type       = this.GetDeclaringType(asset, ref startIndex, hintAssembly);

            EventInfo[] allEvents =
                type.GetEvents(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static |
                               BindingFlags.Instance);

            return(allEvents.Single(e => Naming.GetAssetId(e).Equals(assetIdentifier.AssetId)));
        }
Exemplo n.º 8
0
        public static AssetIdentifier FromMemberInfo(MemberInfo memberInfo)
        {
            Module  declaringModule = (memberInfo.ReflectedType ?? memberInfo).Module;
            Version version         = declaringModule.Assembly.GetName().Version;
            string  assetId;

            if (memberInfo is Type)
            {
                assetId = Naming.GetAssetId((Type)memberInfo);
                Type t = (Type)memberInfo;
                if (t.IsGenericParameter)
                {
                    version = (t.DeclaringMethod ?? (MemberInfo)t.ReflectedType).Module.Assembly.GetName().Version;
                }
            }
            else if (memberInfo is ConstructorInfo)
            {
                assetId = Naming.GetAssetId((ConstructorInfo)memberInfo);
            }
            else if (memberInfo is PropertyInfo)
            {
                assetId = Naming.GetAssetId((PropertyInfo)memberInfo);
            }
            else if (memberInfo is MethodInfo)
            {
                assetId = Naming.GetAssetId((MethodInfo)memberInfo);
            }
            else if (memberInfo is EventInfo)
            {
                assetId = Naming.GetAssetId((EventInfo)memberInfo);
            }
            else if (memberInfo is FieldInfo)
            {
                assetId = Naming.GetAssetId((FieldInfo)memberInfo);
            }
            else
            {
                throw new ArgumentOutOfRangeException("memberInfo",
                                                      string.Format("Invalid memeberInfo type: {0}",
                                                                    memberInfo.GetType().Name));
            }


            return(new AssetIdentifier(assetId, version));
        }
Exemplo n.º 9
0
        internal XElement GetDocComments(FieldInfo fieldInfo)
        {
            string sig = Naming.GetAssetId(fieldInfo);

            return(this.GetMemberElement(sig));
        }
Exemplo n.º 10
0
        public XElement GetDocComments(ConstructorInfo ctor)
        {
            string sig = Naming.GetAssetId(ctor);

            return(this.GetMemberElement(sig));
        }
Exemplo n.º 11
0
 public XElement GetDocComments(Type type)
 {
     return(this.GetMemberElement(Naming.GetAssetId(type)));
 }
Exemplo n.º 12
0
        public XElement GetDocComments(MethodInfo methodInfo)
        {
            string sig = Naming.GetAssetId(methodInfo);

            return(this.GetMemberElement(sig));
        }
Exemplo n.º 13
0
        public XElement GetDocComments(EventInfo eventInfo)
        {
            string sig = Naming.GetAssetId(eventInfo);

            return(this.GetMemberElement(sig));
        }
Exemplo n.º 14
0
        public XElement GetDocComments(PropertyInfo propertyInfo)
        {
            string sig = Naming.GetAssetId(propertyInfo);

            return(this.GetMemberElement(sig));
        }
Exemplo n.º 15
0
 public static AssetIdentifier FromNamespace(string namespaceName, Version version)
 {
     return(new AssetIdentifier(Naming.GetAssetId(namespaceName),
                                version));
 }