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


C# TypeDeclaration.AddChild方法代码示例

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


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

示例1: AddImplementation

        static void AddImplementation(RefactoringContext context, TypeDeclaration result, ICSharpCode.NRefactory.TypeSystem.IType guessedType)
        {
            foreach (var property in guessedType.GetProperties ()) {
                if (!property.IsAbstract)
                    continue;
                if (property.IsIndexer) {
                    var indexerDecl = new IndexerDeclaration() {
                        ReturnType = context.CreateShortType(property.ReturnType),
                        Modifiers = GetModifiers(property),
                        Name = property.Name
                    };
                    indexerDecl.Parameters.AddRange(ConvertParameters(context, property.Parameters));
                    if (property.CanGet)
                        indexerDecl.Getter = new Accessor();
                    if (property.CanSet)
                        indexerDecl.Setter = new Accessor();
                    result.AddChild(indexerDecl, Roles.TypeMemberRole);
                    continue;
                }
                var propDecl = new PropertyDeclaration() {
                    ReturnType = context.CreateShortType(property.ReturnType),
                    Modifiers = GetModifiers (property),
                    Name = property.Name
                };
                if (property.CanGet)
                    propDecl.Getter = new Accessor();
                if (property.CanSet)
                    propDecl.Setter = new Accessor();
                result.AddChild(propDecl, Roles.TypeMemberRole);
            }

            foreach (var method in guessedType.GetMethods ()) {
                if (!method.IsAbstract)
                    continue;
                var decl = new MethodDeclaration() {
                    ReturnType = context.CreateShortType(method.ReturnType),
                    Modifiers = GetModifiers (method),
                    Name = method.Name,
                    Body = new BlockStatement() {
                        new ThrowStatement(new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException")))
                    }
                };
                decl.Parameters.AddRange(ConvertParameters(context, method.Parameters));
                result.AddChild(decl, Roles.TypeMemberRole);
            }

            foreach (var evt in guessedType.GetEvents ()) {
                if (!evt.IsAbstract)
                    continue;
                var decl = new EventDeclaration() {
                    ReturnType = context.CreateShortType(evt.ReturnType),
                    Modifiers = GetModifiers (evt),
                    Name = evt.Name
                };
                result.AddChild(decl, Roles.TypeMemberRole);
            }
        }
开发者ID:Xiaoqing,项目名称:NRefactory,代码行数:57,代码来源:CreateClassDeclarationAction.cs

示例2: AddHyperLinkControl

		public static void AddHyperLinkControl(TypeDeclaration classObject, TargetField field, string fullTypeName)
		{
			StringBuilder sb = new StringBuilder();
			sb.AppendFormat("[{0}(\"{1}\",\"{2}\")] ", typeof(UIClientPropertyAttribute).FullName, field.SourceFieldName, fullTypeName);
			sb.AppendFormat("public Link {0}", field.SourceFieldName);
			sb.AppendFormat("{{ get {{ return this.TryGetLink(\"ctrl00_{0}\"); }} }}", field.SourceFieldName);
			using(StringReader reader = new StringReader(sb.ToString()))
			{
				CSharpParser parser = new CSharpParser();
				var memberList = parser.ParseTypeMembers(reader);
				foreach(var member in memberList)
				{
					var property = (PropertyDeclaration)member;
					var role = new ICSharpCode.NRefactory.Role<ICSharpCode.NRefactory.CSharp.AttributedNode>("Member");
					property.Remove();
					classObject.AddChild(property, TypeDeclaration.MemberRole);
				}
			}
		}
开发者ID:mmooney,项目名称:MMDB.UITest,代码行数:19,代码来源:TargetControlGenerator.cs

示例3: AddTypeMembers

		void AddTypeMembers(TypeDeclaration astType, TypeDefinition typeDef)
		{
			// Add fields
			foreach(FieldDefinition fieldDef in typeDef.Fields) {
				if (MemberIsHidden(fieldDef, context.Settings)) continue;
				astType.AddChild(CreateField(fieldDef), TypeDeclaration.MemberRole);
			}
			
			// Add events
			foreach(EventDefinition eventDef in typeDef.Events) {
				astType.AddChild(CreateEvent(eventDef), TypeDeclaration.MemberRole);
			}

			// Add properties
			CreateProperties(astType, typeDef);
			
			// Add constructors
			foreach(MethodDefinition methodDef in typeDef.Methods) {
				if (!methodDef.IsConstructor) continue;
				
				astType.AddChild(CreateConstructor(methodDef), TypeDeclaration.MemberRole);
			}
			
			// Add methods
			foreach(MethodDefinition methodDef in typeDef.Methods) {
				if (methodDef.IsConstructor || MemberIsHidden(methodDef, context.Settings)) continue;
				
				astType.AddChild(CreateMethod(methodDef), TypeDeclaration.MemberRole);
			}
		}
开发者ID:eldersantos,项目名称:ILSpy,代码行数:30,代码来源:AstBuilder.cs

示例4: DynamizeMembers

		/// <summary>
		/// Adds argfull and argless stubs for all PHP visible members.
		/// </summary>
		private void DynamizeMembers(TypeDeclaration type, TypeDeclaration outType)
		{
			List<Statement> populate_statements = new List<Statement>();

			foreach (INode member in type.Children)
			{
				AttributedNode node = member as AttributedNode;
				if (node != null && Utility.IsDecoratedByAttribute(node, "PHP.Core.PhpVisibleAttribute"))
				{
					MethodDeclaration method_decl;
					PropertyDeclaration prop_decl;

					if ((method_decl = member as MethodDeclaration) != null)
					{
						populate_statements.Add(DynamizeMethod(method_decl, outType));
					}
					else if ((prop_decl = member as PropertyDeclaration) != null)
					{
						populate_statements.Add(DynamizeProperty(prop_decl, outType));
					}
					else throw new InvalidOperationException("PhpVisible applied to invalid member");
				}
			}

			// add the __PopulateTypeDesc method
			MethodDeclaration populator = new MethodDeclaration(
				"__PopulateTypeDesc",
				Modifier.Private | Modifier.Static,
				new TypeReference("void", "System.Void"), new List<ParameterDeclarationExpression>(), null);

			populator.Parameters.Add(new ParameterDeclarationExpression(new TypeReference("PhpTypeDesc"), "desc"));

			populator.Body = new BlockStatement();
			foreach (Statement stmt in populate_statements)
			{
				if (stmt != null) populator.Body.AddChild(stmt);
			}

			outType.AddChild(populator);
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:43,代码来源:Dynamizer.cs

示例5: CreateType

		public TypeDeclaration CreateType(TypeDefinition typeDef)
		{
			TypeDefinition oldCurrentType = context.CurrentType;
			context.CurrentType = typeDef;
			TypeDeclaration astType = new TypeDeclaration();
			ConvertAttributes(astType, typeDef);
			astType.AddAnnotation(typeDef);
			astType.Modifiers = ConvertModifiers(typeDef);
			astType.Name = CleanName(typeDef.Name);
			
			if (typeDef.IsEnum) {  // NB: Enum is value type
				astType.ClassType = ClassType.Enum;
				astType.Modifiers &= ~Modifiers.Sealed;
			} else if (typeDef.IsValueType) {
				astType.ClassType = ClassType.Struct;
				astType.Modifiers &= ~Modifiers.Sealed;
			} else if (typeDef.IsInterface) {
				astType.ClassType = ClassType.Interface;
				astType.Modifiers &= ~Modifiers.Abstract;
			} else {
				astType.ClassType = ClassType.Class;
			}
			
			IEnumerable<GenericParameter> genericParameters = typeDef.GenericParameters;
			if (typeDef.DeclaringType != null && typeDef.DeclaringType.HasGenericParameters)
				genericParameters = genericParameters.Skip(typeDef.DeclaringType.GenericParameters.Count);
			astType.TypeParameters.AddRange(MakeTypeParameters(genericParameters));
			astType.Constraints.AddRange(MakeConstraints(genericParameters));
			
			// Nested types
			foreach(TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
				if (MemberIsHidden(nestedTypeDef, context.Settings))
					continue;
				astType.AddChild(CreateType(nestedTypeDef), TypeDeclaration.MemberRole);
			}
			
			
			if (typeDef.IsEnum) {
				long expectedEnumMemberValue = 0;
				bool forcePrintingInitializers = IsFlagsEnum(typeDef);
				foreach (FieldDefinition field in typeDef.Fields) {
					if (field.IsRuntimeSpecialName) {
						// the value__ field
						if (field.FieldType != typeDef.Module.TypeSystem.Int32) {
							astType.AddChild(ConvertType(field.FieldType), TypeDeclaration.BaseTypeRole);
						}
					} else {
						EnumMemberDeclaration enumMember = new EnumMemberDeclaration();
						enumMember.Name = CleanName(field.Name);
						long memberValue = (long)CSharpPrimitiveCast.Cast(TypeCode.Int64, field.Constant, false);
						if (forcePrintingInitializers || memberValue != expectedEnumMemberValue) {
							enumMember.AddChild(new PrimitiveExpression(field.Constant), EnumMemberDeclaration.InitializerRole);
						}
						expectedEnumMemberValue = memberValue + 1;
						astType.AddChild(enumMember, TypeDeclaration.MemberRole);
					}
				}
			} else {
				// Base type
				if (typeDef.BaseType != null && !typeDef.IsValueType && typeDef.BaseType.FullName != "System.Object") {
					astType.AddChild(ConvertType(typeDef.BaseType), TypeDeclaration.BaseTypeRole);
				}
				foreach (var i in typeDef.Interfaces)
					astType.AddChild(ConvertType(i), TypeDeclaration.BaseTypeRole);
				
				
				AddTypeMembers(astType, typeDef);
			}

			context.CurrentType = oldCurrentType;
			return astType;
		}
开发者ID:eldersantos,项目名称:ILSpy,代码行数:72,代码来源:AstBuilder.cs

示例6: Visit

			public override void Visit (Mono.CSharp.Enum e)
			{
				TypeDeclaration newType = new TypeDeclaration ();
				AddAttributeSection (newType, e);
				newType.ClassType = ClassType.Enum;
				var location = LocationsBag.GetMemberLocation (e);
				
				AddModifiers (newType, location);
				int curLoc = 0;
				if (location != null)
					newType.AddChild (new CSharpTokenNode (Convert (location [curLoc++]), "enum".Length), TypeDeclaration.Roles.Keyword);
				newType.AddChild (Identifier.Create (e.MemberName.Name, Convert (e.MemberName.Location)), AstNode.Roles.Identifier);
				
				if (e.BaseTypeExpression != null) {
					if (location != null && curLoc < location.Count)
						newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Colon);
					newType.AddChild (ConvertToType (e.BaseTypeExpression), TypeDeclaration.BaseTypeRole);
				}

				if (location != null && curLoc < location.Count)
					newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.LBrace);
				typeStack.Push (newType);
				
				foreach (EnumMember member in e.OrderedAllMembers) {
					Visit (member);
					if (location != null && curLoc < location.Count - 1) //last one is closing brace
						newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.Comma);
				}
				
				if (location != null && location.Count > 2) {
					if (location != null && curLoc < location.Count)
						newType.AddChild (new CSharpTokenNode (Convert (location[curLoc++]), 1), AstNode.Roles.RBrace);
					
					if (e.HasOptionalSemicolon)
						newType.AddChild (new CSharpTokenNode (Convert (e.OptionalSemicolon), 1), AstNode.Roles.Semicolon);
				} else {
					// parser error, set end node to max value.
					newType.AddChild (new ErrorNode (), AstNode.Roles.Error);
				}
				typeStack.Pop ();
				AddType (newType);
			}
开发者ID:N3X15,项目名称:ILSpy,代码行数:42,代码来源:CSharpParser.cs

示例7: Visit

			public override void Visit(Interface i)
			{
				var newType = new TypeDeclaration();
				newType.ClassType = ClassType.Interface;
				AddAttributeSection(newType, i);
				var location = LocationsBag.GetMemberLocation(i);
				AddModifiers(newType, location);
				int curLoc = 0;
				if (location != null && location.Count > 0)
					newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.InterfaceKeyword), Roles.InterfaceKeyword);
				newType.AddChild(Identifier.Create(i.MemberName.Name, Convert(i.MemberName.Location)), Roles.Identifier);
				AddTypeParameters(newType, i.MemberName);
				
				if (i.TypeBaseExpressions != null) {
					if (location != null && curLoc < location.Count)
						newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.Colon), Roles.Colon);
					var commaLocations = LocationsBag.GetLocations(i.TypeBaseExpressions);
					int j = 0;
					foreach (var baseTypes in i.TypeBaseExpressions) {
						newType.AddChild(ConvertToType(baseTypes), Roles.BaseType);
						if (commaLocations != null && j < commaLocations.Count) {
							newType.AddChild(new CSharpTokenNode(Convert(commaLocations [j]), Roles.Comma), Roles.Comma);
							j++;
						}
					}
				}
				
				AddConstraints(newType, i.CurrentTypeParameters);
				if (location != null && curLoc < location.Count)
					newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.LBrace), Roles.LBrace);
				typeStack.Push(newType);
				base.Visit(i);
				if (location != null && location.Count > 2) {
					if (location != null && curLoc < location.Count)
						newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.RBrace), Roles.RBrace);
					if (location != null && curLoc < location.Count)
						newType.AddChild(new CSharpTokenNode(Convert(location [curLoc++]), Roles.Semicolon), Roles.Semicolon);
				} else {
					// parser error, set end node to max value.
					newType.AddChild(new ErrorNode(), Roles.Error);
				}
				typeStack.Pop();
				AddType(newType);
			}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:44,代码来源:CSharpParser.cs

示例8: GetExplicitInterfaceTypes

        /// <summary>
        /// Builds and adds the needed nested types in a current type representing explicit interfaces
        /// </summary>
        /// <param name="currentType"></param>
        public static void GetExplicitInterfaceTypes(TypeDeclaration currentType)
        {
            //Trim the type name to avoid errors with generic types
            string currentTypeName = currentType.Name.TrimEnd("_Base".ToCharArray()).TrimEnd("_T".ToCharArray());

            //SEARCH FOR THE METHODS IN THE CURRENT TYPE THAT SHOULD BE IMPLEMENTED IN A NESTED CLASS
            List<MethodDeclaration> methodsOfCurrentType = new List<MethodDeclaration>();
            foreach (KeyValuePair<AstType, List<MethodDeclaration>> kvp in Cache.GetPrivateImplementation())
            {
                foreach (MethodDeclaration m in kvp.Value)
                {
                    if (m.TypeMember.Name == currentTypeName)
                        methodsOfCurrentType.Add(m);
                }
            }

            //CREATE A DICTIONARY WITH THE NESTEDCLASS AND METHODS NEEDED (SORTED)
            Dictionary<AstType, List<MethodDeclaration>> privateImplClass = new Dictionary<AstType, List<MethodDeclaration>>();
            foreach (MethodDeclaration m in methodsOfCurrentType)
            {
                foreach (KeyValuePair<AstType, List<MethodDeclaration>> kvp in Cache.GetPrivateImplementation())
                {
                    if (kvp.Value.Contains(m))
                    {
                        //If the method private implementation is corresponding to the current key type in the loop, continue
                        if (GetTypeName(m.PrivateImplementationType) == GetTypeName(kvp.Key))
                        {
                            //REMOVE THE METHOD FROM THE CURRENT TYPE                            
                            currentType.Members.Remove(m);
                            RemoveHeaderNode(m, currentType);

                            //REMOVE THE PRIVATE IMPLEMENTATION
                            m.PrivateImplementationType = Ast.AstType.Null;

                            //Add the method in the sorted dictionary
                            if (privateImplClass.ContainsKey(kvp.Key))
                                privateImplClass[kvp.Key].Add((MethodDeclaration)m.Clone());

                            else
                                privateImplClass.Add(kvp.Key, new List<MethodDeclaration>() { (MethodDeclaration)m.Clone() });

                        }
                    }
                }
            }

            //CREATE FROM THE NESTED CLASS THE NESTEDTYPEDECLARATION NODE
            foreach (KeyValuePair<AstType, List<MethodDeclaration>> kvp in privateImplClass)
            {
                TypeDeclaration type = new TypeDeclaration();
                string nestedTypeName = "_interface_" + GetTypeName(kvp.Key);
                type.NameToken = new Identifier(nestedTypeName, TextLocation.Empty);
                type.Name = nestedTypeName;
                type.ModifierTokens.Add(new CppModifierToken(TextLocation.Empty, Modifiers.Public));

                if (kvp.Key is SimpleType)
                {
                    foreach (AstType tp in (kvp.Key as SimpleType).TypeArguments)
                        type.TypeParameters.Add(new TypeParameterDeclaration() { NameToken = new Identifier(GetTypeName(tp), TextLocation.Empty) });
                }

                //ADD BASE TYPES
                SimpleType baseType = new SimpleType(GetTypeName(kvp.Key));
                if (kvp.Key is SimpleType)
                {
                    foreach (AstType tp in (kvp.Key as SimpleType).TypeArguments)
                        baseType.TypeArguments.Add((AstType)tp.Clone());
                }

                type.AddChild(baseType, TypeDeclaration.BaseTypeRole);

                //REMOVE THE BASE TYPE BECAUSE THE NESTED TYPE WILL INHERIT FROM IT
                try
                {
                    currentType.BaseTypes.Remove(currentType.BaseTypes.First(x => GetTypeName(x) == GetTypeName(baseType)));
                }
                catch (InvalidOperationException)
                {
                    //The element is not present in the list
                    //Safe to ignore this :)
                }

                //ADD METHODS
                type.Members.AddRange(kvp.Value);

                //ADD FIELD
                HeaderFieldDeclaration fdecl = new HeaderFieldDeclaration();
                SimpleType nestedType = new SimpleType(nestedTypeName);
                foreach (TypeParameterDeclaration tp in type.TypeParameters)
                    nestedType.TypeArguments.Add(new SimpleType(tp.Name));

                ExplicitInterfaceTypeDeclaration ntype = new Ast.ExplicitInterfaceTypeDeclaration(type);

                fdecl.ReturnType = nestedType;
                string _tmp = "_" + GetTypeName(fdecl.ReturnType).ToLower();
                fdecl.Variables.Add(new VariableInitializer(_tmp));
//.........这里部分代码省略.........
开发者ID:AlexAlbala,项目名称:Alter-Native,代码行数:101,代码来源:Resolver.cs

示例9: Visit

			public override void Visit (Mono.CSharp.Enum e)
			{
				TypeDeclaration newType = new TypeDeclaration ();
				AddAttributeSection (newType, e);
				newType.ClassType = ClassType.Enum;
				var location = LocationsBag.GetMemberLocation (e);
				
				AddModifiers (newType, location);
				if (location != null)
					newType.AddChild (new CSharpTokenNode (Convert (location [0]), "enum".Length), TypeDeclaration.Roles.Keyword);
				newType.AddChild (Identifier.Create (e.MemberName.Name, Convert (e.MemberName.Location)), AstNode.Roles.Identifier);
				
				if (e.BaseTypeExpression != null)
					newType.AddChild (ConvertToType (e.BaseTypeExpression), TypeDeclaration.BaseTypeRole);

				if (location != null && location.Count > 1)
					newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AstNode.Roles.LBrace);
				typeStack.Push (newType);
				base.Visit (e);
				if (location != null && location.Count > 2) {
					newType.AddChild (new CSharpTokenNode  (Convert (location[2]), 1), AstNode.Roles.RBrace);
				} else {
					// parser error, set end node to max value.
					newType.AddChild (new ErrorNode (), AstNode.Roles.Error);
				}
				typeStack.Pop ();
				AddType (newType);
			}
开发者ID:aleksandersumowski,项目名称:monodevelop,代码行数:28,代码来源:CSharpParser.cs

示例10: AddTypeMembers

        void AddTypeMembers(TypeDeclaration astType, TypeDefinition typeDef)
        {
            // Add fields
            foreach(FieldDefinition fieldDef in typeDef.Fields) {
                astType.AddChild(CreateField(fieldDef), TypeDeclaration.MemberRole);
            }

            // Add events
            foreach(EventDefinition eventDef in typeDef.Events) {
                astType.AddChild(CreateEvent(eventDef), TypeDeclaration.MemberRole);
            }

            // Add properties
            foreach(PropertyDefinition propDef in typeDef.Properties) {
                astType.AddChild(CreateProperty(propDef), TypeDeclaration.MemberRole);
            }

            // Add constructors
            foreach(MethodDefinition methodDef in typeDef.Methods) {
                if (!methodDef.IsConstructor) continue;

                astType.AddChild(CreateConstructor(methodDef), TypeDeclaration.MemberRole);
            }

            // Add methods
            foreach(MethodDefinition methodDef in typeDef.Methods) {
                if (methodDef.IsSpecialName) continue;

                astType.AddChild(CreateMethod(methodDef), TypeDeclaration.MemberRole);
            }
        }
开发者ID:KleinR,项目名称:ILSpy,代码行数:31,代码来源:AstBuilder.cs

示例11: Visit

			public override void Visit (Struct s)
			{
				TypeDeclaration newType = new TypeDeclaration ();
				newType.ClassType = ClassType.Struct;
				AddAttributeSection (newType, s);
				var location = LocationsBag.GetMemberLocation (s);
				AddModifiers (newType, location);
				if (location != null)
					newType.AddChild (new CSharpTokenNode (Convert (location [0]), "struct".Length), TypeDeclaration.Roles.Keyword);
				newType.AddChild (new Identifier (s.MemberName.Name, Convert (s.MemberName.Location)), AstNode.Roles.Identifier);
				if (s.MemberName.TypeArguments != null)  {
					var typeArgLocation = LocationsBag.GetLocations (s.MemberName);
					if (typeArgLocation != null)
						newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation [0]), 1), TypeDeclaration.Roles.LChevron);
					AddTypeParameters (newType, typeArgLocation, s.MemberName.TypeArguments);
					if (typeArgLocation != null)
						newType.AddChild (new CSharpTokenNode (Convert (typeArgLocation [1]), 1), TypeDeclaration.Roles.RChevron);
					AddConstraints (newType, s);
				}
				
				if (s.TypeBaseExpressions != null) {
					foreach (var baseTypes in s.TypeBaseExpressions) {
						newType.AddChild (ConvertToType (baseTypes), TypeDeclaration.BaseTypeRole);
					}
				}
				
				if (location != null && location.Count > 1)
					newType.AddChild (new CSharpTokenNode (Convert (location [1]), 1), AstNode.Roles.LBrace);
				typeStack.Push (newType);
				base.Visit (s);
				if (location != null && location.Count > 2)
					newType.AddChild (new CSharpTokenNode (Convert (location [2]), 1), AstNode.Roles.RBrace);
				typeStack.Pop ();
				AddType (newType);
			}
开发者ID:rmattuschka,项目名称:ILSpy,代码行数:35,代码来源:CSharpParser.cs

示例12: Visit

			public override void Visit (Mono.CSharp.Enum e)
			{
				TypeDeclaration newType = new TypeDeclaration ();
				newType.ClassType = ClassType.Enum;
				var location = LocationsBag.GetMemberLocation (e);
				
				AddModifiers (newType, location);
				if (location != null)
					newType.AddChild (new CSharpTokenNode (Convert (location[0]), "enum".Length), TypeDeclaration.Roles.Keyword);
				newType.AddChild (CreateIdentifier (e.Basename, Convert (e.MemberName.Location)), AstNode.Roles.Identifier);
				if (location != null && location.Count > 1)
					newType.AddChild (new CSharpTokenNode (Convert (location[1]), 1), AstNode.Roles.LBrace);
				typeStack.Push (newType);
				base.Visit (e);
				if (location != null && location.Count > 2)
					newType.AddChild (new CSharpTokenNode  (Convert (location[2]), 1), AstNode.Roles.RBrace);
				typeStack.Pop ();
				AddType (newType);
			}
开发者ID:slluis,项目名称:monodevelop,代码行数:19,代码来源:CSharpParser.cs

示例13: CreateType

        public TypeDeclaration CreateType(TypeDefinition typeDef)
        {
            TypeDeclaration astType = new TypeDeclaration();
            astType.Modifiers = ConvertModifiers(typeDef);
            astType.Name = typeDef.Name;

            if (typeDef.IsEnum) {  // NB: Enum is value type
                astType.ClassType = ClassType.Enum;
                astType.Modifiers &= ~Modifiers.Sealed;
            } else if (typeDef.IsValueType) {
                astType.ClassType = ClassType.Struct;
                astType.Modifiers &= ~Modifiers.Sealed;
            } else if (typeDef.IsInterface) {
                astType.ClassType = ClassType.Interface;
                astType.Modifiers &= ~Modifiers.Abstract;
            } else {
                astType.ClassType = ClassType.Class;
            }

            // Nested types
            foreach(TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
                astType.AddChild(CreateType(nestedTypeDef), TypeDeclaration.MemberRole);
            }

            if (typeDef.IsEnum) {
                foreach (FieldDefinition field in typeDef.Fields) {
                    if (field.IsRuntimeSpecialName) {
                        // the value__ field
                        astType.AddChild(ConvertType(field.FieldType), TypeDeclaration.BaseTypeRole);
                    } else {
                        EnumMemberDeclaration enumMember = new EnumMemberDeclaration();
                        enumMember.Name = field.Name;
                        astType.AddChild(enumMember, TypeDeclaration.MemberRole);
                    }
                }
            } else {
                // Base type
                if (typeDef.BaseType != null && !typeDef.IsValueType && typeDef.BaseType.FullName != Constants.Object) {
                    astType.AddChild(ConvertType(typeDef.BaseType), TypeDeclaration.BaseTypeRole);
                }
                foreach (var i in typeDef.Interfaces)
                    astType.AddChild(ConvertType(i), TypeDeclaration.BaseTypeRole);

                AddTypeMembers(astType, typeDef);
            }

            return astType;
        }
开发者ID:KleinR,项目名称:ILSpy,代码行数:48,代码来源:AstBuilder.cs

示例14: AddSerializibility

		/// <summary>
		/// Makes sure that the PHP-visible type is serializable.
		/// </summary>
		private void AddSerializibility(TypeDeclaration type, TypeDeclaration outType)
		{
			// make the type serializable
			if (!Utility.IsDecoratedByAttribute(type, "System.SerializableAttribute"))
			{
				AttributeSection section = new AttributeSection();
				section.Attributes.Add(new ICSharpCode.NRefactory.Parser.AST.Attribute("Serializable", null, null));
				outType.Attributes.Add(section);

				ConstructorDeclaration ctor = new ConstructorDeclaration(type.Name, 
					((type.Modifier & Modifier.Sealed) == Modifier.Sealed ? Modifier.Private : Modifier.Protected),
					new List<ParameterDeclarationExpression>(), null);

				ctor.Parameters.Add(
					new ParameterDeclarationExpression(new TypeReference("System.Runtime.Serialization.SerializationInfo"), "info"));
				ctor.Parameters.Add(
					new ParameterDeclarationExpression(new TypeReference("System.Runtime.Serialization.StreamingContext"), "context"));

				ctor.ConstructorInitializer = new ConstructorInitializer();
				ctor.ConstructorInitializer.ConstructorInitializerType = ConstructorInitializerType.Base;
					
				ctor.ConstructorInitializer.Arguments.Add(new IdentifierExpression("info"));
				ctor.ConstructorInitializer.Arguments.Add(new IdentifierExpression("context"));

				ctor.Body = new BlockStatement();

				outType.AddChild(ctor);
			}
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:32,代码来源:Dynamizer.cs

示例15: DynamizeProperty

		/// <summary>
		/// Adds stubs for a PhpVisible property.
		/// </summary>
		private Statement DynamizeProperty(PropertyDeclaration property, TypeDeclaration outType)
		{
			MethodDeclaration getter = null, setter = null;

			if (property.HasGetRegion)
			{
				// add the getter stub
				getter = new MethodDeclaration(
					"__get_" + property.Name, Modifier.Private | Modifier.Static,
					new TypeReference("Object"),
					new List<ParameterDeclarationExpression>(),
					new List<AttributeSection>());

				getter.Parameters.Add(new ParameterDeclarationExpression(new TypeReference("Object"), "instance"));

				getter.Body = new BlockStatement();
				getter.Body.AddChild(new ReturnStatement(new FieldReferenceExpression(new ParenthesizedExpression(
					new CastExpression(new TypeReference(((TypeDeclaration)property.Parent).Name),
					new IdentifierExpression("instance"))), property.Name)));

				outType.AddChild(getter);
			}

			if (property.HasSetRegion)
			{
				// add the setter stub
				setter = new MethodDeclaration(
					"__set_" + property.Name, Modifier.Private | Modifier.Static,
					new TypeReference("void", "System.Void"),
					new List<ParameterDeclarationExpression>(),
					new List<AttributeSection>());

				setter.Parameters.Add(new ParameterDeclarationExpression(new TypeReference("Object"), "instance"));
				setter.Parameters.Add(new ParameterDeclarationExpression(new TypeReference("Object"), "value"));

				setter.Body = new BlockStatement();

				Expression rhs = Convertor.ConvertTo(
					property.Name,
					new IdentifierExpression("value"),
					property.TypeReference,
					setter.Body,
					new ReturnStatement(NullExpression.Instance),
					false,
					false,
					1);

				setter.Body.AddChild(new StatementExpression(new AssignmentExpression(
					(new FieldReferenceExpression(new ParenthesizedExpression(
					new CastExpression(new TypeReference(((TypeDeclaration)property.Parent).Name),
					new IdentifierExpression("instance"))), property.Name)),
					AssignmentOperatorType.Assign, rhs)));

				outType.AddChild(setter);
			}

			// return an expression to be put to __PopulateTypeDesc
			ArrayList parameters = new ArrayList();
			parameters.Add(new PrimitiveExpression(property.Name, property.Name));
			parameters.Add(Utility.ModifierToMemberAttributes(property.Modifier));

			if (getter != null)
			{
				ArrayList del_params = new ArrayList();
				del_params.Add(new FieldReferenceExpression(
					new TypeReferenceExpression(((TypeDeclaration)property.Parent).Name),
					getter.Name));

				parameters.Add(new ObjectCreateExpression(new TypeReference("GetterDelegate"), del_params));
			}
			else parameters.Add(new PrimitiveExpression(null, String.Empty));

			if (setter != null)
			{
				ArrayList del_params = new ArrayList();
				del_params.Add(new FieldReferenceExpression(
					new TypeReferenceExpression(((TypeDeclaration)property.Parent).Name),
					setter.Name));

				parameters.Add(new ObjectCreateExpression(new TypeReference("SetterDelegate"), del_params));
			}
			else parameters.Add(new PrimitiveExpression(null, String.Empty));

			return new StatementExpression(new InvocationExpression(
				new FieldReferenceExpression(new IdentifierExpression("desc"), "AddProperty"),
				parameters));
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:90,代码来源:Dynamizer.cs


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