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


C# TypeDefinition.GetMethods方法代码示例

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


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

示例1: GetMethodsFromType

 private static void GetMethodsFromType(List<MethodDefinition> ret, TypeDefinition type)
 {
     if (type.ContainsIgnoreAttribute()) return;
     foreach(var method in type.GetMethods())
     {
         if (method.ContainsIgnoreAttribute()) continue;
         ret.Add(method);
     }
     
     foreach(var nested in type.NestedTypes)
     {
         GetMethodsFromType(ret, nested);
     }
 }
开发者ID:jeroldhaas,项目名称:ContinuousTests,代码行数:14,代码来源:AssemblyDefinitionExtensions.cs

示例2: PreserveExportedMethods

		void PreserveExportedMethods (TypeDefinition type)
		{
			if (!type.HasMethods)
				return;

			foreach (var method in type.GetMethods ()) {
				if (!IsExportedMethod (method))
					continue;

				if (!IsOverridenInUserCode (method))
					continue;

				PreserveMethod (type, method);
			}
		}
开发者ID:Zman0169,项目名称:mono,代码行数:15,代码来源:MarkNSObjectsBase.cs

示例3: InjectEqualsInternal

        public static MethodReference InjectEqualsInternal(TypeDefinition type, TypeReference typeRef, MethodDefinition collectionEquals)
        {
            var methodAttributes = MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static;
            var method = new MethodDefinition("EqualsInternal", methodAttributes, ReferenceFinder.Boolean.TypeReference);
            method.CustomAttributes.MarkAsGeneratedCode();

            var left = method.Parameters.Add("left", typeRef);
            var right = method.Parameters.Add("right", typeRef);

            var body = method.Body;
            body.InitLocals = true;
            var ins = body.Instructions;

            var properties = type.GetPropertiesWithoutIgnores(ignoreAttributeName);

            foreach (var property in properties)
            {
                AddPropertyCode(type, collectionEquals, property, ins, left, right);
            }

            var methods = type.GetMethods();
            var customLogic = methods
                .Where(x => x.CustomAttributes.Any(y => y.AttributeType.Name == customAttribute)).ToArray();

            if (customLogic.Length > 2)
            {
                throw new WeavingException("Only one custom method can be specified.");
            }

            if (customLogic.Length == 1)
            {
                AddCustomLogicCall(type, body, ins, customLogic);
            }

            AddReturnTrue(ins);

            body.OptimizeMacros();

            type.Methods.AddOrReplace(method);

            var methodToCall = new MethodReference(method.Name, method.ReturnType, typeRef);
            foreach (var parameter in method.Parameters)
            {
                methodToCall.Parameters.Add(parameter);
            }

            return methodToCall;
        }
开发者ID:rjasica,项目名称:Equals,代码行数:48,代码来源:EqualsInjector.cs

示例4: OnBindMethodsDefinitions

        private void OnBindMethodsDefinitions(MonoAssemblyResolver assemblyTarget, TypeDefinition typeDefinition,
            TreeNode rootNode)
        {
            var methodDefinitions = typeDefinition.GetMethods(false);

            for (int i = 0; i < methodDefinitions.Count; i++)
            {
                var node = new TreeNode
                               {
                                   Text =
                                       string.Format("{0} ({1})", methodDefinitions[i].Name,
                                                     methodDefinitions[i].Parameters.Count),
                                   Tag = new BindItem { Method = methodDefinitions[i], Assembly = assemblyTarget }
                               };

                rootNode.Nodes.Add(node);
            }
        }
开发者ID:hermanocabral,项目名称:CodeInject,代码行数:18,代码来源:frmMain.cs

示例5: ProcessMethods

		void ProcessMethods (TypeDefinition type, List<ExportedMethod> exported)
		{
			foreach (MethodDefinition method in type.GetMethods ()) {
				CustomAttribute attribute;
				if (TryGetExportAttribute (method, out attribute)) {
					exported.Add (new ExportedMethod (attribute, method));
					continue;
				}

				if (!method.IsVirtual)
					continue;

				var bases = Annotations.GetBaseMethods (method);
				if (bases == null)
					continue;

				foreach (MethodDefinition @base in bases) {
					if (@base.DeclaringType.IsInterface)
						continue;

					if (TryGetExportAttribute (@base, out attribute)) {
						exported.Add (new ExportedMethod (attribute, method));
						break;
					}
				}
			}
		}
开发者ID:Zman0169,项目名称:mono,代码行数:27,代码来源:MethodMapInjection.cs

示例6: GenerateMethod

 protected string GenerateMethod(TypeDefinition type, string methodName, bool followDependencies)
 {
     var method = type.GetMethods(methodName).First();
     TextWriter writer = new StringWriter();
     var generator = new JsCodeGenerator(this.typeSystem, writer, false);
     var context = new TranslationContext(this.typeSystem, generator);
     var asmDependencies = new List<AssemblyDefinition>();
     context.GenerateMethod(method, followDependencies, asmDependencies);
     return writer.ToString();
 }
开发者ID:JimmyJune,项目名称:DotWeb,代码行数:10,代码来源:TranslationTestHelper.cs

示例7: IsAllStatic

		static bool IsAllStatic (TypeDefinition type)
		{
			if (type == null)
				return false;

			if (type.HasMethods) {
				foreach (MethodDefinition ctor in type.GetConstructors ()) {
					// let's the default ctor pass (since it's always here for 1.x code)
					if (!ctor.IsStatic && ctor.HasParameters)
						return false;
				}

				foreach (MethodDefinition method in type.GetMethods ()) {
					if (!method.IsStatic)
						return false;
				}
			}

			if (type.HasFields) {
				foreach (FieldDefinition field in type.Fields) {
					if (!field.IsStatic)
						return false;
				}
			}

			if (type.BaseType.FullName == "System.Object")
				return true;

			return IsAllStatic (type.BaseType.Resolve ());
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:30,代码来源:AvoidConstructorsInStaticTypesRule.cs

示例8: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			if (type.IsEnum || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			CheckAbstractClassWithoutResponsability (type);
			if (avoidUnusedParameters != null) {
				foreach (MethodDefinition method in type.GetMethods ()) {
					avoidUnusedParameters.CheckMethod (method);
				}
			}

			CheckUnnecesaryDelegation (type);
			return Runner.CurrentRuleResult;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:15,代码来源:AvoidSpeculativeGeneralityRule.cs

示例9: MostlyMethodsDelegatesCall

		private static bool MostlyMethodsDelegatesCall (TypeDefinition type)
		{
			if (!type.HasMethods)
				return false; // 0 / 2 + 1 <= 0

			int delegationCounter = 0;
			IList<MethodDefinition> methods = type.GetMethods ().ToList ();
			foreach (MethodDefinition method in methods) {
				if (OnlyDelegatesCall (method))
					delegationCounter++;
			}

			return methods.Count / 2 + 1 <= delegationCounter;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:14,代码来源:AvoidSpeculativeGeneralityRule.cs

示例10: IsAllStatic

		static bool IsAllStatic (TypeDefinition type)
		{
			if (type.HasMethods) {
				foreach (MethodDefinition ctor in type.GetConstructors ()) {
					// let's the default ctor pass (since it's always here for 1.x code)
					if (!ctor.IsStatic && ctor.HasParameters)
						return false;
				}

				foreach (MethodDefinition method in type.GetMethods ()) {
					if (!method.IsStatic)
						return false;
				}
			}
			if (type.HasFields) {
				foreach (FieldDefinition field in type.Fields) {
					if (!field.IsStatic)
						return false;
				}
			}
			return true;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:22,代码来源:ConsiderUsingStaticTypeRule.cs

示例11: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			if (type.IsEnum || type.IsDelegate ())
				return RuleResult.DoesNotApply;

			if (GetMethodCount (type) == 0)
				return RuleResult.DoesNotApply;

			// we look for a Parse method defined in the type
			bool has_parse = false;
			foreach (MethodDefinition method in type.GetMethods ()) {
				if (MethodSignatures.Parse.Matches (method)) {
					// the type provides a "<type> <type>::Parse(string)" method
					has_parse = true;
					break;
				}
			}

			// if no Parse method is found; or
			// if a Parse method is found along with a TryParse method
			if (!has_parse || HasTryParseMethod (type))
				return RuleResult.Success;

			// otherwise we report a defect to add a TryParse alternative
			Runner.Report (type, Severity.Medium, Confidence.High);
			return RuleResult.Failure;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:27,代码来源:ProvideTryParseAlternativeRule.cs

示例12: AutoModifyMethod

        private void AutoModifyMethod(TypeDefinition targetType, MethodDefinition yourMethod,
			MemberActionAttribute memberAction)
        {
            Log_modifying_member("method", yourMethod);
            var bodySource = yourMethod;
            var insertAttribute = yourMethod.GetCustomAttribute<DuplicatesBodyAttribute>();
            if (insertAttribute != null) {
                //Note that the source type is resolved using yourMethod's module, which uses a different IMetadataResolver,
                //and thus will resolve the method from the target, unmodified assembly.

                var importSourceType = insertAttribute.SourceType != null
                    ? yourMethod.Module.Import((TypeReference) insertAttribute.SourceType)
                    : yourMethod.Module.Import(targetType);

                var importMethod = importSourceType.Resolve().GetMethods(insertAttribute.MethodName,
                    yourMethod.Parameters.Select(x => x.ParameterType)).SingleOrDefault();

                var others =
                    importSourceType.Resolve().Methods.Where(x => x.Name == insertAttribute.MethodName).ToArray();

                if (importMethod == null) {
                    throw Errors.Missing_member("method", yourMethod, insertAttribute.MethodName);
                }

                bodySource = importMethod;
            }
            var modifiesMemberAttr = memberAction as ModifiesMemberAttribute;
            var newMemberAttr = memberAction as NewMemberAttribute;
            ModificationScope scope;
            string targetMethodName;

            if (modifiesMemberAttr != null) {
                targetMethodName = modifiesMemberAttr.MemberName ?? yourMethod.Name;
                scope = modifiesMemberAttr.Scope;

            } else if (newMemberAttr != null) {
                targetMethodName = yourMethod.Name;
                scope = ModificationScope.All;
            } else {
                throw Errors.Unknown_action_attribute(memberAction);
            }
            var targetMethod =
                targetType.GetMethods(targetMethodName, yourMethod.Parameters.Select(x => x.ParameterType)).FirstOrDefault();

            if (targetMethod == null) {
                throw Errors.Missing_member("method", yourMethod, targetMethodName);
            }
            if (modifiesMemberAttr != null && targetMethod.IsAbstract && (scope & ModificationScope.Body) != 0) {
                throw Errors.Invalid_member("method", yourMethod, targetMethod.FullName,
                    "You cannot modify the body of an abstract method.");
            }

            ModifyMethod(targetMethod, yourMethod, scope & ~ModificationScope.Body, newMemberAttr != null);
            ModifyMethod(targetMethod, bodySource, ModificationScope.Body & scope, false);
        }
开发者ID:gitter-badger,项目名称:Patchwork,代码行数:55,代码来源:ModifyExisting.cs


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