当前位置: 首页>>代码示例>>C#>>正文


C# MethodBase.IsOperatorOverload方法代码示例

本文整理汇总了C#中System.Reflection.MethodBase.IsOperatorOverload方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.IsOperatorOverload方法的具体用法?C# MethodBase.IsOperatorOverload怎么用?C# MethodBase.IsOperatorOverload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.MethodBase的用法示例。


在下文中一共展示了MethodBase.IsOperatorOverload方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MemberFilter

 /// <summary>
 /// Determines if a member is valid for this repository.
 /// </summary>
 /// <param name="methodBase">The member to test.</param>
 /// <param name="isPropertyMethod">Indicates that the method is a property getter or setter.</param>
 /// <returns><c>true</c> if the member is valid.</returns>
 protected virtual bool MemberFilter(MethodBase methodBase, bool isPropertyMethod)
 {
     if (methodBase == null)
         return false;
     if (methodBase.GetExternalVisibility() == ExternalVisibilityKind.Hidden)
         return false;
     var name = methodBase.Name;
     if (name.Length >= 2 && (name[0] == '$' || name[name.Length - 1] == '$'))
         return false;
     if (methodBase.IsFinalizer())
         return false;
     if(!isPropertyMethod && methodBase.IsSpecialName){
         if(methodBase.IsConstructor)
             return true;
         if(methodBase.IsOperatorOverload())
             return true;
         return false;
     }
     return true;
 }
开发者ID:aarondandy,项目名称:ducky-docs,代码行数:26,代码来源:ReflectionCodeDocMemberRepository.cs

示例2: ConvertToModel

            private CodeDocMethod ConvertToModel(MethodBase methodBase, CodeDocMemberDetailLevel detailLevel, ICodeDocMemberDataProvider extraMemberDataProvider = null)
            {
                Contract.Requires(methodBase != null);
                Contract.Ensures(Contract.Result<CodeDocMethod>() != null);
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocMethod>().ShortName));
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocMethod>().FullName));
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocMethod>().Title));
                Contract.Ensures(Contract.Result<CodeDocMethod>().Title == Contract.Result<CodeDocMethod>().ShortName);
                Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<CodeDocMethod>().SubTitle));

                var includeExceptions = detailLevel != CodeDocMemberDetailLevel.Minimum;
                var appendXmlDoc = detailLevel.HasFlag(CodeDocMemberDetailLevel.Summary) || detailLevel.HasFlag(CodeDocMemberDetailLevel.AdditionalContents);
                var provideXmlDoc = includeExceptions || detailLevel != CodeDocMemberDetailLevel.Minimum;
                var includeInheritance = detailLevel.HasFlag(CodeDocMemberDetailLevel.Inheritance);
                var includeParameters = detailLevel != CodeDocMemberDetailLevel.Minimum;

                var methodInfo = methodBase as MethodInfo;
                var methodCRef = GetCRefIdentifier(methodBase);
                var model = new CodeDocMethod(methodCRef);
                model.Uri = GetUri(methodBase);

                var memberDataProvider = new CodeDocMemberInfoProvider<MethodBase>(methodBase);

                if (provideXmlDoc) {
                    var xmlDocs = XmlDocs.GetMember(methodCRef.FullCRef);
                    if (xmlDocs != null)
                        memberDataProvider.Add(new CodeDocMemberXmlDataProvider(xmlDocs));
                }

                if (extraMemberDataProvider != null)
                    memberDataProvider.Add(extraMemberDataProvider);

                if (includeInheritance && methodInfo != null) {
                    var baseDefinition = methodInfo.FindNextAncestor();
                    if (baseDefinition != null) {
                        var baseDefinitionModel = GetOnly(GetCRefIdentifier(baseDefinition), detailLevel);
                        if (baseDefinitionModel != null)
                            memberDataProvider.Add(new CodeDocMemberDataProvider(baseDefinitionModel));
                    }
                }

                if (appendXmlDoc)
                    ApplyContentXmlDocs(model, memberDataProvider);

                model.ExternalVisibility = memberDataProvider.ExternalVisibility ?? ExternalVisibilityKind.Public;
                model.ShortName = RegularTypeDisplayNameOverlay.GetDisplayName(methodBase);
                model.FullName = FullTypeDisplayNameOverlay.GetDisplayName(methodBase);
                model.Title = model.ShortName;
                Contract.Assume(methodBase.DeclaringType != null);
                model.NamespaceName = methodBase.DeclaringType.Namespace;

                if (includeParameters) {
                    model.Parameters = Array.ConvertAll(
                        methodBase.GetParameters(),
                        p => CreateArgument(p, memberDataProvider));

                    if (methodInfo != null && methodInfo.ReturnParameter != null &&
                        methodInfo.ReturnType != typeof (void))
                        model.Return = CreateReturn(methodInfo.ReturnParameter, memberDataProvider);
                }

                if (methodBase.IsConstructor)
                    model.SubTitle = "Constructor";
                else if (model.Parameters != null && model.Parameters.Count == 1 && model.HasReturn && CSharpOperatorNameSymbolMap.IsConversionOperatorMethodName(methodBase.Name)) {
                    model.SubTitle = "Conversion";

                    string conversionOperationName;
                    if (methodBase.Name.EndsWith("Explicit", StringComparison.OrdinalIgnoreCase))
                        conversionOperationName = "Explicit";
                    else if (methodBase.Name.EndsWith("Implicit", StringComparison.OrdinalIgnoreCase))
                        conversionOperationName = "Implicit";
                    else
                        conversionOperationName = String.Empty;

                    var conversionParameterPart = String.Concat(
                        model.Parameters[0].ParameterType.ShortName,
                        " to ",
                        model.Return.ParameterType.ShortName);

                    model.ShortName = String.IsNullOrEmpty(conversionOperationName)
                        ? conversionParameterPart
                        : String.Concat(conversionOperationName, ' ', conversionParameterPart);
                    model.Title = model.ShortName;
                }
                else if (methodBase.IsOperatorOverload())
                    model.SubTitle = "Operator";
                else
                    model.SubTitle = "Method";

                Contract.Assume(methodBase.DeclaringType != null);
                model.Namespace = GetOrCreateNamespaceByName(methodBase.DeclaringType.Namespace);
                model.Assembly = GetCodeDocAssembly(methodBase.DeclaringType.Assembly);
                model.DeclaringType = GetOrConvert(methodBase.DeclaringType, CodeDocMemberDetailLevel.Minimum);
                model.IsOperatorOverload = methodBase.IsOperatorOverload();
                model.IsExtensionMethod = methodBase.IsExtensionMethod();
                model.IsSealed = methodBase.IsSealed();
                model.IsStatic = memberDataProvider.IsStatic.GetValueOrDefault();
                model.IsObsolete = memberDataProvider.IsObsolete.GetValueOrDefault();
                model.IsPure = memberDataProvider.IsPure.GetValueOrDefault();

//.........这里部分代码省略.........
开发者ID:aarondandy,项目名称:ducky-docs,代码行数:101,代码来源:ReflectionCodeDocMemberRepository.cs

示例3: GetDisplayName

        /// <summary>
        /// Generates a display name for the given method.
        /// </summary>
        /// <param name="methodBase">The method to generate a display name for.</param>
        /// <returns>A display name.</returns>
        public string GetDisplayName(MethodBase methodBase)
        {
            if (null == methodBase) throw new ArgumentNullException("methodBase");
            Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<string>()));
            string name;
            if (methodBase.IsConstructor) {
                Contract.Assume(methodBase.DeclaringType != null);
                var typeName = methodBase.DeclaringType.Name;
                if (methodBase.DeclaringType.GetGenericArguments().Length > 0) {
                    var tickIndex = typeName.LastIndexOf('`');
                    if (tickIndex >= 0)
                        typeName = typeName.Substring(0, tickIndex);
                }
                name = typeName;
            }
            else if (methodBase.IsOperatorOverload()) {
                if (CSharpOperatorNameSymbolMap.TryGetOperatorSymbol(methodBase.Name, out name)) {
                    name = String.Concat("operator ", name);
                }
                else {
                    name = methodBase.Name;
                    if (name.StartsWith("op_"))
                        name = name.Substring(3);
                }
            }
            else {
                name = methodBase.Name;
                var genericParameters = methodBase.GetGenericArguments();
                if (genericParameters.Length > 0) {
                    var tickIndex = name.LastIndexOf('`');
                    if (tickIndex >= 0)
                        name = name.Substring(0, tickIndex);
                    name = String.Concat(
                        name,
                        '<',
                        String.Join(ListSeparator, genericParameters.Select(GetDisplayName)),
                        '>');
                }
            }

            var parameters = methodBase.GetParameters();
            Contract.Assume(parameters != null);
            name = String.Concat(name, '(', GetParameterText(parameters), ')');

            if (ShowTypeNameForMembers) {
                Contract.Assume(null != methodBase.DeclaringType);
                name = String.Concat(GetDisplayName(methodBase.DeclaringType), '.', name);
            }

            return name;
        }
开发者ID:aarondandy,项目名称:ducky-docs,代码行数:56,代码来源:StandardReflectionDisplayNameGenerator.cs


注:本文中的System.Reflection.MethodBase.IsOperatorOverload方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。