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


C# TypeDeclaration.Annotation方法代码示例

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


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

示例1: CreateProperties

		private void CreateProperties(TypeDeclaration astType, TypeDefinition typeDef)
		{
			CustomAttribute attributeToRemove = null;
			foreach (PropertyDefinition propDef in typeDef.Properties) {
				MemberDeclaration astProp = CreateProperty(propDef);

				if (astProp.Name == "Item" && propDef.HasParameters) {
					var defaultMember = GetDefaultMember(astType.Annotation<TypeDefinition>());
					if (defaultMember.Item1 == "Item") {
						astProp = ConvertPropertyToIndexer((PropertyDeclaration)astProp, propDef);
						attributeToRemove = defaultMember.Item2;
					} else if ((propDef.GetMethod ?? propDef.SetMethod).HasOverrides) {
						astProp = ConvertPropertyToIndexer((PropertyDeclaration)astProp, propDef);
					}
				}

				astType.AddChild(astProp, TypeDeclaration.MemberRole);
			}

			if (attributeToRemove != null) {
				var astAttr = astType.Attributes.SelectMany(sec => sec.Attributes).First(attr => attr.Annotation<CustomAttribute>() == attributeToRemove);
				var attrSection = (AttributeSection)astAttr.Parent;
				if (attrSection.Attributes.Count == 1)
					attrSection.Remove();
				else
					astAttr.Remove();
			}
		}
开发者ID:eldersantos,项目名称:ILSpy,代码行数:28,代码来源:AstBuilder.cs

示例2: VisitTypeDeclaration

                public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
                {
                    var td = typeDeclaration.Annotation<TypeDefinition>();
                    if (td == null) return;

                    var xamlFile = iFull.GetRelativePath(td.WellFullName + ".xaml", '.');
                    if (iFull.iCsRelativeFileSet.Contains(xamlFile))
                    {
                        var generatedMembers = typeDeclaration.Members.Where(x => x.Attributes.SelectMany(y => y.Attributes).Select(y => y.Annotation<CustomAttribute>()).Any(y => y != null && y.AttributeType.FullName == "System.CodeDom.Compiler.GeneratedCodeAttribute"));
                        if (generatedMembers.Any())
                        {
                            // 修改为分部类型
                            typeDeclaration.Modifiers |= Modifiers.Partial;

                            // 删除自动生成代码
                            var generatedFlds = generatedMembers.SelectMany(x => x.Descendants.OfType<MemberReferenceExpression>())
                                .Select(x => x.Annotation<FieldDefinition>())
                                .Where(x => x != null && x.DeclaringType == td)
                                .Distinct()
                                .Select(x => x.Name);
                            var removeFlds = typeDeclaration.Members.OfType<FieldDeclaration>()
                                .Where(x => generatedFlds.Any(y => x.Variables.Any(z => z.Name == y)));
                            foreach (var x in generatedMembers.Concat(removeFlds).OrderByDescending(x => x.StartLocation))
                            {
                                x.Remove();
                            }
                        }
                        return;
                    }

                    var settingsFile = iFull.GetRelativePath(td.WellFullName + ".settings", '.');
                    if (iFull.iCsRelativeFileSet.Contains(settingsFile))
                    {
                        // 修改为分部类型
                        typeDeclaration.Modifiers |= Modifiers.Partial;
                    }
                }
开发者ID:DKeeper1523,项目名称:ilspy_yh,代码行数:37,代码来源:CSharpLanguage.cs


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