コード例 #1
0
        /// <summary>
        /// Examines the set of <paramref name="attributes"/> and returns a new <see cref="SourceInfo"/>
        /// instance from the first <c>SourceInfoAttribute</c> in the set.
        /// </summary>
        /// <param name="attributes">A list of attribute instances that may contain a <c>SourceInfoAttribute</c>.</param>
        /// <returns>A new <see cref="SourceInfo"/> instance or <c>null</c> if the set of <paramref name="attributes"/>
        /// did not contain a <c>SourceInfoAttribute</c>.
        /// </returns>
        internal static SourceInfo GetSourceInfoFromAttributes(IEnumerable <object> attributes)
        {
            SourceInfo sourceInfo = null;

            foreach (object attribute in attributes)
            {
                Type attributeType = attribute.GetType();
                if (((SourceInfo.sourceInfoAttributeType != null && attributeType == SourceInfo.sourceInfoAttributeType)) ||
                    attributeType.FullName.EndsWith(SourceInfo.SourceInfoAttributeTypeName, StringComparison.Ordinal))
                {
                    return(SourceInfo.GetSourceInfoFromAttribute(attribute));
                }
            }

            return(sourceInfo);
        }
コード例 #2
0
            /// <summary>
            /// See <see cref="ISourceFileProvider.GetFileForMember"/>.
            /// </summary>
            /// <remarks>
            /// This implementation-specific method uses Reflection to find a
            /// <c>SourceInfoAttribute</c> attached to the member.  If present,
            /// it identifies the source file.
            /// </remarks>
            /// <param name="memberInfo">The member for which a file location is needed.</param>
            /// <returns>The file name or <c>null</c> if it cannot be determined.</returns>
            public string GetFileForMember(MemberInfo memberInfo)
            {
                SourceInfo sourceInfo = SourceInfo.GetSourceInfoFromAttributes(((ICustomAttributeProvider)memberInfo).GetCustomAttributes(false));

                return((sourceInfo == null) ? null : sourceInfo.FileName);
            }