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


C# ITypeDefinition.GetMethods方法代码示例

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


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

示例1: CollectMembersToImplement

        public static List<IMember> CollectMembersToImplement(ITypeDefinition implementingType, IType abstractType)
        {
            //			var def = abstractType.GetDefinition();
            var toImplement = new List<IMember>();
            bool alreadyImplemented;

            // Stub out non-implemented events defined by @iface
            foreach (var ev in abstractType.GetEvents (e => !e.IsSynthetic && e.IsAbstract)) {
                alreadyImplemented = implementingType.GetAllBaseTypeDefinitions().Any(
                    x => x.Kind != TypeKind.Interface && x.Events.Any (y => y.Name == ev.Name)
                    );

                if (!alreadyImplemented)
                    toImplement.Add(ev);
            }

            // Stub out non-implemented methods defined by @iface
            foreach (var method in abstractType.GetMethods (d => !d.IsSynthetic  && d.IsAbstract)) {
                alreadyImplemented = false;

                var allBaseTypes = method.DeclaringType.GetAllBaseTypes().ToList ();
                foreach (var cmet in implementingType.GetMethods (d => !d.IsAbstract && d.Name == method.Name)) {
                    if (allBaseTypes.Contains(cmet.DeclaringType))
                        continue;
                    if (ImplementInterfaceAction.CompareMethods(method, cmet)) {
                        alreadyImplemented = true;
                        break;
                    }
                }
                if (!alreadyImplemented)
                    toImplement.Add(method);
            }

            // Stub out non-implemented properties defined by @iface
            foreach (var prop in abstractType.GetProperties (p => !p.IsSynthetic && p.IsAbstract)) {
                alreadyImplemented = false;
                foreach (var t in implementingType.GetAllBaseTypeDefinitions ()) {
                    if (t.Kind == TypeKind.Interface)
                        continue;
                    foreach (IProperty cprop in t.Properties) {
                        if (!cprop.IsAbstract && cprop.Name == prop.Name) {
                            alreadyImplemented = true;
                        }
                    }
                }
                if (!alreadyImplemented)
                    toImplement.Add(prop);
            }
            return toImplement;
        }
开发者ID:segaman,项目名称:NRefactory,代码行数:50,代码来源:ImplementAbstractMembersAction.cs

示例2: CollectMembersToImplement

		public static List<Tuple<IMember, bool>> CollectMembersToImplement(ITypeDefinition implementingType, IType interfaceType, bool explicitly)
		{
			var def = interfaceType.GetDefinition();
			List<Tuple<IMember, bool>> toImplement = new List<Tuple<IMember, bool>>();
			bool alreadyImplemented;
			// Stub out non-implemented events defined by @iface
			foreach (var ev in interfaceType.GetEvents (e => !e.IsSynthetic && e.DeclaringTypeDefinition.ReflectionName == def.ReflectionName)) {
				bool needsExplicitly = explicitly;
				alreadyImplemented = implementingType.GetAllBaseTypeDefinitions().Any(
					x => x.Kind != TypeKind.Interface && x.Events.Any (y => y.Name == ev.Name)
				);

				if (!alreadyImplemented)
					toImplement.Add(new Tuple<IMember, bool>(ev, needsExplicitly));
			}

			// Stub out non-implemented methods defined by @iface
			foreach (var method in interfaceType.GetMethods (d => !d.IsSynthetic && d.DeclaringTypeDefinition.ReflectionName == def.ReflectionName)) {
				bool needsExplicitly = explicitly;
				alreadyImplemented = false;
				
				foreach (var cmet in implementingType.GetMethods ()) {
					if (CompareMethods(method, cmet)) {
						if (!needsExplicitly && !cmet.ReturnType.Equals(method.ReturnType))
							needsExplicitly = true;
						else
							alreadyImplemented |= !needsExplicitly /*|| cmet.InterfaceImplementations.Any (impl => impl.InterfaceType.Equals (interfaceType))*/;
					}
				}
				if (!alreadyImplemented) 
					toImplement.Add(new Tuple<IMember, bool>(method, needsExplicitly));
			}

			// Stub out non-implemented properties defined by @iface
			foreach (var prop in interfaceType.GetProperties (p => !p.IsSynthetic && p.DeclaringTypeDefinition.ReflectionName == def.ReflectionName)) {
				bool needsExplicitly = explicitly;
				alreadyImplemented = false;
				foreach (var t in implementingType.GetAllBaseTypeDefinitions ()) {
					if (t.Kind == TypeKind.Interface)
						continue;
					foreach (IProperty cprop in t.Properties) {
						if (cprop.Name == prop.Name) {
							if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType))
								needsExplicitly = true;
							else
								alreadyImplemented |= !needsExplicitly/* || cprop.InterfaceImplementations.Any (impl => impl.InterfaceType.Resolve (ctx).Equals (interfaceType))*/;
						}
					}
				}
				if (!alreadyImplemented)
					toImplement.Add(new Tuple<IMember, bool>(prop, needsExplicitly));
			}
			return toImplement;
		}
开发者ID:nieve,项目名称:NRefactory,代码行数:54,代码来源:ImplementInterfaceAction.cs

示例3: GenerateCode

		protected override string GenerateCode(ITypeDefinition currentClass)
		{
			bool implementInterface = this.implementInterface.IsChecked == true;
			bool hasOnPropertyChanged = HasOnPropertyChanged(currentClass);
			bool useEventArgs = false;
			
			AstNode insertionAnchorElement = refactoringContext.GetNode();
			if ((insertionAnchorElement == null) || !(insertionAnchorElement.Parent is TypeDeclaration)) {
				return null;
			}
			NewLineNode newLineNode = insertionAnchorElement as NewLineNode;
			while (insertionAnchorElement.PrevSibling is NewLineNode)
				insertionAnchorElement = insertionAnchorElement.PrevSibling ?? insertionAnchorElement;
			
			using (Script script = refactoringContext.StartScript()) {
				TypeDeclaration currentClassDeclaration = insertionAnchorElement.Parent as TypeDeclaration;
				
				if (implementInterface && !currentClass.IsStatic) {
					if (!hasOnPropertyChanged) {
						var nodes = new List<AstNode>();
						if (!currentClass.GetAllBaseTypeDefinitions().Any(bt => bt.FullName == "System.ComponentModel.INotifyPropertyChanged")) {
							AstNode nodeBeforeClassBlock = currentClassDeclaration.LBraceToken;
							if (nodeBeforeClassBlock.PrevSibling is NewLineNode) {
								// There's a new line before the brace, insert before it!
								nodeBeforeClassBlock = nodeBeforeClassBlock.PrevSibling;
							}
							int insertion = editor.Document.GetOffset(nodeBeforeClassBlock.StartLocation);
							
							AstType interfaceTypeNode = refactoringContext.CreateShortType("System.ComponentModel", "INotifyPropertyChanged", 0);
							var directBaseTypes = currentClass.DirectBaseTypes.Where(t => t.FullName != "System.Object");
							if (currentClassDeclaration.BaseTypes.Count > 0) {
								script.InsertText(insertion, ", " + interfaceTypeNode + " ");
							} else {
								script.InsertText(insertion, " : " + interfaceTypeNode + " ");
							}
						}

						var rt = new GetClassTypeReference("System.ComponentModel", "INotifyPropertyChanged", 0);
						var rtResolved = rt.Resolve(refactoringContext.Compilation);
						var ev = rtResolved.GetEvents().First(e => e.Name == "PropertyChanged");
						
						EventDeclaration propertyChangedEvent = new EventDeclaration();
						propertyChangedEvent.Variables.Add(new VariableInitializer(ev.Name));
						propertyChangedEvent.Modifiers = Modifiers.Public;
						propertyChangedEvent.ReturnType = refactoringContext.CreateShortType(ev.ReturnType);
						
						nodes.Add(propertyChangedEvent);
						
						MethodDeclaration onEvent = CreateOnEventMethod(ev, currentClass);
						nodes.Add(onEvent);
						foreach (var node in nodes) {
							script.InsertAfter(insertionAnchorElement, node);
							AppendNewLine(script, insertionAnchorElement, newLineNode);
						}
						useEventArgs = false;
					} else {
						useEventArgs = currentClass.GetMethods().First(m => m.Name == "OnPropertyChanged").Parameters[0].Type.FullName != "System.String";
					}
				}
				
				foreach (FieldWrapper field in fields.Where(f => f.IsIncluded)) {
					var prop = CreateProperty(field.Field, true, field.AddSetter);
					if (!field.Field.IsStatic && !currentClass.IsStatic && field.AddSetter && implementInterface) {
						var invocation = new ExpressionStatement(CreateInvocation(field.PropertyName, useEventArgs));
						var assignment = prop.Setter.Body.Children.ElementAt(0) as Statement;
						prop.Setter.Body = new BlockStatement();
						BlockStatement elseBlock = new BlockStatement();
						elseBlock.Add(assignment.Clone());
						elseBlock.Add(invocation);
						prop.Setter.Body.Add(
							new IfElseStatement(
								new BinaryOperatorExpression(new IdentifierExpression(field.MemberName), BinaryOperatorType.InEquality, new IdentifierExpression("value")),
								elseBlock
							)
						);
					}
					
					script.InsertAfter(insertionAnchorElement, prop);
					AppendNewLine(script, insertionAnchorElement, newLineNode);
				}
			}
			
			return null;
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:84,代码来源:CreatePropertiesDialog.xaml.cs

示例4: HasOnPropertyChanged

		bool HasOnPropertyChanged(ITypeDefinition currentClass)
		{
			return currentClass.GetMethods().Any(m => m.Name == "OnPropertyChanged");
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:4,代码来源:CreatePropertiesDialog.xaml.cs

示例5: CreateEventCompletion

		IEnumerable<ICompletionItem> CreateEventCompletion(XamlCompletionContext context, ITypeDefinition td)
		{
			IMethod invoker = td.GetMethods(method => method.Name == "Invoke").FirstOrDefault();
			if (invoker != null && context.ActiveElement != null) {
				var item = context.ActiveElement;
				var resolver = new XamlAstResolver(compilation, context.ParseInformation);
				var mrr = resolver.ResolveAttribute(context.Attribute) as MemberResolveResult;
				IEvent evt;
				if (mrr == null || (evt = mrr.Member as IEvent) == null)
					return EmptyList<ICompletionItem>.Instance;
				int offset = XmlEditor.XmlParser.GetActiveElementStartIndex(context.Editor.Document.Text, context.Editor.Caret.Offset);
				
				if (offset == -1)
					return Enumerable.Empty<ICompletionItem>();
				
				var loc = context.Editor.Document.GetLocation(offset);
				
				string name = context.ActiveElement.GetAttributeValue("Name");
				if (string.IsNullOrEmpty(name))
					name = context.ActiveElement.GetAttributeValue(XamlConst.XamlNamespace, "Name");
				
				return FindMatchingEventHandlers(context, evt, (string.IsNullOrEmpty(name) ? item.Name : name));
			}
			
			return EmptyList<ICompletionItem>.Instance;
		}
开发者ID:hefnerliu,项目名称:SharpDevelop,代码行数:26,代码来源:CompletionDataGenerator.cs

示例6: Visit

        public override void Visit(ITypeDefinition typeDefinition)
        {
            VisitTypeDefinitionNoMembers(typeDefinition);

            this.Visit(typeDefinition.Events);
            this.Visit(typeDefinition.GetFields(Context));
            this.Visit(typeDefinition.GetMethods(Context));
            this.VisitNestedTypes(typeDefinition.GetNestedTypes(Context));
            this.Visit(typeDefinition.GetProperties(Context));
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:10,代码来源:ReferenceIndexer.cs

示例7: CollectMembersToImplement

		public static List<Tuple<IMember, bool>> CollectMembersToImplement(ITypeDefinition implementingType, IType interfaceType, bool explicitly, out bool interfaceMissing)
		{
			//var def = interfaceType.GetDefinition();
			List<Tuple<IMember, bool>> toImplement = new List<Tuple<IMember, bool>>();
			bool alreadyImplemented;
			interfaceMissing = true;
			// Stub out non-implemented events defined by @iface
			foreach (var evGroup in interfaceType.GetEvents (e => !e.IsSynthetic).GroupBy (m => m.DeclaringType).Reverse ())
				foreach (var ev in evGroup) {
					if (ev.DeclaringType.Kind != TypeKind.Interface)
						continue;

					bool needsExplicitly = explicitly;
					alreadyImplemented = implementingType.GetMembers().Any(m => m.ImplementedInterfaceMembers.Any(im => IsImplementation (im, ev)));
				
					if (!alreadyImplemented) {
						toImplement.Add(new Tuple<IMember, bool>(ev, needsExplicitly));
					} else {
						interfaceMissing = false;
					}
				}
			
			// Stub out non-implemented methods defined by @iface
			foreach (var methodGroup in interfaceType.GetMethods (d => !d.IsSynthetic).GroupBy (m => m.DeclaringType).Reverse ())
				foreach (var method in methodGroup) {
					if (method.DeclaringType.Kind != TypeKind.Interface)
						continue;
					bool needsExplicitly = explicitly;
					alreadyImplemented = false;

					foreach (var cmet in implementingType.GetMethods ()) {
						alreadyImplemented |= cmet.ImplementedInterfaceMembers.Any(m => IsImplementation (m, method));

						if (CompareMembers(method, cmet)) {
							if (!needsExplicitly && !cmet.ReturnType.Equals(method.ReturnType))
								needsExplicitly = true;
							else
								alreadyImplemented |= !needsExplicitly /*|| cmet.InterfaceImplementations.Any (impl => impl.InterfaceType.Equals (interfaceType))*/;
						}
					}
					if (toImplement.Where(t => t.Item1 is IMethod).Any(t => CompareMembers(method, (IMethod)t.Item1)))
						needsExplicitly = true;
					if (!alreadyImplemented) {
						toImplement.Add(new Tuple<IMember, bool>(method, needsExplicitly));
					} else {
						interfaceMissing = false;
					}
				}
			
			// Stub out non-implemented properties defined by @iface
			foreach (var propGroup in interfaceType.GetProperties (p => !p.IsSynthetic).GroupBy (m => m.DeclaringType).Reverse ())
				foreach (var prop in propGroup) {
					if (prop.DeclaringType.Kind != TypeKind.Interface)
						continue;

					bool needsExplicitly = explicitly;
					alreadyImplemented = implementingType.GetMembers().Any(m => m.ImplementedInterfaceMembers.Any(im => IsImplementation (im, prop)));

					foreach (var t in implementingType.GetAllBaseTypeDefinitions ()) {
						if (t.Kind == TypeKind.Interface) {
							foreach (var cprop in t.Properties) {
								if (cprop.Name == prop.Name && cprop.IsShadowing) {
									if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType))
										needsExplicitly = true;
								}
							}
							continue;
						}
						foreach (var cprop in t.Properties) {
							if (cprop.Name == prop.Name) {
								if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType))
									needsExplicitly = true;
								else
									alreadyImplemented |= !needsExplicitly/* || cprop.InterfaceImplementations.Any (impl => impl.InterfaceType.Resolve (ctx).Equals (interfaceType))*/;
							}
						}
					}
					if (!alreadyImplemented) {
						toImplement.Add(new Tuple<IMember, bool>(prop, needsExplicitly));
					} else {
						interfaceMissing = false;
					}
				}
			return toImplement;
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:85,代码来源:ImplementInterfaceAction.cs

示例8: UpdateTestClass

		public void UpdateTestClass(ITypeDefinition typeDefinition)
		{
			fullTypeName = typeDefinition.FullTypeName;
			if (this.NestedTestsInitialized) {
				int baseClassIndex = 0;
				foreach (IType baseType in typeDefinition.GetNonInterfaceBaseTypes()) {
					ITypeDefinition baseTypeDef = baseType.GetDefinition();
					// Check that the base type isn't equal to System.Object or the current class itself
					if (baseTypeDef == null || baseTypeDef == typeDefinition || baseTypeDef.KnownTypeCode == KnownTypeCode.Object)
						continue;
					if (baseTypeDef.DeclaringTypeDefinition != null)
						continue; // we only support inheriting from top-level classes
					var baseClassName = baseTypeDef.FullTypeName;
					if (baseClassIndex < baseClassNames.Count && baseClassName == baseClassNames[baseClassIndex]) {
						// base class is already in the list, just keep it
						baseClassIndex++;
					} else {
						// base class is not in the list, or the remaining portion of the list differs
						// remove remaining portion of the list:
						RemoveBaseClasses(baseClassIndex);
						// Add new base class:
						parentProject.RegisterInheritedClass(baseClassName, this);
						baseClassNames.Add(baseClassName);
						baseClassIndex++;
					}
				}
				
				HashSet<ITest> newOrUpdatedNestedTests = new HashSet<ITest>();
				// Update nested test classes:
				foreach (ITypeDefinition nestedClass in typeDefinition.NestedTypes) {
					if (!NUnitTestFramework.IsTestClass(nestedClass))
						continue;
					
					NUnitTestClass nestedTestClass = FindNestedTestClass(nestedClass.Name, nestedClass.TypeParameterCount);
					if (nestedTestClass != null) {
						nestedTestClass.UpdateTestClass(nestedClass);
					} else {
						nestedTestClass = new NUnitTestClass(parentProject, nestedClass.FullTypeName);
						this.NestedTestCollection.Add(nestedTestClass);
					}
					newOrUpdatedNestedTests.Add(nestedTestClass);
				}
				// Get methods (not operators etc.)
				foreach (IMethod method in typeDefinition.GetMethods(m => m.SymbolKind == SymbolKind.Method)) {
					if (!NUnitTestFramework.IsTestMethod(method))
						continue;
					
					IUnresolvedMethod unresolvedMethod = (IUnresolvedMethod)method.UnresolvedMember;
					string methodNameWithDeclaringType;
					FullTypeName derivedFixture;
					if (method.DeclaringTypeDefinition == typeDefinition) {
						derivedFixture = default(FullTypeName); // method is not inherited
						methodNameWithDeclaringType = method.Name;
					} else {
						if (method.DeclaringTypeDefinition == null)
							continue;
						derivedFixture = fullTypeName; // method is inherited
						methodNameWithDeclaringType = method.DeclaringTypeDefinition.Name + "." + method.Name;
					}
					
					NUnitTestMethod testMethod;
					if (method.IsOverride) {
						testMethod = FindTestMethodWithShortName(method.Name);
					} else {
						testMethod = FindTestMethod(methodNameWithDeclaringType);
					}
					if (testMethod != null) {
						testMethod.UpdateTestMethod(unresolvedMethod, derivedFixture);
					} else {
						testMethod = new NUnitTestMethod(parentProject, unresolvedMethod, derivedFixture);
						this.NestedTestCollection.Add(testMethod);
					}
					newOrUpdatedNestedTests.Add(testMethod);
				}
				// Remove all tests that weren't contained in the new type definition anymore:
				this.NestedTestCollection.RemoveAll(t => !newOrUpdatedNestedTests.Contains(t));
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:78,代码来源:NUnitTestClass.cs

示例9: ExportCustomAttributes

 private List<JsClrAttribute> ExportCustomAttributes(ITypeDefinition ce)
 {
     var list = new List<JsClrAttribute>();
     list.AddRange(ExportAttributes(ce, ce.Attributes));
     foreach (var me in ce.GetMethods())
     {
         list.AddRange(ExportAttributes(me, me.Attributes));
     }
     foreach (var pe in ce.GetProperties())
     {
         list.AddRange(ExportAttributes(pe, pe.Attributes));
     }
     return list;
 }
开发者ID:benbon,项目名称:SharpKit,代码行数:14,代码来源:MemberConverter_Clr.cs


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