Exemplo n.º 1
0
 /// <summary>
 /// Visit a <see cref="NRInterface"/>.
 /// </summary>
 /// <param name="nrInterface">The <see cref="NRInterface"/> to visit.</param>
 public void Visit(NRInterface nrInterface)
 {
     OutputLine("NRInterface");
     indent++;
     PrintMembers(nrInterface);
     indent--;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Visit a <see cref="NRInterface"/>.
        /// </summary>
        /// <param name="nrInterface">The <see cref="NRInterface"/> to visit.</param>
        public void Visit(NRInterface nrInterface)
        {
            if (!string.IsNullOrWhiteSpace(nrInterface.DeclaringTypeFullName) && (currentType != null && nrInterface.DeclaringTypeFullName != currentType.FullName || currentType == null))
            {
                // Do not output the interface since it is nested and we are not inside the parent type.
                return;
            }
            NRTypeBase oldCurrentType = currentType;

            currentType = nrInterface;

            VisitAttributes(nrInterface);

            OutputLine(nrInterface.Declaration());
            OutputLine("{");
            indent++;
            foreach (NRProperty nrProperty in nrInterface.Properties)
            {
                nrProperty.Accept(this);
            }
            foreach (NREvent nrEvent in nrInterface.Events)
            {
                nrEvent.Accept(this);
            }
            foreach (NRMethod nrMethod in nrInterface.Methods)
            {
                nrMethod.Accept(this);
            }
            indent--;
            OutputLine("}");
            OutputEmptyLineAfterType();

            currentType = oldCurrentType;
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Gets the <see cref="NRInterface" /> as a C# string. Only the head of the interface
        ///     is returned.
        /// </summary>
        /// <param name="nrInterface">The interface to get the code for.</param>
        /// <returns>A string representing the interface header.</returns>
        public static string Declaration(this NRInterface nrInterface)
        {
            string accessModifier    = AddSpace(nrInterface.AccessModifier.Declaration( ));
            string genericDecl       = GetGenericDefinition(nrInterface);
            string baseDecl          = GetImplementedInterfaces(nrInterface);
            string genericConstraint = GetGenericConstraint(nrInterface);

            return(string.Format("{0}interface {1}{2}{3}{4}", accessModifier, nrInterface.Name, genericDecl, baseDecl, genericConstraint));
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Determines if an interface will be reflected.
 /// </summary>
 /// <param name="nrInterface">The interface to test.</param>
 /// <returns><c>True</c> if the interface should be reflected.</returns>
 public bool Reflect(NRInterface nrInterface)
 {
     if (Filter.Reflect(nrInterface))
     {
         ReflectedInterfaces++;
         return(true);
     }
     IgnoredInterfaces++;
     return(false);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Visit a <see cref="NRInterface"/>.
 /// </summary>
 /// <param name="nrInterface">The <see cref="NRInterface"/> to visit.</param>
 public void Visit(NRInterface nrInterface)
 {
     VisitAttributes(nrInterface);
     Output(ToString(nrInterface.AccessModifier) + "interface " + nrInterface.Name + GetGenericDefinition(nrInterface));
     PrintImplementedInterfaces(nrInterface);
     VisitTypeParameters(nrInterface);
     OutputLine("");
     OutputLine("{");
     indent++;
     foreach (NRProperty nrProperty in nrInterface.Properties)
     {
         nrProperty.Accept(this);
     }
     foreach (NREvent nrEvent in nrInterface.Events)
     {
         nrEvent.Accept(this);
     }
     foreach (NRMethod nrMethod in nrInterface.Methods)
     {
         nrMethod.Accept(this);
     }
     indent--;
     OutputLine("}");
 }
Exemplo n.º 6
0
 /// <summary>
 ///     Initializes a new instance of <see cref="NRRealization" />.
 /// </summary>
 /// <param name="baseType">The base type of the generalization.</param>
 /// <param name="implementingType">The implementing type of the realization.</param>
 public NRRealization(NRInterface baseType, NRSingleInheritanceType implementingType)
 {
     BaseType         = baseType;
     ImplementingType = implementingType;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Determines if an interface will be reflected.
 /// </summary>
 /// <param name="nrInterface">The interface to test.</param>
 /// <returns>
 /// <c>True</c> if the interface should be reflected.
 /// </returns>
 public bool Reflect(NRInterface nrInterface)
 {
     return(filter.Reflect(nrInterface));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Determines if an interface will be reflected.
 /// </summary>
 /// <param name="nrInterface">The interface to test.</param>
 /// <returns>
 /// <c>True</c> if the interface should be reflected.
 /// </returns>
 public bool Reflect(NRInterface nrInterface)
 {
   return filter.Reflect(nrInterface);
 }
Exemplo n.º 9
0
 /// <summary>
 ///     Determines if an interface will be reflected.
 /// </summary>
 /// <param name="nrInterface">The interface to test.</param>
 /// <returns><c>True</c> if the interface should be reflected.</returns>
 public bool Reflect(NRInterface nrInterface)
 {
     return(Reflect(FilterElements.Interface, nrInterface));
 }
Exemplo n.º 10
0
 /// <summary>
 ///     Determines if an interface will be reflected.
 /// </summary>
 /// <param name="nrInterface">The interface to test.</param>
 /// <returns><c>True</c> if the interface should be reflected.</returns>
 public bool Reflect(NRInterface nrInterface)
 {
     return(true);
 }
Exemplo n.º 11
0
        // ========================================================================
        // Methods

        #region === Methods

        /// <summary>
        /// Extracts the relationships between the types of <paramref name="nrAssembly"/>.
        /// </summary>
        /// <param name="nrAssembly">The relationships are extracted from the types within
        ///                          this <see cref="NRAssembly"/>.</param>
        /// <param name="createNesting">Set to <c>true</c> to create nesting relationships.</param>
        /// <param name="createGeneralization">Set to <c>true</c> to create generalization relationships.</param>
        /// <param name="createRealization">Set to <c>true</c> to create realization relationships.</param>
        /// <param name="createAssociation">Set to <c>true</c> to create association relationships.</param>
        /// <returns>The extracted relationships.</returns>
        public NRRelationships CreateRelationships(NRAssembly nrAssembly, bool createNesting = true, bool createGeneralization = true, bool createRealization = true, bool createAssociation = true)
        {
            NRRelationships nrRelationships          = new NRRelationships();
            Dictionary <string, NRTypeBase> entities = nrAssembly.Types.ToDictionary(nrTypeBase => nrTypeBase.FullName);

            //Create the nesting relationships
            if (createNesting)
            {
                foreach (NRTypeBase nrTypeBase in entities.Values)
                {
                    if (!String.IsNullOrWhiteSpace(nrTypeBase.DeclaringTypeFullName))
                    {
                        if (entities.ContainsKey(nrTypeBase.DeclaringTypeFullName))
                        {
                            NRSingleInheritanceType parent = entities[nrTypeBase.DeclaringTypeFullName] as NRSingleInheritanceType;
                            if (parent != null)
                            {
                                nrRelationships.Nestings.Add(new NRNesting(parent, nrTypeBase));
                            }
                        }
                    }
                }
            }

            //Create the generalization relationships
            if (createGeneralization)
            {
                foreach (NRSingleInheritanceType derivedType in nrAssembly.SingleInheritanceTypes)
                {
                    if (derivedType.BaseType != null && derivedType.BaseType.FullName != null)
                    {
                        if (entities.ContainsKey(derivedType.BaseType.FullName))
                        {
                            NRSingleInheritanceType baseType = entities[derivedType.BaseType.FullName] as NRSingleInheritanceType;
                            if (baseType != null)
                            {
                                nrRelationships.Generalizations.Add(new NRGeneralization(baseType, derivedType));
                            }
                        }
                    }
                }

                // Interfaces may derive from other interfaces as well.
                foreach (NRInterface derivedInterface in nrAssembly.Interfaces)
                {
                    foreach (NRTypeUsage implementedInterface in derivedInterface.ImplementedInterfaces)
                    {
                        if (entities.ContainsKey(implementedInterface.FullName))
                        {
                            NRInterface nrInterface = entities[implementedInterface.FullName] as NRInterface;
                            if (nrInterface != null)
                            {
                                nrRelationships.Generalizations.Add(new NRGeneralization(nrInterface, derivedInterface));
                            }
                        }
                    }
                }
            }

            //Create the realization relationships
            if (createRealization)
            {
                foreach (NRSingleInheritanceType implementingType in nrAssembly.SingleInheritanceTypes)
                {
                    foreach (NRTypeUsage implementedInterface in implementingType.ImplementedInterfaces)
                    {
                        if (entities.ContainsKey(implementedInterface.FullName))
                        {
                            NRInterface nrInterface = entities[implementedInterface.FullName] as NRInterface;
                            if (nrInterface != null)
                            {
                                nrRelationships.Realizations.Add(new NRRealization(nrInterface, implementingType));
                            }
                        }
                    }
                }
            }

            //Create the association relationships
            if (createAssociation)
            {
                foreach (NRSingleInheritanceType startType in nrAssembly.SingleInheritanceTypes)
                {
                    foreach (NRField nrField in startType.Fields)
                    {
                        string fullName = nrField.TypeFullName;
                        bool   array    = false;
                        if (fullName.EndsWith("[]"))
                        {
                            //Array!
                            fullName = fullName.Substring(0, fullName.IndexOf('['));
                            array    = true;
                        }
                        if (fullName.Contains("["))
                        {
                            //Generic!
                            fullName = fullName.Substring(0, fullName.IndexOf('['));
                        }
                        if (entities.ContainsKey(fullName))
                        {
                            NRTypeBase    endType     = entities[fullName];
                            NRAssociation association = new NRAssociation
                            {
                                StartType       = startType,
                                EndMultiplicity = array ? "*" : "1",
                                StartRole       = nrField.Name,
                                EndType         = endType
                            };
                            nrRelationships.Associations.Add(association);
                        }
                    }
                }
            }

            return(nrRelationships);
        }