本文整理汇总了C#中System.Reflection类的典型用法代码示例。如果您正苦于以下问题:C# Reflection类的具体用法?C# Reflection怎么用?C# Reflection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Reflection类属于System命名空间,在下文中一共展示了Reflection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetQueryHandlersParameter
private static ResolvedParameter GetQueryHandlersParameter(Reflection.Assembly queryHandlersAssembly)
{
return new ResolvedParameter(
(p, c) =>
{
var parameterType = p.ParameterType.GetGenericArguments().FirstOrDefault();
return parameterType != null &&
parameterType.GetGenericTypeDefinition() == typeof (IQueryHandler<>);
},
(p, c) =>
{
var queryHandlerList = new ArrayList();
var queryHandlerType = p.ParameterType.GetGenericArguments().First();
var queryHandlerEntityType = queryHandlerType.GetGenericArguments().First();
foreach (var queryHandler in GetQueryHandlers(queryHandlersAssembly))
{
var specificQueryHandler = queryHandler.MakeGenericType(queryHandlerEntityType);
queryHandlerList.Add(c.Resolve(specificQueryHandler));
}
return queryHandlerList.ToArray(queryHandlerType);
});
}
示例2: GetQueryHandlers
private static IEnumerable<Type> GetQueryHandlers(Reflection.Assembly assembly)
{
return from t in assembly.GetTypes()
from i in t.GetInterfaces()
where i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IQueryHandler<>)
select t;
}
示例3: GetNativePointerSize
private static int GetNativePointerSize(SysReflection.MethodInfo xMethodInfo)
{
// old code, which goof up everything for structs
//return (int)Align(SizeOfType(xMethodInfo.DeclaringType), 4);
// TODO native pointer size, so that COSMOS could be 64 bit OS
return 4;
}
示例4: ReflectionAssemblyReference
public ReflectionAssemblyReference(MetadataHost host, SR.Assembly assembly)
: base(host)
{
mAssembly = assembly;
FullName = mAssembly.FullName;
Name = mAssembly.GetName().Name;
Location = mAssembly.Location;
}
示例5: Exists
public static bool Exists(REF.Assembly ass, string path, string name)
{
try { using(Stream s = Open(ass, path, name)) {} }
catch (FileNotFoundException) { return false; }
return true;
}
示例6: FindMatchingMethod
public static MethodDefinition FindMatchingMethod(this TypeDefinition tdef, SR.MethodBase minf, bool throwOnNotFound = false)
{
if (throwOnNotFound)
return tdef.Methods.First(mdef => mdef.MethodMatches(minf));
else
return tdef.Methods.FirstOrDefault(mdef => mdef.MethodMatches(minf));
}
示例7: MethodInfo
public MethodInfo(bcl.MethodBase method)
{
Namespace = method.Name;
DeclaringType = method.DeclaringType.Name;
Name = GetName(method);
Signature = Name + " (" + GetArguments(method) + ")";
}
示例8: Map_boolean_switch_creates_boolean_value
public void Map_boolean_switch_creates_boolean_value()
{
// Fixture setup
var tokenPartitions = new[]
{
new KeyValuePair<string, IEnumerable<string>>("x", new [] { "true" })
};
var specProps = new[]
{
SpecificationProperty.Create(
new OptionSpecification("x", string.Empty, false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '\0', Maybe.Nothing<object>(), string.Empty, string.Empty, new List<string>(), typeof(bool), TargetType.Switch),
typeof(Simple_Options).GetProperties().Single(p => p.Name.Equals("BoolValue", StringComparison.Ordinal)),
Maybe.Nothing<object>())
};
// Exercize system
var result = OptionMapper.MapValues(
specProps.Where(pt => pt.Specification.IsOption()),
tokenPartitions,
(vals, type, isScalar) => TypeConverter.ChangeType(vals, type, isScalar, CultureInfo.InvariantCulture, false),
StringComparer.Ordinal
);
// Verify outcome
Assert.NotNull(((Ok<IEnumerable<SpecificationProperty>, Error>)result).Success.Single(
a => a.Specification.IsOption()
&& ((OptionSpecification)a.Specification).ShortName.Equals("x")
&& (bool)((Just<object>)a.Value).Value));
// Teardown
}
示例9: FindMatchingField
public static FieldDefinition FindMatchingField(this TypeDefinition tdef, SR.FieldInfo finf, bool throwOnNotFound = false)
{
if (throwOnNotFound)
return tdef.Fields.First(fdef => fdef.FieldMatches(finf));
else
return tdef.Fields.FirstOrDefault(fdef => fdef.FieldMatches(finf));
}
示例10: DecompilationTestCase
public DecompilationTestCase(SR.MethodInfo method, TestCaseType type, string filename, string resultFilename) : base(method)
{
this.TestName.Name = method.DeclaringType.FullName + "." + method.Name + "." + type.ToString();
this.TestName.FullName = this.TestName.Name;
this.resultFilename=resultFilename;
this.type = type;
}
示例11: Open
/// <summary>
/// Open a manifest file from <paramref name="ass"/>
/// </summary>
/// <param name="ass">Assembly to get the manifest file from</param>
/// <param name="path">Type path to the file</param>
/// <param name="name">File name (with extension)</param>
/// <returns>Manifest file's stream</returns>
/// <exception cref="Debug.ExceptionLog">When a <see cref="System.IO.FileNotFoundException"/> is encountered, it is caught and rethrown as a this type of exception</exception>
public static Stream Open(REF.Assembly ass, string path, string name)
{
string manifest_path = string.Format("{0}{1}{2}", BasePath, path.Replace('\\', '.'), name);
Stream s = null;
try { s = ass.GetManifestResourceStream(manifest_path); }
catch (FileNotFoundException) { throw new Debug.ExceptionLog("Manifest not found! {0}+{1}", ass.FullName, manifest_path); }
return s;
}
示例12: GetAssemblyNameReference
AssemblyNameReference GetAssemblyNameReference (SR.AssemblyName name)
{
foreach (AssemblyNameReference reference in m_module.AssemblyReferences)
if (reference.FullName == name.FullName)
return reference;
return null;
}
示例13: GetArgument
string GetArgument(bcl.ParameterInfo arg)
{
if (arg.ParameterType.IsGenericParameter)
{
}
return TypeUtils.ToFriendlyName(arg.ParameterType) + " " + arg.Name;
}
示例14: TestImport
static FieldReference TestImport (SR.FieldInfo field)
{
AssemblyDefinition assembly = GetAssembly();
FieldReference reference = assembly.MainModule.Import (field);
assembly.MainModule.Import (field);
CheckForDuplicates (assembly);
return reference;
}
示例15: GetName
string GetName(bcl.MethodBase method)
{
if (method.IsGenericMethod)
{
var genericArgs = method.GetGenericArguments();
return method.Name + "<" + string.Join(", ", genericArgs.Select(TypeUtils.ToFriendlyName)) + ">";
}
return method.Name;
}