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