本文整理汇总了C#中IAssembly.FindTypes方法的典型用法代码示例。如果您正苦于以下问题:C# IAssembly.FindTypes方法的具体用法?C# IAssembly.FindTypes怎么用?C# IAssembly.FindTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAssembly
的用法示例。
在下文中一共展示了IAssembly.FindTypes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckForNonPublicMethods
/// <summary>
/// Ensures that the proxy assembly contains no private, protected or internal methods. Those methods are dangerous in this context, since a call to a non-public method from a proxy one will compile (since both methods are in the same class), but then result in a runtime exception (since the method will be in a different class).
/// </summary>
/// <param name="proxy">The proxy assembly.</param>
/// <exception cref="ProxyMistakeException">The assembly contains non-public methods.</exception>
private void CheckForNonPublicMethods(IAssembly proxy)
{
var privateMethods = proxy
.FindTypes(MemberType.Static, typeof(ProxyOfAttribute))
.SelectMany(t => t.FindMethods(MemberType.Static).Select(m => new { FullName = t.FullName + ":" + m.Name, IsPublic = m.IsPublic }))
.Where(m => !m.IsPublic)
.Select(m => m.FullName)
.ToList();
switch (privateMethods.Count)
{
case 0:
break;
case 1:
throw new ProxyMistakeException(string.Format("The proxy assembly is not expected to contain private methods, since after the merge, they could be called from a tampered class. The following private method was found: {0}.", privateMethods.Single()));
default:
throw new ProxyMistakeException(string.Format("The proxy assembly is not expected to contain private methods, since after the merge, they could be called from a tampered class. The following private methods were found: {0}.", string.Join("; ", privateMethods)));
}
}
示例2: CheckForInstanceTypes
/// <summary>
/// Ensures that the proxy assembly contains no instance types. Instance types don't make much sense in a context of a proxy, and so indicate with high probability a typo.
/// </summary>
/// <param name="proxy">The proxy assembly.</param>
/// <exception cref="ProxyMistakeException">The assembly contains instance types.</exception>
private void CheckForInstanceTypes(IAssembly proxy)
{
Contract.Requires(proxy != null);
var instanceTypes = proxy.FindTypes(MemberType.Instance).Select(t => t.FullName).Except(new[] { "<Module>" }).ToList();
switch (instanceTypes.Count)
{
case 0:
break;
case 1:
throw new ProxyMistakeException(string.Format("The proxy assembly is not expected to contain instance types. The following instance type was found: {0}.", instanceTypes.Single()));
default:
throw new ProxyMistakeException(string.Format("The proxy assembly is not expected to contain instance types. The following instance types were found: {0}.", string.Join("; ", instanceTypes)));
}
}