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


C# Type.GetMethod方法代码示例

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


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

示例1: TryCreate

        public static ParseableSerializer TryCreate(Type type, TypeModel model)
        {
            if (type == null) throw new ArgumentNullException("type");
#if WINRT || PORTABLE || COREFX
            MethodInfo method = null;
            
#if WINRT || COREFX
            foreach (MethodInfo tmp in type.GetTypeInfo().GetDeclaredMethods("Parse"))
#else
            foreach (MethodInfo tmp in type.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly))
#endif
            {
                ParameterInfo[] p;
                if (tmp.Name == "Parse" && tmp.IsPublic && tmp.IsStatic && tmp.DeclaringType == type && (p = tmp.GetParameters()) != null && p.Length == 1 && p[0].ParameterType == typeof(string))
                {
                    method = tmp;
                    break;
                }
            }
#else
            MethodInfo method = type.GetMethod("Parse",
                BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly,
                null, new Type[] { model.MapType(typeof(string)) }, null);
#endif
            if (method != null && method.ReturnType == type)
            {
                if (Helpers.IsValueType(type))
                {
                    MethodInfo toString = GetCustomToString(type);
                    if (toString == null || toString.ReturnType != model.MapType(typeof(string))) return null; // need custom ToString, fools
                }
                return new ParseableSerializer(method);
            }
            return null;
        }
开发者ID:GeorchW,项目名称:protobuf-net,代码行数:35,代码来源:ParseableSerializer.cs

示例2: GetCustomToString

        private static MethodInfo GetCustomToString(Type type)
        {
#if WINRT
            foreach (MethodInfo method in type.GetTypeInfo().GetDeclaredMethods("ToString"))
            {
                if (method.IsPublic && !method.IsStatic && method.GetParameters().Length == 0) return method;
            }
            return null;
#elif PORTABLE || COREFX
            MethodInfo method = Helpers.GetInstanceMethod(type, "ToString", Helpers.EmptyTypes);
            if (method == null || !method.IsPublic || method.IsStatic || method.DeclaringType != type) return null;
            return method;
#else

            return type.GetMethod("ToString", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
                        null, Helpers.EmptyTypes, null);
#endif
        }
开发者ID:GeorchW,项目名称:protobuf-net,代码行数:18,代码来源:ParseableSerializer.cs

示例3: ReadNullCheckedTail

        internal void ReadNullCheckedTail(Type type, IProtoSerializer tail, Compiler.Local valueFrom)
        {
            #if !FX11
            Type underlyingType;

            if (type.IsValueType && (underlyingType = Helpers.GetUnderlyingType(type)) != null)
            {
                if(tail.RequiresOldValue)
                {
                    // we expect the input value to be in valueFrom; need to unpack it from T?
                    using (Local loc = GetLocalWithValue(type, valueFrom))
                    {
                        LoadAddress(loc, type);
                        EmitCall(type.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
                    }
                }
                else
                {
                    Helpers.DebugAssert(valueFrom == null); // not expecting a valueFrom in this case
                }
                tail.EmitRead(this, null); // either unwrapped on the stack or not provided
                if (tail.ReturnsValue)
                {
                    // now re-wrap the value
                    EmitCtor(type, underlyingType);
                }
                return;
            }
            #endif
            // either a ref-type of a non-nullable struct; treat "as is", even if null
            // (the type-serializer will handle the null case; it needs to allow null
            // inputs to perform the correct type of subclass creation)
            tail.EmitRead(this, valueFrom);
        }
开发者ID:banksyhf,项目名称:Auxilium-2,代码行数:34,代码来源:CompilerContext.cs

示例4: EmitWrite

 internal void EmitWrite(Type helperType, string methodName, Compiler.Local valueFrom)
 {
     if (Helpers.IsNullOrEmpty(methodName)) throw new ArgumentNullException("methodName");
     MethodInfo method = helperType.GetMethod(
         methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
     if (method == null || method.ReturnType != MapType(typeof(void))) throw new ArgumentException("methodName");
     LoadValue(valueFrom);
     LoadReaderWriter();
     EmitCall(method);
 }
开发者ID:banksyhf,项目名称:Auxilium-2,代码行数:10,代码来源:CompilerContext.cs

示例5: EmitBasicRead

 internal void EmitBasicRead(Type helperType, string methodName, Type expectedType)
 {
     MethodInfo method = helperType.GetMethod(
         methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
     if (method == null || method.ReturnType != expectedType
         || method.GetParameters().Length != 1) throw new ArgumentException("methodName");
     LoadReaderWriter();
     EmitCall(method);
 }
开发者ID:banksyhf,项目名称:Auxilium-2,代码行数:9,代码来源:CompilerContext.cs

示例6: WriteNullCheckedTail

 internal void WriteNullCheckedTail(Type type, IProtoSerializer tail, Compiler.Local valueFrom)
 {
     if (type.IsValueType)
     {
         Type underlyingType = null;
     #if !FX11
         underlyingType = Helpers.GetUnderlyingType(type);
     #endif
         if (underlyingType == null)
         { // not a nullable T; can invoke directly
             tail.EmitWrite(this, valueFrom);
         }
         else
         { // nullable T; check HasValue
             using (Compiler.Local valOrNull = GetLocalWithValue(type, valueFrom))
             {
                 LoadAddress(valOrNull, type);
                 LoadValue(type.GetProperty("HasValue"));
                 CodeLabel @end = DefineLabel();
                 BranchIfFalse(@end, false);
                 LoadAddress(valOrNull, type);
                 EmitCall(type.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
                 tail.EmitWrite(this, null);
                 MarkLabel(@end);
             }
         }
     }
     else
     { // ref-type; do a null-check
         LoadValue(valueFrom);
         CopyValue();
         CodeLabel hasVal = DefineLabel(), @end = DefineLabel();
         BranchIfTrue(hasVal, true);
         DiscardValue();
         Branch(@end, false);
         MarkLabel(hasVal);
         tail.EmitWrite(this, null);
         MarkLabel(@end);
     }
 }
开发者ID:banksyhf,项目名称:Auxilium-2,代码行数:40,代码来源:CompilerContext.cs

示例7: WriteGetKeyImpl

        private void WriteGetKeyImpl(TypeBuilder type, bool hasInheritance, SerializerPair[] methodPairs, Compiler.CompilerContext.ILVersion ilVersion, string assemblyName, out ILGenerator il, out int knownTypesCategory, out FieldBuilder knownTypes, out Type knownTypesLookupType)
        {

            il = Override(type, "GetKeyImpl");
            Compiler.CompilerContext ctx = new Compiler.CompilerContext(il, false, false, methodPairs, this, ilVersion, assemblyName, MapType(typeof(System.Type), true));
            
            if (types.Count <= KnownTypes_ArrayCutoff)
            {
                knownTypesCategory = KnownTypes_Array;
                knownTypesLookupType = MapType(typeof(System.Type[]), true);
            }
            else
            {
#if NO_GENERICS
                knownTypesLookupType = null;
#else
                knownTypesLookupType = MapType(typeof(System.Collections.Generic.Dictionary<System.Type, int>), false);
#endif
                if (knownTypesLookupType == null)
                {
                    knownTypesLookupType = MapType(typeof(Hashtable), true);
                    knownTypesCategory = KnownTypes_Hashtable;
                }
                else
                {
                    knownTypesCategory = KnownTypes_Dictionary;
                }
            }
            knownTypes = type.DefineField("knownTypes", knownTypesLookupType, FieldAttributes.Private | FieldAttributes.InitOnly | FieldAttributes.Static);

            switch (knownTypesCategory)
            {
                case KnownTypes_Array:
                    {
                        il.Emit(OpCodes.Ldsfld, knownTypes);
                        il.Emit(OpCodes.Ldarg_1);
                        // note that Array.IndexOf is not supported under CF
                        il.EmitCall(OpCodes.Callvirt, MapType(typeof(IList)).GetMethod(
                            "IndexOf", new Type[] { MapType(typeof(object)) }), null);
                        if (hasInheritance)
                        {
                            il.DeclareLocal(MapType(typeof(int))); // loc-0
                            il.Emit(OpCodes.Dup);
                            il.Emit(OpCodes.Stloc_0);

                            BasicList getKeyLabels = new BasicList();
                            int lastKey = -1;
                            for (int i = 0; i < methodPairs.Length; i++)
                            {
                                if (methodPairs[i].MetaKey == methodPairs[i].BaseKey) break;
                                if (lastKey == methodPairs[i].BaseKey)
                                {   // add the last label again
                                    getKeyLabels.Add(getKeyLabels[getKeyLabels.Count - 1]);
                                }
                                else
                                {   // add a new unique label
                                    getKeyLabels.Add(ctx.DefineLabel());
                                    lastKey = methodPairs[i].BaseKey;
                                }
                            }
                            Compiler.CodeLabel[] subtypeLabels = new Compiler.CodeLabel[getKeyLabels.Count];
                            getKeyLabels.CopyTo(subtypeLabels, 0);

                            ctx.Switch(subtypeLabels);
                            il.Emit(OpCodes.Ldloc_0); // not a sub-type; use the original value
                            il.Emit(OpCodes.Ret);

                            lastKey = -1;
                            // now output the different branches per sub-type (not derived type)
                            for (int i = subtypeLabels.Length - 1; i >= 0; i--)
                            {
                                if (lastKey != methodPairs[i].BaseKey)
                                {
                                    lastKey = methodPairs[i].BaseKey;
                                    // find the actual base-index for this base-key (i.e. the index of
                                    // the base-type)
                                    int keyIndex = -1;
                                    for (int j = subtypeLabels.Length; j < methodPairs.Length; j++)
                                    {
                                        if (methodPairs[j].BaseKey == lastKey && methodPairs[j].MetaKey == lastKey)
                                        {
                                            keyIndex = j;
                                            break;
                                        }
                                    }
                                    ctx.MarkLabel(subtypeLabels[i]);
                                    Compiler.CompilerContext.LoadValue(il, keyIndex);
                                    il.Emit(OpCodes.Ret);
                                }
                            }
                        }
                        else
                        {
                            il.Emit(OpCodes.Ret);
                        }
                    }
                    break;
                case KnownTypes_Dictionary:
                    {
                        LocalBuilder result = il.DeclareLocal(MapType(typeof(int)));
//.........这里部分代码省略.........
开发者ID:SimonPStevens,项目名称:protobuf-net,代码行数:101,代码来源:RuntimeTypeModel.cs

示例8: WriteConstructors

 private void WriteConstructors(TypeBuilder type, ref int index, SerializerPair[] methodPairs, ref ILGenerator il, int knownTypesCategory, FieldBuilder knownTypes, Type knownTypesLookupType, Compiler.CompilerContext ctx)
 {
     type.DefineDefaultConstructor(MethodAttributes.Public);
     il = type.DefineTypeInitializer().GetILGenerator();
     switch (knownTypesCategory)
     {
         case KnownTypes_Array:
             {
                 Compiler.CompilerContext.LoadValue(il, types.Count);
                 il.Emit(OpCodes.Newarr, ctx.MapType(typeof(System.Type)));
                 index = 0;
                 foreach (SerializerPair pair in methodPairs)
                 {
                     il.Emit(OpCodes.Dup);
                     Compiler.CompilerContext.LoadValue(il, index);
                     il.Emit(OpCodes.Ldtoken, pair.Type.Type);
                     il.EmitCall(OpCodes.Call, ctx.MapType(typeof(System.Type)).GetMethod("GetTypeFromHandle"), null);
                     il.Emit(OpCodes.Stelem_Ref);
                     index++;
                 }
                 il.Emit(OpCodes.Stsfld, knownTypes);
                 il.Emit(OpCodes.Ret);
             }
             break;
         case KnownTypes_Dictionary:
             {
                 Compiler.CompilerContext.LoadValue(il, types.Count);
                 //LocalBuilder loc = il.DeclareLocal(knownTypesLookupType);
                 il.Emit(OpCodes.Newobj, knownTypesLookupType.GetConstructor(new Type[] { MapType(typeof(int)) }));
                 il.Emit(OpCodes.Stsfld, knownTypes);
                 int typeIndex = 0;
                 foreach (SerializerPair pair in methodPairs)
                 {
                     il.Emit(OpCodes.Ldsfld, knownTypes);
                     il.Emit(OpCodes.Ldtoken, pair.Type.Type);
                     il.EmitCall(OpCodes.Call, ctx.MapType(typeof(System.Type)).GetMethod("GetTypeFromHandle"), null);
                     int keyIndex = typeIndex++, lastKey = pair.BaseKey;
                     if (lastKey != pair.MetaKey) // not a base-type; need to give the index of the base-type
                     {
                         keyIndex = -1; // assume epic fail
                         for (int j = 0; j < methodPairs.Length; j++)
                         {
                             if (methodPairs[j].BaseKey == lastKey && methodPairs[j].MetaKey == lastKey)
                             {
                                 keyIndex = j;
                                 break;
                             }
                         }
                     }
                     Compiler.CompilerContext.LoadValue(il, keyIndex);
                     il.EmitCall(OpCodes.Callvirt, knownTypesLookupType.GetMethod("Add", new Type[] { MapType(typeof(System.Type)), MapType(typeof(int)) }), null);
                 }
                 il.Emit(OpCodes.Ret);
             }
             break;
         case KnownTypes_Hashtable:
             {
                 Compiler.CompilerContext.LoadValue(il, types.Count);
                 il.Emit(OpCodes.Newobj, knownTypesLookupType.GetConstructor(new Type[] { MapType(typeof(int)) }));
                 il.Emit(OpCodes.Stsfld, knownTypes);
                 int typeIndex = 0;
                 foreach (SerializerPair pair in methodPairs)
                 {
                     il.Emit(OpCodes.Ldsfld, knownTypes);
                     il.Emit(OpCodes.Ldtoken, pair.Type.Type);
                     il.EmitCall(OpCodes.Call, ctx.MapType(typeof(System.Type)).GetMethod("GetTypeFromHandle"), null);
                     int keyIndex = typeIndex++, lastKey = pair.BaseKey;
                     if (lastKey != pair.MetaKey) // not a base-type; need to give the index of the base-type
                     {
                         keyIndex = -1; // assume epic fail
                         for (int j = 0; j < methodPairs.Length; j++)
                         {
                             if (methodPairs[j].BaseKey == lastKey && methodPairs[j].MetaKey == lastKey)
                             {
                                 keyIndex = j;
                                 break;
                             }
                         }
                     }
                     Compiler.CompilerContext.LoadValue(il, keyIndex);
                     il.Emit(OpCodes.Box, MapType(typeof(int)));
                     il.EmitCall(OpCodes.Callvirt, knownTypesLookupType.GetMethod("Add", new Type[] { MapType(typeof(object)), MapType(typeof(object)) }), null);
                 }
                 il.Emit(OpCodes.Ret);
             }
             break;
         default:
             throw new InvalidOperationException();
     }
 }
开发者ID:SimonPStevens,项目名称:protobuf-net,代码行数:90,代码来源:RuntimeTypeModel.cs

示例9: GetInstanceMethod

        internal static MethodInfo GetInstanceMethod(Type declaringType, string name, Type[] types)
        {
            if(types == null) types = EmptyTypes;
#if PORTABLE
            MethodInfo method = declaringType.GetMethod(name, types);
            if (method != null && method.IsStatic) method = null;
            return method;
#else
            return declaringType.GetMethod(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                null, types, null);
#endif
        }
开发者ID:CragonGame,项目名称:GameCloud.IM,代码行数:12,代码来源:Helpers.cs

示例10: GetStaticMethod

 internal static MethodInfo GetStaticMethod(Type declaringType, string name)
 {
     return declaringType.GetMethod(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
 }
开发者ID:CragonGame,项目名称:GameCloud.IM,代码行数:4,代码来源:Helpers.cs

示例11: EmitBeq

        private void EmitBeq(Compiler.CompilerContext ctx, Compiler.CodeLabel label, Type type)
        {
            switch (Helpers.GetTypeCode(type))
            {
                case ProtoTypeCode.Boolean:
                case ProtoTypeCode.Byte:
                case ProtoTypeCode.Char:
                case ProtoTypeCode.Double:
                case ProtoTypeCode.Int16:
                case ProtoTypeCode.Int32:
                case ProtoTypeCode.Int64:
                case ProtoTypeCode.SByte:
                case ProtoTypeCode.Single:
                case ProtoTypeCode.UInt16:
                case ProtoTypeCode.UInt32:
                case ProtoTypeCode.UInt64:
                    ctx.BranchIfEqual(label, false);
                    break;

                default:
                    MethodInfo method = type.GetMethod("op_Equality", BindingFlags.Public | BindingFlags.Static,
                        null, new Type[] { type, type}, null);
                    if (method == null || method.ReturnType != ctx.MapType(typeof(bool)))
                    {
                        throw new InvalidOperationException("No suitable equality operator found for default-values of type: " + type.FullName);
                    }
                    ctx.EmitCall(method);
                    ctx.BranchIfTrue(label, false);
                    break;
            }
        }
开发者ID:banksyhf,项目名称:Auxilium-2,代码行数:31,代码来源:DefaultValueDecorator.cs

示例12: DelegateInnerClassTypeWrapper

			internal DelegateInnerClassTypeWrapper(string name, Type delegateType)
				: base(Modifiers.Public | Modifiers.Interface | Modifiers.Abstract, name, null)
			{
#if STATIC_COMPILER || STUB_GENERATOR
				this.fakeType = FakeTypes.GetDelegateType(delegateType);
#elif !FIRST_PASS
				this.fakeType = typeof([email protected]<>).MakeGenericType(delegateType);
#endif
				MethodInfo invoke = delegateType.GetMethod("Invoke");
				ParameterInfo[] parameters = invoke.GetParameters();
				TypeWrapper[] argTypeWrappers = new TypeWrapper[parameters.Length];
				System.Text.StringBuilder sb = new System.Text.StringBuilder("(");
				MemberFlags flags = MemberFlags.None;
				for (int i = 0; i < parameters.Length; i++)
				{
					Type parameterType = parameters[i].ParameterType;
					if (parameterType.IsByRef)
					{
						flags |= MemberFlags.DelegateInvokeWithByRefParameter;
						parameterType = ArrayTypeWrapper.MakeArrayType(parameterType.GetElementType(), 1);
					}
					argTypeWrappers[i] = ClassLoaderWrapper.GetWrapperFromType(parameterType);
					sb.Append(argTypeWrappers[i].SigName);
				}
				TypeWrapper returnType = ClassLoaderWrapper.GetWrapperFromType(invoke.ReturnType);
				sb.Append(")").Append(returnType.SigName);
				MethodWrapper invokeMethod = new DynamicOnlyMethodWrapper(this, "Invoke", sb.ToString(), returnType, argTypeWrappers, flags);
				SetMethods(new MethodWrapper[] { invokeMethod });
				SetFields(FieldWrapper.EmptyArray);
			}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:30,代码来源:DotNetTypeWrapper.cs

示例13: IsDelegate

		private static bool IsDelegate(Type type)
		{
			// HACK non-public delegates do not get the special treatment (because they are likely to refer to
			// non-public types in the arg list and they're not really useful anyway)
			// NOTE we don't have to check in what assembly the type lives, because this is a DotNetTypeWrapper,
			// we know that it is a different assembly.
			if (!type.IsAbstract && type.IsSubclassOf(Types.MulticastDelegate) && type.IsVisible)
			{
				MethodInfo invoke = type.GetMethod("Invoke");
				if (invoke != null)
				{
					foreach (ParameterInfo p in invoke.GetParameters())
					{
						// we don't support delegates with pointer parameters
						if (IsPointerType(p.ParameterType))
						{
							return false;
						}
					}
					return !IsPointerType(invoke.ReturnType);
				}
			}
			return false;
		}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:24,代码来源:DotNetTypeWrapper.cs

示例14: GetDelegateInvokeStubName

		internal static string GetDelegateInvokeStubName(Type delegateType)
		{
			MethodInfo delegateInvoke = delegateType.GetMethod("Invoke");
			ParameterInfo[] parameters = delegateInvoke.GetParameters();
			string name = null;
			for (int i = 0; i < parameters.Length; i++)
			{
				if (parameters[i].ParameterType.IsByRef)
				{
					name = (name ?? "<Invoke>") + "_" + i;
				}
			}
			return name ?? "Invoke";
		}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:14,代码来源:DotNetTypeWrapper.cs

示例15: GetStaticMethod

 internal static MethodInfo GetStaticMethod(Type declaringType, string name, Type[] parameterTypes)
 {
    return declaringType.GetMethod(name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, parameterTypes, null);
 }
开发者ID:GeorchW,项目名称:protobuf-net,代码行数:4,代码来源:Helpers.cs


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