當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。