Exemplo n.º 1
0
        public static TypeScriptMethod ChangeCaseCopy(
            OutputSettings outputSettings,
            TypeContext typeContext,
            string baseName,
            TypeScriptType containingType,
            string otherTypeLiteral,
            bool toContainingType,
            bool toCamelCase)
        {
            TypeReference otherType = typeContext.GetLiteralReference(otherTypeLiteral);

            TypeScriptMethod result = new TypeScriptMethod();

            result.Name     = baseName + containingType.SourceType.UnqualifiedSimpleName;
            result.Appender = new CopyMethod.OutputAppender(
                outputSettings,
                typeContext,
                containingType,
                new CaseChangeCopySettings(
                    toContainingType,
                    toCamelCase),
                toContainingType);

            if (toContainingType)
            {
                result.Arguments = new List <TypeScriptMember>()
                {
                    new TypeScriptMember()
                    {
                        Name = "source",
                        Type = otherType
                    }
                };
                result.Type = containingType;
            }
            else
            {
                result.Arguments = new List <TypeScriptMember>()
                {
                    new TypeScriptMember()
                    {
                        Name = "target",
                        Type = otherType
                    }
                };
                result.Type = otherType;
            }

            return(result);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private bool TryGetMember(TypeScriptInterface interfaceContext,
                                  CodeProperty property,
                                  TypeContext typeContext,
                                  out TypeScriptMember member)
        {
            member = null;
            if (property.Access != vsCMAccess.vsCMAccessPublic)
            {
                return(false);
            }

            var getter = property.Getter;

            if (getter == null)
            {
                return(false);
            }

            var values = GetMemberValues(property, typeContext);

            string name;

            if (values.Name != null)
            {
                name = values.Name;
            }
            else
            {
                name = property.Name;
                if (name.StartsWith("@"))
                {
                    name = name.Substring(1);
                }
            }

            TypeReference memberType;

            if (!string.IsNullOrWhiteSpace(values.Type))
            {
                memberType = typeContext.GetLiteralReference(values.Type);
            }
            else
            {
                memberType = typeContext.GetTypeReference(
                    TypeName.ParseDte(getter.Type.AsFullName),
                    interfaceContext);
            }

            member = new TypeScriptMember
            {
                Name = name,
                //FullName = property.FullName,
                Optional = values.Optional,
                Ignore   = values.Ignore,
                Type     = memberType
            };

            if (member.Ignore)
            {
                return(false);
            }

            if (values.CamelCase && values.Name == null)
            {
                member.Name = member.Name.Substring(0, 1).ToLowerInvariant() + member.Name.Substring(1);
            }

            return(true);
        }