示例#1
0
        public virtual object VisitInterfacePropertyNode(InterfacePropertyNode interfacePropertyNode, object data)
        {
            stackMap.Push(interfacePropertyNode);
            interfacePropertyNode.Attributes.AcceptVisitor(this, data);

            interfacePropertyNode.Type.AcceptVisitor(this, data);

            stackMap.Pop();
            return(null);
        }
示例#2
0
		private void ParseInterfaceMember()									
		{
			ParsePossibleAttributes(false);
			ParseModifiers();

			switch (curtok.ID)
			{
				case TokenID.Event:
					// event
					InterfaceEventNode node = new InterfaceEventNode(curtok);
					curInterface.Events.Add(node);

					if (curAttributes.Count > 0)
					{
						node.Attributes = curAttributes;
						curAttributes = new NodeCollection<AttributeNode>();
					}

					node.Modifiers = curmods;
					curmods = Modifier.Empty;
					AssertAndAdvance(TokenID.Event);
					node.Type = ParseType();
                    node.Names.Add(ParseQualifiedIdentifier(false, true, true));
					AssertAndAdvance(TokenID.Semi);

					break;
				default:
					IType type = ParseType();
					if (type == null)
					{
						ReportError("Expected type or ident in interface member definition.");
					}
					switch (curtok.ID)
					{
						case TokenID.This:
							// interface indexer
							InterfaceIndexerNode iiNode = new InterfaceIndexerNode(curtok);
							if (curAttributes.Count > 0)
							{
								iiNode.Attributes = curAttributes;
								curAttributes = new NodeCollection<AttributeNode>();
							}
							iiNode.Type = type;
							Advance(); // over 'this'
							iiNode.Params = ParseParamList(TokenID.LBracket, TokenID.RBracket);

							bool hasGetter = false;
							bool hasSetter = false;
							ParseInterfaceAccessors(ref hasGetter, ref hasSetter);
							iiNode.HasGetter = hasGetter;
							iiNode.HasSetter = hasSetter;
							break;

						default:
                            QualifiedIdentifierExpression name = ParseQualifiedIdentifier(false, true, true);
							if (name == null || name.Expressions.Expressions.Count == 0)
							{
								ReportError("Expected name or ident in member definition.");
							}
							switch (curtok.ID)
							{
                                case TokenID.Less:
								case TokenID.LParen:
									// method
									InterfaceMethodNode mnode = new InterfaceMethodNode(curtok);
									curInterface.Methods.Add(mnode);

									if (curAttributes.Count > 0)
									{
										mnode.Attributes = curAttributes;
										curAttributes = new NodeCollection<AttributeNode>();
									}

									mnode.Modifiers = curmods;
									curmods = Modifier.Empty;

									mnode.Names.Add(name);
									mnode.Type = type;

                                    ParsePossibleTypeParameterNode(true, true, false);
                                    //if generic applies type parameter collection to the node
                                    ApplyTypeParameters(mnode);

                                    // starts at LParen

									mnode.Params = ParseParamList();

                                    ParsePossibleTypeParameterConstraintNode(mnode);
                                    ApplyTypeParameterConstraints(mnode);


									AssertAndAdvance(TokenID.Semi);
									break;

								case TokenID.LCurly:
									// property
									InterfacePropertyNode pnode = new InterfacePropertyNode(curtok);
									curInterface.Properties.Add(pnode);									

									// these are the prop nodes
									if (curAttributes.Count > 0)
									{
										pnode.Attributes = curAttributes;
										curAttributes = new NodeCollection<AttributeNode>();
									}
									
									pnode.Modifiers = curmods;
									curmods = Modifier.Empty;

									pnode.Names.Add(name);
									pnode.Type = type;

									bool pHasGetter = false;
									bool pHasSetter = false;
									ParseInterfaceAccessors(ref pHasGetter, ref pHasSetter);
									pnode.HasGetter = pHasGetter;
									pnode.HasSetter = pHasSetter;

									if (curtok.ID == TokenID.Semi)
									{
										AssertAndAdvance(TokenID.Semi);
									}
									break;

								default:
									ReportError("Invalid interface member syntax.");
									break;
							}
							break;
					}
					break;
			}
		}
示例#3
0
        private void BuilderProperty(CodeTypeDeclaration entity, InterfacePropertyNode property)
        {
            TypeNode type = (TypeNode)property.Type;
            string propertyname = property.Names[0].GenericIdentifier;

            CodeMemberField field = new CodeMemberField(GetTypeRef(type.GenericIdentifier), "m" +propertyname );
            CodeMemberField fieldinfo = new CodeMemberField();
            field.Attributes = MemberAttributes.Private;
            entity.Members.Add(field);
            CodeCommentStatement comm;
            CodeMemberProperty mp = new CodeMemberProperty();
           
                comm = new CodeCommentStatement("<summary>");
                comm.Comment.DocComment = true;
                fieldinfo.Comments.Add(comm);
                comm = new CodeCommentStatement(type.GenericIdentifier);
                comm.Comment.DocComment = true;
                fieldinfo.Comments.Add(comm);

             if (!string.IsNullOrEmpty(property.Comment))
                    {
                        comm = new CodeCommentStatement(property.Comment);
                        comm.Comment.DocComment = true;
                        fieldinfo.Comments.Add(comm);
                    }

                    StringReader sr = new StringReader(property.DocComment);
                    string value= sr.ReadLine();
                    while (value != null)
                    {
                        if (value.IndexOf("summary>") == -1)
                        {
                            comm = new CodeCommentStatement(value.Replace("///",""));
                            comm.Comment.DocComment = true;
                            fieldinfo.Comments.Add(comm);
                        }
                        value = sr.ReadLine();
                    }

                comm = new CodeCommentStatement("</summary>");
                comm.Comment.DocComment = true;
                fieldinfo.Comments.Add(comm);
            
            mp.Name = propertyname.Substring(0, 1).ToUpper() + propertyname.Substring(1, propertyname.Length - 1);
            string columnName = propertyname;
            foreach (AttributeNode attribute in property.Attributes)
            {
                CodeAttributeDeclaration dad = new CodeAttributeDeclaration(attribute.Name.GenericIdentifier);
                if (attribute.Arguments.Count > 0)
                {
                    foreach (AttributeArgumentNode aan in attribute.Arguments)
                    {
                        ExpressionNode pe = aan.Expression;
                        System.Reflection.PropertyInfo pi = pe.GetType().GetProperty("Value");
                        object data = pi.GetValue(pe, null);
                        dad.Arguments.Add(new CodeAttributeArgument(new CodePrimitiveExpression(data)));
                    }
                }
                mp.CustomAttributes.Add(dad);
                
            }
            //foreach (CodeAttributeDeclaration aitem in property.CustomAttributes)
            //{
            //    mp.CustomAttributes.Add(aitem);
            //    if (aitem.Name.ToLower() == "id" || aitem.Name.ToLower() == "column")
            //    {
            //        if (aitem.Arguments.Count > 0)
            //        {
            //            CodePrimitiveExpression pe = aitem.Arguments[0].Value as CodePrimitiveExpression;
            //            if (pe != null)
            //            {
            //                columnName = pe.Value.ToString();
            //            }
            //            else
            //            {
            //                columnName = property.Name;

            //            }
            //        }
            //        else
            //        {
            //            columnName = property.Name;
            //        }
            //    }
            //}
            mp.Attributes = MemberAttributes.Public;
            mp.Type = GetTypeRef(type.GenericIdentifier);
            entity.Members.Add(mp);
            mp.GetStatements.Add(
                new CodeMethodReturnStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), field.Name)));

            mp.SetStatements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), field.Name),
                                    new CodePropertySetValueReferenceExpression()));
            mp.SetStatements.Add(
                new CodeMethodInvokeExpression(
                    new CodeMethodReferenceExpression(new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "EntityState"), "FieldChange"), new CodePrimitiveExpression(propertyname)));


            fieldinfo.Type = new CodeTypeReference("Peanut.FieldInfo");
            fieldinfo.Name = propertyname.Substring(0, 1).ToLower() + propertyname.Substring(1, propertyname.Length - 1);
            fieldinfo.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            entity.Members.Add(fieldinfo);
            fieldinfo.InitExpression = new CodeObjectCreateExpression(
                new CodeTypeReference("Peanut.FieldInfo"), new CodePrimitiveExpression(mTableName), new CodePrimitiveExpression(columnName));


        }
示例#4
0
        private string GetFieldName(InterfacePropertyNode property)
        {
            string fieldname=null;
            foreach (AttributeNode attr in property.Attributes)
            {
                if (attr.Name.GenericIdentifier.ToLower() == "id" || attr.Name.GenericIdentifier.ToLower() == "column")
                {
                    if (attr.Arguments.Count > 0)
                    {

                        DDW.StringPrimitive pe = (DDW.StringPrimitive)attr.Arguments[0].Expression;
                        if (pe != null)
                        {
                            fieldname = pe.Value.ToString();
                        }
                        else
                        {
                            fieldname = property.Names[0].GenericIdentifier;

                        }

                    }
                    else
                    {
                        fieldname = property.Names[0].GenericIdentifier;
                    }
                }
            }
            return fieldname;
        }
示例#5
0
        private BaseNode ParseInterfaceMember()
        {
            BaseNode ret = null;

            ParsePossibleAttributes(false);
            ParseModifiers();

            switch (curtok.ID)
            {
                case TokenID.RCurly:
                    break;
                case TokenID.Event:
                    // event
                    InterfaceEventNode node = new InterfaceEventNode(curtok);
                    curInterface.Events.Add(node);

                    ApplyAttributes(node);
                    ApplyDocComment(node);

                    node.Modifiers = curmods;
                    curmods = Modifier.Empty;
                    AssertAndAdvance(TokenID.Event);
                    node.Type = ParseType(false);
                    node.Names.Add(ParseQualifiedIdentifier(false, true, true));
                    AssertAndAdvance(TokenID.Semi);
                    ret = node;
                    break;
                default:
                    IType type = ParseType(false);
                    if (type == null)
                    {
                        ReportError("Expected type or ident in interface member definition.");
                    }
                    switch (curtok.ID)
                    {
                        case TokenID.This:
                            {
                                // interface indexer
                                InterfaceIndexerNode iiNode = new InterfaceIndexerNode(curtok);
                                curInterface.Indexers.Add(iiNode);
                                ApplyAttributes(iiNode);
                                ApplyDocComment(iiNode);

                                iiNode.Type = type;
                                Advance(); // over 'this'
                                iiNode.Params = ParseParamList(TokenID.LBracket, TokenID.RBracket);

                                bool hasGetter, hasSetter;
                                NodeCollection<AttributeNode> getAttrs, setAttrs;
                                ParseInterfaceAccessors(out hasGetter, out getAttrs,
                                    out hasSetter, out setAttrs);
                                iiNode.HasGetter = hasGetter;
                                if (getAttrs != null) iiNode.GetterAttributes = getAttrs;
                                iiNode.HasSetter = hasSetter;
                                if (setAttrs != null) iiNode.SetterAttributes = setAttrs;

                                ret = iiNode;
                                break;
                            }

                        default:
                            QualifiedIdentifierExpression name = ParseQualifiedIdentifier(false, true, true);
                            if (name == null || name.Expressions.Count == 0)
                            {
                                ReportError("Expected name or ident in member definition.");
                            }
                            switch (curtok.ID)
                            {
                                case TokenID.Less:
                                case TokenID.LParen:
                                    // method
                                    InterfaceMethodNode mnode = new InterfaceMethodNode(curtok);
                                    curInterface.Methods.Add(mnode);

                                    ApplyAttributes(mnode);
                                    ApplyDocComment(mnode);


                                    mnode.Modifiers = curmods;
                                    curmods = Modifier.Empty;

                                    mnode.Names.Add(name);
                                    mnode.Type = type;

                                    ParsePossibleTypeParameterNode(true, true, false, true);
                                    //if generic applies type parameter collection to the node
                                    ApplyTypeParameters(mnode);

                                    // starts at LParen

                                    mnode.Params = ParseParamList();

                                    ParsePossibleTypeParameterConstraintNode(mnode);
                                    ApplyTypeParameterConstraints(mnode);

                                    ret = mnode;

                                    AssertAndAdvance(TokenID.Semi);
                                    break;

                                case TokenID.LCurly:
                                    {
                                        // property
                                        InterfacePropertyNode pnode = new InterfacePropertyNode(curtok);
                                        curInterface.Properties.Add(pnode);

                                        ApplyAttributes(pnode);
                                        ApplyDocComment(pnode);


                                        pnode.Modifiers = curmods;
                                        curmods = Modifier.Empty;

                                        pnode.Names.Add(name);
                                        pnode.Type = type;

                                        bool hasGetter, hasSetter;
                                        NodeCollection<AttributeNode> getAttrs, setAttrs;
                                        ParseInterfaceAccessors(out hasGetter, out getAttrs,
                                            out hasSetter, out setAttrs);
                                        pnode.HasGetter = hasGetter;
                                        if (getAttrs != null) pnode.GetterAttributes = getAttrs;
                                        pnode.HasSetter = hasSetter;
                                        if (setAttrs != null) pnode.SetterAttributes = setAttrs;

                                        ret = pnode;

                                        if (curtok.ID == TokenID.Semi)
                                        {
                                            AssertAndAdvance(TokenID.Semi);
                                        }
                                        break;
                                    }

                                default:
                                    ReportError("Invalid interface member syntax.");
                                    break;
                            }
                            break;
                    }
                    break;
            }

            return ret;
        }
        public virtual object VisitInterfacePropertyNode(InterfacePropertyNode interfacePropertyNode, object data)
        {
            stackMap.Push(interfacePropertyNode);
            interfacePropertyNode.Attributes.AcceptVisitor(this, data);

            interfacePropertyNode.Type.AcceptVisitor(this, data);

            stackMap.Pop();
            return null;

        }