Exemple #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);
        }
Exemple #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);
            }
        }
Exemple #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);
        }