예제 #1
0
        private void frmClassEditor_Load(object sender, EventArgs e)
        {
            int selfId = 0;
            if (editmode) {
                selfId=cls.Id;
            }
            else
            {
                cls = new Class();
            }

            tbClassName.Text = cls.Name;
            tbClassAlias.Text = cls.Alias;
            tbClassComment.Text = cls.Comment;

            cbClassAccessModifier.DataSource = context.AccessModifierSet;
            cbClassAccessModifier.DisplayMember = "Name";

            cbClassAncestor.DataSource = context.ClassSet.Where(x=>x.Id!=selfId);
            cbClassAncestor.DisplayMember = "Name";
        }
예제 #2
0
 /// <summary>
 /// Create a new Class object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 public static Class CreateClass(global::System.Int32 id, global::System.String name)
 {
     Class @class = new Class();
     @class.Id = id;
     @class.Name = name;
     return @class;
 }
예제 #3
0
 public ClassEditor(ModelContext context, Class cls)
     : this(context)
 {
     this.cls = cls;
     editmode = true;
 }
예제 #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ClassSet EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToClassSet(Class @class)
 {
     base.AddObject("ClassSet", @class);
 }
예제 #5
0
 public MethodEditor(ModelContext context, Class cls)
 {
     this.context = context;
     this.cls = cls;
     InitializeComponent();
 }
예제 #6
0
 public MemberEditor(ModelContext context, Class cls)
 {
     InitializeComponent();
     this.context = context;
     this.cls = cls;
 }
예제 #7
0
        private string BuildClassExport(Class cls)
        {
            //StringBuilder sbNs = new StringBuilder();
            StringBuilder sbMembers = new StringBuilder();
            StringBuilder sbMethods = new StringBuilder();

            HashSet<String> ns = new HashSet<String>();
            ns.Add("System");

            string hostNs = null;
            string hostClass = null;
            ParseClassName(cls, out hostNs, out hostClass);

            string ancestorName = null;
            if (cls.Ancestor != null && cls.Ancestor.Name != ObjectClass)
            {
                string ancestorNs = null;
                ParseClassName(cls.Ancestor, out ancestorNs, out ancestorName);
                ns.Add(ancestorNs);
            }

            // append members
            foreach (Member member in cls.Members)
            {
                sbMembers.Append("    ").Append(member.AccessModifier.Name).Append(' ');
                string memberTypeAlias = member.MemberType.Class.Alias;
                string memberTypeClass = null;
                string memberTypeNs = null;
                ParseClassName(member.MemberType.Class, out memberTypeNs, out memberTypeClass);
                ns.Add(memberTypeNs);
                if (String.IsNullOrEmpty(memberTypeAlias)) memberTypeAlias = memberTypeClass;
                sbMembers.Append(memberTypeAlias).Append(' ').Append(member.Name).AppendLine(";");
            }

            // append methods
            foreach (Method method in cls.Methods)
            {
                StringBuilder sbMethodComment = new StringBuilder();
                StringBuilder sbMethodDeclaration = new StringBuilder();

                sbMethodComment.AppendLine("    /// <summary>");
                foreach (string line in method.Comment.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                {
                    sbMethodComment.Append("    /// ").AppendLine(line);
                }
                sbMethodComment.AppendLine("    /// </summary>");

                sbMethodDeclaration.Append("    ").Append(method.AccessModifier.Name).Append(' ');
                bool returns = false;
                if (method.ReturnType != null)
                {
                    returns = true;
                    string methodTypeAlias = method.ReturnType.Class.Alias;
                    string methodTypeClass = null;
                    string methodTypeNs = null;
                    ParseClassName(method.ReturnType.Class, out methodTypeNs, out methodTypeClass);
                    ns.Add(methodTypeNs);
                    if (String.IsNullOrEmpty(methodTypeAlias)) methodTypeAlias = methodTypeClass;
                    sbMethodDeclaration.Append(methodTypeAlias);
                }
                else
                {
                    sbMethodDeclaration.Append("void");
                }
                sbMethodDeclaration.Append(' ').Append(method.Name).Append('(');

                int paramCount = 0;
                foreach (Parameter param in method.Parameters)
                {
                    string paramAlias = param.Type.Alias;
                    string paramClass = null;
                    string paramNs = null;
                    ParseClassName(param.Type, out paramNs, out paramClass);
                    ns.Add(paramNs);
                    if (String.IsNullOrEmpty(paramAlias)) paramAlias = paramClass;
                    if (paramCount++ > 0) sbMethodDeclaration.Append(", ");
                    sbMethodDeclaration.Append(paramAlias).Append(' ').Append(param.Name);
                    sbMethodComment.Append("    ////<param name=\"").Append(param.Name).AppendLine("\"></param>");
                }

                sbMethodDeclaration.AppendLine(") { }").AppendLine();
                if (returns) sbMethodComment.AppendLine("    /// <returns></returns>");

                sbMethods.Append(sbMethodComment.ToString()).Append(sbMethodDeclaration.ToString());
            }

            StringBuilder output = new StringBuilder();
            foreach (string s in ns.ToArray())
            {
                output.Append("using ").Append(s).AppendLine(";");
            }
            output.AppendLine();

            output.Append("namespace ").Append(hostNs).AppendLine(" {").AppendLine();

            // start writting class
            if (!String.IsNullOrEmpty(cls.Comment))
            {
                output.AppendLine("  /// <summary>");
                foreach (string line in cls.Comment.Split(new string[]{Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries))
                {
                    output.Append("  /// ").AppendLine(line);
                }
                output.AppendLine("  /// </summary>");
            }
            output.Append("  ").Append(cls.AccessModifier.Name).Append(" class ").Append(hostClass);
            if (ancestorName != null)
            {
                output.Append(" : ").Append(ancestorName);
            }
            output.AppendLine(" {").AppendLine();

            output.AppendLine(sbMembers.ToString());
            output.AppendLine(sbMethods.ToString());

            // end writting class
            output.AppendLine("  }").AppendLine().AppendLine("}");

            return output.ToString();
        }
예제 #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cls"></param>
 /// <param name="ns"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 private void ParseClassName(Class cls, out string ns, out string name)
 {
     int i = cls.Name.LastIndexOf('.');
     if (i >= 0)
     {
         ns = cls.Name.Substring(0, i);
         name = cls.Name.Substring(i + 1);
     }
     else
     {
         ns = null;
         name = cls.Name;
     }
 }