本文整理汇总了C#中System.Reflection.ParameterInfo.GetSingleAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterInfo.GetSingleAttribute方法的具体用法?C# ParameterInfo.GetSingleAttribute怎么用?C# ParameterInfo.GetSingleAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.ParameterInfo
的用法示例。
在下文中一共展示了ParameterInfo.GetSingleAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindMatchingMember
private MemberInfo FindMatchingMember(
ParameterInfo par, BindingFlags flags, Mode mode)
{
var attr = par.GetSingleAttribute<CtorFieldMapToAttribute>();
bool isExact = attr != null;
var name = isExact ? attr.FieldOrPropertyName : par.Name;
IEnumerable<string> names;
var inclFields = (mode & Mode.Fields) != 0;
var inclProperties = (mode & Mode.Properties) != 0;
if (!isExact)
{
var nrmName = name;
if (inclFields)
{
if (nrmName.StartsWith("m_", StringComparison.OrdinalIgnoreCase))
nrmName = nrmName.Substring(2);
else if (nrmName.StartsWith("_", StringComparison.Ordinal))
nrmName = nrmName.Substring(1);
}
bool empty = nrmName.Length == 0;
if (!empty && char.IsUpper(nrmName, 0))
nrmName = char.ToLowerInvariant(nrmName[0]) + nrmName.Substring(1);
var nms = new List<string>();
if (inclFields)
{
nms.Add("_" + nrmName);
nms.Add("m_" + nrmName);
}
if (!empty)
{
nms.Add(nrmName);
nrmName = char.ToUpperInvariant(nrmName[0]) + nrmName.Substring(1);
nms.Add(nrmName);
if (inclFields)
{
nms.Add("_" + nrmName);
nms.Add("m_" + nrmName);
}
}
names = nms;
}
else
{
names = new[] {name};
}
MemberInfo result = null;
if (inclProperties)
foreach (var n in names)
FindMatchingMember(ref result, par, false, n, names, flags);
if (result != null)
return result;
if (inclFields)
foreach (var n in names)
FindMatchingMember(ref result, par, true, n, names, flags);
if (result != null)
return result;
throw new SerializerException(
"Constructor {0}.{1}(...{2} {3}...) does not map to {4} {5} {6}{7} with type {8}",
FieldType.FullName, FieldType.Name,
par.ParameterType, par.Name,
(flags & BindingFlags.NonPublic) != 0 ? "public and private" : "public",
inclProperties && inclFields ? "fields or properties" : (inclFields ? "fields" : "properties"),
isExact ? "" : "similar to ", name, par.ParameterType.ToDebugStr());
}