예제 #1
0
        public static List <CSField> Parse(FieldDeclaration fieldNode)
        {
            var returnList = new List <CSField>();
            EnumProtectionLevel protectionLevel = EnumProtectionLevel.None;

            if ((fieldNode.Modifiers & Modifiers.Public) == Modifiers.Public)
            {
                protectionLevel = EnumProtectionLevel.Public;
            }
            else if ((fieldNode.Modifiers & Modifiers.Private) == Modifiers.Private)
            {
                protectionLevel = EnumProtectionLevel.Private;
            }
            else if ((fieldNode.Modifiers & Modifiers.Protected) == Modifiers.Protected)
            {
                protectionLevel = EnumProtectionLevel.Protected;
            }
            else if ((fieldNode.Modifiers & Modifiers.Internal) == Modifiers.Internal)
            {
                protectionLevel = EnumProtectionLevel.Internal;
            }
            string typeName;
            string typeNamespace;

            DotNetParserHelper.SplitType(fieldNode.ReturnType.ToString(), out typeName, out typeNamespace);
            foreach (VariableInitializer variableNode in fieldNode.Variables)
            {
                CSField fieldObject = new CSField
                {
                    TypeNamespace   = typeNamespace,
                    TypeName        = typeName,
                    FieldName       = variableNode.Name,
                    ProtectionLevel = protectionLevel
                };
                if (variableNode.Initializer != null)
                {
                    if (variableNode.Initializer is PrimitiveExpression)
                    {
                        PrimitiveExpression primitiveExpression = (PrimitiveExpression)variableNode.Initializer;
                        fieldObject.FieldValue = primitiveExpression.Value;
                    }
                }
                foreach (var attributeSectionNode in fieldNode.Attributes)
                {
                    foreach (var attributeNode in attributeSectionNode.Attributes)
                    {
                        var attribute = CSAttribute.Parse(attributeNode);
                        fieldObject.AttributeList.Add(attribute);
                    }
                }
                returnList.Add(fieldObject);
            }
            return(returnList);
        }
예제 #2
0
        internal static void BuildClass(CSClass classObject, TypeDeclaration typeDefinitionNode, string relativeFilePath)
        {
            var fieldList = typeDefinitionNode.Children.Where(i => i is FieldDeclaration);

            if ((typeDefinitionNode.Modifiers & Modifiers.Public) == Modifiers.Public)
            {
                classObject.ProtectionLevel = EnumProtectionLevel.Public;
            }
            else if ((typeDefinitionNode.Modifiers & Modifiers.Private) == Modifiers.Private)
            {
                classObject.ProtectionLevel = EnumProtectionLevel.Private;
            }
            else if ((typeDefinitionNode.Modifiers & Modifiers.Protected) == Modifiers.Protected)
            {
                classObject.ProtectionLevel = EnumProtectionLevel.Protected;
            }
            else if ((typeDefinitionNode.Modifiers & Modifiers.Internal) == Modifiers.Internal)
            {
                classObject.ProtectionLevel = EnumProtectionLevel.Internal;
            }
            foreach (FieldDeclaration fieldNode in fieldList)
            {
                var fieldObjectList = CSField.Parse(fieldNode);
                classObject.FieldList.AddRange(fieldObjectList);
            }
            var propertyList = typeDefinitionNode.Children.Where(i => i is PropertyDeclaration);

            foreach (PropertyDeclaration propertyNode in propertyList)
            {
                var propertyObject = CSProperty.Parse(propertyNode);
                classObject.PropertyList.Add(propertyObject);
            }
            var attributeSectionList = typeDefinitionNode.Children.Where(i => i is AttributeSection);

            foreach (AttributeSection attributeSectionNode in attributeSectionList)
            {
                foreach (var attributeNode in attributeSectionNode.Attributes)
                {
                    var attribute = CSAttribute.Parse(attributeNode);
                    classObject.AttributeList.Add(attribute);
                }
            }
            if (!classObject.FileRelativePathList.Contains(relativeFilePath, StringComparer.CurrentCultureIgnoreCase))
            {
                classObject.FileRelativePathList.Add(relativeFilePath);
            }
        }
예제 #3
0
        public static CSProperty Parse(PropertyDeclaration propertyNode)
        {
            CSProperty returnValue = new CSProperty();

            returnValue.ProtectionLevel = EnumProtectionLevel.Private;
            if ((propertyNode.Modifiers & Modifiers.Public) == Modifiers.Public)
            {
                returnValue.ProtectionLevel = EnumProtectionLevel.Public;
            }
            else if ((propertyNode.Modifiers & Modifiers.Private) == Modifiers.Private)
            {
                returnValue.ProtectionLevel = EnumProtectionLevel.Private;
            }
            else if ((propertyNode.Modifiers & Modifiers.Protected) == Modifiers.Protected)
            {
                returnValue.ProtectionLevel = EnumProtectionLevel.Protected;
            }
            else if ((propertyNode.Modifiers & Modifiers.Internal) == Modifiers.Internal)
            {
                returnValue.ProtectionLevel = EnumProtectionLevel.Internal;
            }
            string typeName;
            string typeNamespace;

            DotNetParserHelper.SplitType(propertyNode.ReturnType.ToString(), out typeName, out typeNamespace);
            returnValue.TypeName      = typeName;
            returnValue.TypeNamespace = typeNamespace;
            returnValue.PropertyName  = propertyNode.Name;
            foreach (var attributeSectionNode in propertyNode.Attributes)
            {
                foreach (var attributeNode in attributeSectionNode.Attributes)
                {
                    var attribute = CSAttribute.Parse(attributeNode);
                    returnValue.AttributeList.Add(attribute);
                }
            }
            return(returnValue);
        }
예제 #4
0
		public static CSAttribute Parse(ICSharpCode.NRefactory.CSharp.Attribute attributeNode)
		{
			var returnValue = new CSAttribute();
			string typeName;
			string typeNamespace;
			DotNetParserHelper.SplitType(attributeNode.Type.ToString(), out typeName, out typeNamespace);
			returnValue.TypeName = typeName;
			returnValue.TypeNamespace = typeNamespace;

			foreach (var node in attributeNode.Children)
			{
				if(node is PrimitiveExpression)
				{
					var primitiveExpressionNode = (PrimitiveExpression)node;
					var argument = new CSAttributeArgument
					{
						ArguementValue = primitiveExpressionNode.Value
					};
					returnValue.ArgumentList.Add(argument);
				}
				if(node is NamedExpression)
				{
					var namedExpressionNode = (NamedExpression)node;
					if(namedExpressionNode.Expression is PrimitiveExpression)
					{
						var primitiveExpressionNode = (PrimitiveExpression)namedExpressionNode.Expression;
						var argument = new CSAttributeArgument
						{
							ArgumentName = namedExpressionNode.Identifier,
							ArguementValue = primitiveExpressionNode.Value
						};
						returnValue.ArgumentList.Add(argument);
					}
					else if(namedExpressionNode.Expression is MemberReferenceExpression)
					{
						var memberReferenceExpressionNode = (MemberReferenceExpression)namedExpressionNode.Expression;
					}
					else 
					{
						throw new Exception("Unrecognized expression type: " + namedExpressionNode.Expression.GetType().FullName);
					}
				}
				if(node is NamedArgumentExpression)
				{
					var namedArgumentExpressionNode = (NamedArgumentExpression)node;
					if (namedArgumentExpressionNode.Expression is PrimitiveExpression)
					{
						var primitiveExpressionNode = (PrimitiveExpression)namedArgumentExpressionNode.Expression;
						var argument = new CSAttributeArgument
						{
							ArgumentName = namedArgumentExpressionNode.Identifier,
							ArguementValue = primitiveExpressionNode.Value
						};
						returnValue.ArgumentList.Add(argument);
					}
					else if (namedArgumentExpressionNode.Expression is MemberReferenceExpression)
					{
						var memberReferenceExpressionNode = (MemberReferenceExpression)namedArgumentExpressionNode.Expression;
					}
					else
					{
						throw new Exception("Unrecognized expression type: " + namedArgumentExpressionNode.Expression.GetType().FullName);
					}
					
				}
			}
			return returnValue;
		}