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


C# Reflection.GetType方法代码示例

本文整理汇总了C#中System.Reflection.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Reflection.GetType方法的具体用法?C# Reflection.GetType怎么用?C# Reflection.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection的用法示例。


在下文中一共展示了Reflection.GetType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImportGenericInstanceMethod

		MethodReference ImportGenericInstanceMethod (SR.MethodInfo mi, ImportContext context)
		{
			SR.MethodInfo gmd = (SR.MethodInfo) mi.GetType ().GetMethod ("GetGenericMethodDefinition").Invoke (mi, null);
			GenericInstanceMethod gim = new GenericInstanceMethod (
				ImportMethodBase (gmd, gmd.ReturnType, context));

			foreach (Type genArg in GetGenericArguments (mi))
				gim.GenericArguments.Add (ImportSystemType (genArg, context));

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

示例2: GetMetadataToken

		static int GetMetadataToken (SR.MethodInfo mi)
		{
			return (int) mi.GetType ().GetProperty ("MetadataToken").GetValue (mi, null);
		}
开发者ID:nobled,项目名称:mono,代码行数:4,代码来源:ReflectionHelper.cs

示例3: GetInjectees

        private InjecteeCollection GetInjectees(SR.Assembly targetAssembly, SR.Assembly injectionAssembly)
        {
            _classInjectees = new List<TypeInjecteeBase>();

            var injectees = new InjecteeCollection();

            var injectionAssemblyTypes = injectionAssembly.GetTypes();
            foreach (var injectionType in injectionAssemblyTypes)
            {
                var classAttrs = injectionType.GetCustomAttributes(typeof(InjectionAttributeBase), false);
                if (classAttrs.Count(a => a != null) >= 2)
                    throw new InvalidOperationException("Can not define multiple class attributes for the same class");

                var classAttr = classAttrs.Select(a => a as ITypeAttribute).FirstOrDefault(a => a != null);
                if (classAttr == null)
                    continue;

                if (classAttr is TypeAddInjectionAttribute)
                {
                    var classAddInjectee = (TypeAddInjectee)classAttr.GetInjectee(null, injectionType);

                    if (!String.IsNullOrEmpty(classAddInjectee.Attr.ParentFullName))
                        classAddInjectee.ParentType = targetAssembly.GetType(classAddInjectee.Attr.ParentFullName, true);

                    injectees.Add(classAddInjectee);
                    _classInjectees.Add(classAddInjectee);
                }
                else
                {
                    var name = !String.IsNullOrEmpty(classAttr.FullName) ? classAttr.FullName : injectionType.GetNormalizedName();
                    var targetType = targetAssembly.GetType(name, true);
                    var baseClassInjectee = classAttr.GetInjectee(targetType, injectionType);
                    injectees.Add(baseClassInjectee);
                    _classInjectees.Add(baseClassInjectee);
                }
            }

            foreach (var baseClassInjectee in _classInjectees)
            {
                var classInjectee = baseClassInjectee as TypeInjectee;
                if (classInjectee != null)
                {
                    foreach (var field in classInjectee.InjecteeType.GetFields(BINDING_FLAGS))
                    {
                        var fieldAttrs = field.GetCustomAttributes(typeof(InjectionAttributeBase), false);
                        if (fieldAttrs.Count(a => a != null) >= 2)
                            throw new InvalidOperationException("Can not define multiple field attributes for the same field");

                        var fieldAttr = fieldAttrs.Select(a => a as IFieldAttribute).FirstOrDefault(a => a != null);
                        if (fieldAttr == null)
                            continue;

                        var targetField = GetTargetField(fieldAttr, classInjectee.TargetType, field);
                        var fieldInjectee = fieldAttr.GetInjectee(targetField, field, classInjectee);
                        classInjectee.Injectees.Add(fieldInjectee);
                    }

                    foreach (var method in classInjectee.InjecteeType.GetMethods(BINDING_FLAGS))
                    {
                        var methodAttrs = method.GetCustomAttributes(typeof(InjectionAttributeBase), false);
                        if (methodAttrs.Count(a => a != null) >= 2)
                            throw new InvalidOperationException("Can not define multiple method attributes for the same method");

                        var methodAttr = methodAttrs.Select(a => a as IMethodAttribute).FirstOrDefault(a => a != null);
                        if (methodAttr == null)
                            continue;

                        var targetMethod = GetTargetMethod(methodAttr, classInjectee.TargetType, method);
                        var methodInjectee = methodAttr.GetInjectee(targetMethod, method, classInjectee);
                        classInjectee.Injectees.Add(methodInjectee);
                    }
                }
            }

            return injectees;
        }
开发者ID:MarkusSintonen,项目名称:MNetInjector,代码行数:76,代码来源:Injector.cs

示例4: GetGenericArguments

		static Type [] GetGenericArguments (SR.MethodInfo mi)
		{
			return (Type []) mi.GetType ().GetMethod ("GetGenericArguments").Invoke (mi, null);
		}
开发者ID:nobled,项目名称:mono,代码行数:4,代码来源:ReflectionHelper.cs

示例5: MapCustomAttributes

        private void MapCustomAttributes(SR.ICustomAttributeProvider provider, MC.ICustomAttributeProvider targetProvider)
        {
            var type = provider.GetType();

            // System.Reflection.Module.GetCustomAttributesData() not implemented in mono <= 3.4.0
            if (_is_running_mono && typeof(System.Reflection.Module).IsAssignableFrom(type)) return;

            var method = type.GetMethod("GetCustomAttributesData");
            if (method == null)
                throw new NotSupportedException("No method GetCustomAttributesData for type " + provider.GetType().FullName);

            var custom_attributes_data = (IList<CustomAttributeData>)method.Invoke(provider, new object[0]);

            foreach (var custom_attribute_data in custom_attributes_data)
            {
                var custom_attribute = new CustomAttribute(CreateReference(custom_attribute_data.Constructor, null));

                foreach (var argument in custom_attribute_data.ConstructorArguments)
                {
                    custom_attribute.ConstructorArguments.Add(CustomAttributeArgumentFor(argument));
                }

                foreach (var named_argument in custom_attribute_data.NamedArguments)
                {
                    var argument = new MC.CustomAttributeNamedArgument(named_argument.MemberInfo.Name, CustomAttributeArgumentFor(named_argument.TypedValue));
                    if (named_argument.MemberInfo is PropertyInfo)
                        custom_attribute.Properties.Add(argument);
                    else if (named_argument.MemberInfo is FieldInfo)
                        custom_attribute.Fields.Add(argument);
                    else
                        throw new NotSupportedException();
                }

                targetProvider.CustomAttributes.Add(custom_attribute);
            }
        }
开发者ID:Horusiath,项目名称:Vagabond,代码行数:36,代码来源:AssemblyParser.cs


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