Example #1
0
        public void ShouldVisitEachProperty()
        {
            var codeClass = DTETransformer.BuildDteClass(typeof(M));
            int callCount = 0;

            var expectedNames = new string[] { "A", "B", "C" };

            Traversal.TraverseProperties(
                codeClass.Members,
                (p) => { Assert.AreEqual(expectedNames[callCount++], p.Name); });
            Assert.AreEqual(3, callCount);
        }
Example #2
0
 private void PopulateMembers(
     CodeElements members,
     TypeScriptInterface interfaceOutput,
     TypeContext typeContext)
 {
     Traversal.TraverseProperties(
         members,
         (property) =>
     {
         TypeScriptMember member;
         if (TryGetMember(
                 interfaceOutput,
                 property,
                 typeContext,
                 out member))
         {
             interfaceOutput.Fields.Add(member);
         }
     });
 }
Example #3
0
        public TypeScriptInterface Build(
            CodeClass codeClass,
            TypeContext typeContext)
        {
            TypeScriptInterface result = null;

            TypeScriptInterfaceAttributeValues attributeValues = this.GetAttributeValues(codeClass);

            if (attributeValues != null)
            {
                string moduleName = attributeValues.Module;
                if (String.IsNullOrEmpty(moduleName) &&
                    codeClass.Namespace != null)
                {
                    moduleName = codeClass.Namespace.FullName;
                }

                bool interfaceCreated;
                result = typeContext.GetOrCreateInterface(
                    moduleName,
                    TypeName.ParseDte(codeClass.FullName),
                    GetInterfaceName(attributeValues),
                    out interfaceCreated);

                if (!String.IsNullOrEmpty(attributeValues.Extends))
                {
                    result.Parent = typeContext.GetLiteralReference(attributeValues.Extends);
                }
                else if (codeClass.Bases.Count > 0)
                {
                    // Getting the first item directly causes problems in unit tests.  Get it from an enumerator.
                    IEnumerator enumerator = codeClass.Bases.GetEnumerator();
                    enumerator.MoveNext();
                    TypeName parentTypeName = TypeName.ParseDte(
                        ((CodeElement)enumerator.Current).FullName);

                    if (BuilderHelper.IsValidBaseType(parentTypeName))
                    {
                        result.Parent = typeContext.GetTypeReference(
                            parentTypeName,
                            result);
                    }
                }

                result.IndexedType = this.GetIndexedType(
                    result,
                    codeClass,
                    typeContext);

                Traversal.TraverseProperties(
                    codeClass.Members,
                    (property) =>
                {
                    TypeScriptMember member;
                    if (TryGetMember(
                            result,
                            property,
                            typeContext,
                            out member))
                    {
                        result.Fields.Add(member);
                    }
                });
            }
            return(result);
        }