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


C# ICustomAttributeProvider.ToString方法代码示例

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


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

示例1: Create

 public string Create(Type attrType, ICustomAttributeProvider provider)
 {
     if (attrType == null) throw new ArgumentNullException(nameof(attrType));
     if (provider == null) throw new ArgumentNullException(nameof(provider));
     string name;
     var mi = provider as MemberInfo;
     var t = mi as Type;
     var p = provider as ParameterInfo;
     var a = provider as Assembly;
     var m = provider as System.Reflection.Module;
     if (t != null)
     {
         name = t.FullName;
     }
     else if (p != null)
     {
         name = $"{(p.Member.DeclaringType ?? p.Member.ReflectedType)?.FullName}|{p.Member.Name}|{p.Name}";
     }
     else if (mi != null)
     {
         var decType = mi.DeclaringType ?? mi.ReflectedType;
         name = $"{decType?.FullName}|{mi}";
     }
     else if (a != null)
     {
         name = a.FullName;
     }
     else if (m != null)
     {
         name = m.FullyQualifiedName;
     }
     else
     {
         name = provider.ToString();
     }
     return $"{attrType.FullName}|{name}";
 }
开发者ID:riberk,项目名称:Rib.Common,代码行数:37,代码来源:AttributesReader.cs

示例2: AnalyzeCustomAttributes

        bool AnalyzeCustomAttributes(ICustomAttributeProvider ca)
        {
            if (!ca.HasCustomAttributes) return false;
            bool ret = false;
            foreach (var i in ca.CustomAttributes)
            {
                foreach (var arg in i.ConstructorArguments)
                    AnalyzeCustomAttributeArgs(arg);

                int idx = 0;
                foreach (var arg in i.Fields)
                {
                    FieldDefinition field;
                    if (i.AttributeType is TypeDefinition &&
                       (field = (i.AttributeType as TypeDefinition).Fields.SingleOrDefault(_ => _.Name == arg.Name)) != null)
                        ((field as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(
                            new CustomAttributeMemberReference(i, idx, true));

                    AnalyzeCustomAttributeArgs(arg.Argument);
                    idx++;
                }

                idx = 0;
                foreach (var arg in i.Properties)
                {
                    PropertyDefinition prop;
                    if (i.AttributeType is TypeDefinition &&
                       (prop = (i.AttributeType as TypeDefinition).Properties.SingleOrDefault(_ => _.Name == arg.Name)) != null)
                        ((prop as IAnnotationProvider).Annotations[RenRef] as List<IReference>).Add(
                            new CustomAttributeMemberReference(i, idx, false));

                    AnalyzeCustomAttributeArgs(arg.Argument);
                    idx++;
                }

                if (Database.ExcludeAttributes.Contains(i.AttributeType.FullName) && ca is IAnnotationProvider)
                {
                    (ca as IAnnotationProvider).Annotations[RenOk] = false;
                    Confuser.Database.AddEntry(DB_SRC, ca.ToString(), i.AttributeType.FullName + " => Not renamed");
                    ret = true;
                }
            }
            return ret;
        }
开发者ID:n017,项目名称:Confuser,代码行数:44,代码来源:NameAnalyzer.cs


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