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


C# System.Reflection类代码示例

本文整理汇总了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);
                    });
        }
开发者ID:elranu,项目名称:btr-dalc-prototype,代码行数:27,代码来源:RepositoryModule.cs

示例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;
 }
开发者ID:elranu,项目名称:btr-dalc-prototype,代码行数:7,代码来源:RepositoryModule.cs

示例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;
	}
开发者ID:nstone101,项目名称:Cosmos,代码行数:7,代码来源:Call.cs

示例4: ReflectionAssemblyReference

 public ReflectionAssemblyReference(MetadataHost host, SR.Assembly assembly)
     : base(host)
 {
     mAssembly = assembly;
     FullName = mAssembly.FullName;
     Name = mAssembly.GetName().Name;
     Location = mAssembly.Location;
 }
开发者ID:Sullux,项目名称:tws,代码行数:8,代码来源:ReflectionAssemblyReference.cs

示例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;
			}
开发者ID:CodeAsm,项目名称:open-sauce,代码行数:7,代码来源:Assembly.cs

示例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));
 }
开发者ID:MarkusSintonen,项目名称:MNetInjector,代码行数:7,代码来源:Extensions.cs

示例7: MethodInfo

 public MethodInfo(bcl.MethodBase method)
 {
     Namespace = method.Name;
     DeclaringType = method.DeclaringType.Name;
     Name = GetName(method);
     Signature = Name + " (" + GetArguments(method) + ")";
 }
开发者ID:niik,项目名称:RxSpy,代码行数:7,代码来源:MethodInfo.cs

示例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
        }
开发者ID:anthonylangsworth,项目名称:commandline,代码行数:31,代码来源:OptionMapperTests.cs

示例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));
 }
开发者ID:MarkusSintonen,项目名称:MNetInjector,代码行数:7,代码来源:Extensions.cs

示例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;
 }
开发者ID:pusp,项目名称:o2platform,代码行数:7,代码来源:DecompilationTestCase.cs

示例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;
			}
开发者ID:CodeAsm,项目名称:open-sauce,代码行数:16,代码来源:Assembly.cs

示例12: GetAssemblyNameReference

		AssemblyNameReference GetAssemblyNameReference (SR.AssemblyName name)
		{
			foreach (AssemblyNameReference reference in m_module.AssemblyReferences)
				if (reference.FullName == name.FullName)
					return reference;

			return null;
		}
开发者ID:nobled,项目名称:mono,代码行数:8,代码来源:ReflectionHelper.cs

示例13: GetArgument

        string GetArgument(bcl.ParameterInfo arg)
        {
            if (arg.ParameterType.IsGenericParameter)
            {
            }

            return TypeUtils.ToFriendlyName(arg.ParameterType) + " " + arg.Name;
        }
开发者ID:niik,项目名称:RxSpy,代码行数:8,代码来源:MethodInfo.cs

示例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;
		}
开发者ID:transformersprimeabcxyz,项目名称:cecil-old,代码行数:9,代码来源:ImportReflectionTestFixture.cs

示例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;
        }
开发者ID:niik,项目名称:RxSpy,代码行数:10,代码来源:MethodInfo.cs


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