Ejemplo n.º 1
0
        public string Write(ClassDiagramVisitorContext context)
        {
            string color = _class.Color ?? _diagram.GetClassColor(_class);

            StringBuilder buffer = new StringBuilder();

            buffer.AppendLine(string.Format("    class \"{0}\"{1} {2}", _class.Name, color, "{"));

            var definedMembers = _class.Members.InnerList.Where(x => !x.IsInherited).OrderBy(x => x.Name).ToArray();

            if (!IsBaseClassVisible(_class, context))
            {
                var inheritedMembers = _class.Members.InnerList.Where(x => x.IsInherited).OrderBy(x => x.Name);
                WriteClassMembers(inheritedMembers, buffer);

                if (definedMembers.Length > 0)
                {
                    buffer.AppendLine("    --");
                }
            }

            WriteClassMembers(definedMembers, buffer);

            buffer.AppendLine("    }");

            var note = _class.MetaModel.Note != null ? _class.MetaModel.Note.ToString() : null;

            if (note != null)
            {
                buffer.AppendLine(note);
            }

            return buffer.ToString();
        }
Ejemplo n.º 2
0
        private bool IsBaseClassVisible(ClassDescriptor @class, ClassDiagramVisitorContext context)
        {
            if (_diagram.RootClasses.InnerList.Any(x => x.ReflectedType == @class.ReflectedType.BaseType))
                return true;

            if (context.VisitedRelatedClasses.Any(x => x.ReflectedType == @class.ReflectedType.BaseType))
                return true;

            return false;
        }
Ejemplo n.º 3
0
        private void LoadMethods(ClassDiagramVisitorContext context)
        {
            var methods = this.ReflectedType.GetMethods(context.ShowMethodsBindingFlags);

            foreach (var method in methods)
            {
                if(!method.IsProperty()) // weed up the compiler generated methods for properties
                    _methods.Add(new ClassMethodDescriptor(method));
            }
        }
Ejemplo n.º 4
0
        public string Write(ClassDiagramVisitorContext context)
        {
            StringBuilder buffer = new StringBuilder();

            var names = Enum.GetNames(_enumType);

            buffer.AppendLine("enum \"{0}\" {1}".FormatWith(_enumType.Name, "{"));

            foreach (var name in names)
            {
                buffer.AppendLine("     {0}".FormatWith(name));
            }

            buffer.AppendLine("}");

            return buffer.ToString();
        }
Ejemplo n.º 5
0
 protected override void LoadMembers(ClassDiagramVisitorContext context)
 {
     // don't load any member for enums
 }
Ejemplo n.º 6
0
 public ClassDiagramFormatter(ClassDiagram diagram, ClassDiagramVisitorContext context)
 {
     _diagram = diagram;
     _context = context;
 }
Ejemplo n.º 7
0
 protected abstract void Finalize(ClassDiagramVisitorContext current);
Ejemplo n.º 8
0
        protected override void Finalize(ClassDiagramVisitorContext current)
        {
            var formatter = Definition.CreateFormatter(ClassDiagramVisitorContext.Current);

            _buffer.Append(formatter.Format());
        }
Ejemplo n.º 9
0
 public ClassDiagramGeneration(ClassDiagramVisitorContext context)
 {
     _previousVisitorContext            = ClassDiagramVisitorContext.Current;
     ClassDiagramVisitorContext.Current = context;
 }
Ejemplo n.º 10
0
 protected virtual void LoadMembers(ClassDiagramVisitorContext context)
 {
     switch (context.ScanMode)
     {
         case ClassDiagramScanModes.SystemServiceModelMember:
             _members.AddRange(this.ReflectedType.GetFields()
                                                 .Where(x => x.HasAttribute<DataMemberAttribute>() || x.HasAttribute<MessageBodyMemberAttribute>())
                                                 .Select(field => new ClassMemberDescriptor(this.ReflectedType, field, context.GetTypeMetaModel(field.FieldType)))
                              );
             _members.AddRange(this.ReflectedType.GetProperties()
                                                 .Where(x => x.HasAttribute<DataMemberAttribute>() || x.HasAttribute<MessageBodyMemberAttribute>())
                                                 .Select(property => new ClassMemberDescriptor(this.ReflectedType, property, context.GetTypeMetaModel(property.PropertyType)))
                              );
             break;
         default:
             _members.AddRange(this.ReflectedType.GetFields()
                                                 .Select(field => new ClassMemberDescriptor(this.ReflectedType, field, context.GetTypeMetaModel(field.FieldType)))
                              );
             _members.AddRange(this.ReflectedType.GetProperties()
                                                 .Select(property => new ClassMemberDescriptor(this.ReflectedType, property, context.GetTypeMetaModel(property.PropertyType)))
                              );
             break;
     }
 }
Ejemplo n.º 11
0
        public void Visit(ClassDiagramVisitorContext context)
        {
            this.MetaModel = context.GetTypeMetaModel(this.ReflectedType);

            LoadMembers(context);

            bool showInheritance = this.RenderInheritance && this.ReflectedType.BaseType != null;

            if (showInheritance)
            {
                var baseTypeMetaModel = context.GetTypeMetaModel(this.ReflectedType.BaseType);

                showInheritance = !baseTypeMetaModel.HideAsBaseClass && !baseTypeMetaModel.Hidden;
            }

            if (!this.MetaModel.Hidden)
            {
                foreach (ClassMemberDescriptor member in this.Members.InnerList)
                {
                    if (this.MetaModel.TreatAllMembersAsPrimitives)
                        member.TreatAsPrimitive = true;

                    TypeMetaModel metaModel = member.MetaModel;

                    if (!metaModel.Hidden && !member.TreatAsPrimitive)
                    {
                        // if not showing inheritance then show all members
                        // otherwise, only show member that aren't inherited
                        if (!showInheritance || !member.IsInherited)
                        {
                            if (metaModel.IsComplexType && this.GetMemberVisibility(member.Key))
                            {
                                var nextLevel = this.Level + 1;

                                if (member.MemberType.IsEnumerable())
                                {
                                    var enumeratorType = member.MemberType.GetEnumeratorType();
                                    var enumeratorTypeMetaModel = context.GetTypeMetaModel(enumeratorType);

                                    if (enumeratorTypeMetaModel.IsComplexType)
                                    {
                                        context.AddRelated(this, enumeratorType.GetReflected(), ClassDiagramRelationshipTypes.HasMany, nextLevel, member.Name);
                                    }
                                }
                                else
                                {
                                    context.AddRelated(this, member.MemberType.GetReflected(), ClassDiagramRelationshipTypes.HasA, nextLevel, member.Name);
                                }
                            }
                        }
                    }
                }
            }

            if (showInheritance)
            {
                context.AddRelated(this, this.ReflectedType.BaseType.GetReflected(), ClassDiagramRelationshipTypes.Base, this.Level - 1);
            }
        }
Ejemplo n.º 12
0
 protected override void LoadMembers(ClassDiagramVisitorContext context)
 {
     // don't load members if it's an enum
 }
Ejemplo n.º 13
0
        private bool ShouldShowInheritanceInterface(ClassDiagramVisitorContext context, Type type)
        {
            bool showInheritance = this.RenderInheritance && this.ReflectedType.BaseType != null;

            if (showInheritance)
            {
                var interfaceModel = context.GetTypeMetaModel(type);
                showInheritance |= !interfaceModel.HideAsBaseClass && !interfaceModel.Hidden;
            }
            return showInheritance;
        }
Ejemplo n.º 14
0
 protected virtual void LoadMembers(ClassDiagramVisitorContext context)
 {
     switch (context.ScanMode)
     {
         case ClassDiagramScanModes.SystemServiceModelMember:
             _members.AddRange(this.ReflectedType.GetFields()
                                                 .Where(x => x.HasAttribute<DataMemberAttribute>() || x.HasAttribute<MessageBodyMemberAttribute>())
                                                 .Where(x => !x.IsDefined(typeof(CompilerGeneratedAttribute), false))
                                                 .Select(field => new ClassMemberDescriptor(this, field))
                              );
             _members.AddRange(this.ReflectedType.GetProperties()
                                                 .Where(x => x.HasAttribute<DataMemberAttribute>() || x.HasAttribute<MessageBodyMemberAttribute>())
                                                 .Where(x => !x.IsDefined(typeof(CompilerGeneratedAttribute), false))
                                                 .Select(property => new ClassMemberDescriptor(this, property))
                              );
             break;
         case ClassDiagramScanModes.AllMembers:
             _members.AddRange(this.ReflectedType.GetFields(context.ShowMembersBindingFlags)
                                                 .Where(x => !x.IsDefined(typeof(CompilerGeneratedAttribute), false))
                                                 .Select(field => new ClassMemberDescriptor(this, field))
                              );
             _members.AddRange(this.ReflectedType.GetProperties(context.ShowMembersBindingFlags)
                                                 .Where(x => !x.IsDefined(typeof(CompilerGeneratedAttribute), false))
                                                 .Select(property => new ClassMemberDescriptor(this, property))
                              );
             break;
         default:
             _members.AddRange(this.ReflectedType.GetFields()
                                                 .Where(x => !x.IsDefined(typeof(CompilerGeneratedAttribute), false))
                                                 .Select(field => new ClassMemberDescriptor(this, field))
                              );
             _members.AddRange(this.ReflectedType.GetProperties()
                                                 .Where(x => !x.IsDefined(typeof(CompilerGeneratedAttribute), false))
                                                 .Select(property => new ClassMemberDescriptor(this, property))
                              );
             break;
     }
 }
 protected override void Finalize(ClassDiagramVisitorContext current)
 {
     _classes.AddRange(current.VisitedRelatedClasses);
 }
Ejemplo n.º 16
0
 public ClassDiagramSimulation(ClassDiagram diagram)
 {
     _definition = diagram;
     _context = _definition.CreateGenerationContext();
 }
Ejemplo n.º 17
0
 protected abstract void Finalize(ClassDiagramVisitorContext current);
Ejemplo n.º 18
0
 protected override void Finalize(ClassDiagramVisitorContext current)
 {
     var formatter = Definition.CreateFormatter(ClassDiagramVisitorContext.Current);
     _file.Write(formatter.Format());
 }
Ejemplo n.º 19
0
 public ClassDiagramFormatter(ClassDiagram diagram, ClassDiagramVisitorContext context)
 {
     _diagram = diagram;
     _context = context;
 }
Ejemplo n.º 20
0
 public ClassDiagramGeneration(ClassDiagramVisitorContext context)
 {
     _previousVisitorContext = ClassDiagramVisitorContext.Current;
     ClassDiagramVisitorContext.Current = context;
 }