本文整理汇总了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}";
}
示例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;
}