Example #1
0
 public InterfaceType(string name)
 {
     AttributeValues = new TypeScriptInterfaceAttributeValues
     {
         Name = name
     };
 }
Example #2
0
        private string GetInterfaceName(TypeScriptInterfaceAttributeValues attributeValues)
        {
            if (!string.IsNullOrEmpty(attributeValues.NamePrefix))
            {
                return(attributeValues.NamePrefix + attributeValues.Name);
            }

            return(attributeValues.Name);
        }
Example #3
0
        private TypeScriptInterfaceAttributeValues GetAttributeValues(
            CodeClass codeClass)
        {
            TypeScriptInterfaceAttributeValues result = null;

            CodeAttribute attribute;

            if (TryGetAttribute(
                    codeClass.Attributes,
                    InterfaceAttributeFullName,
                    out attribute))
            {
                result = this.GetInterfaceValues(
                    codeClass,
                    attribute);
            }
            return(result);
        }
Example #4
0
 public InterfaceType(TypeScriptInterfaceAttributeValues values)
 {
     AttributeValues = values;
 }
Example #5
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);
        }