Exemple #1
0
        public TypeContext BuildContext()
        {
            var typeContext = new TypeContext(this.Settings);
            var partialClasses = new Dictionary<string, CodeClass>();

            new SolutionTraverser(this.Solution, (ns) =>
            {
                new NamespaceTraverser(ns, (codeClass) =>
                {
                    CodeAttribute attribute;
                    if (!TryGetAttribute(codeClass.Attributes, InterfaceAttributeFullName, out attribute))
                        return;

                    var values = GetInterfaceValues(codeClass, attribute);
                    var interfaceType = new InterfaceType(values);

                    if (!typeContext.ContainsInterfaceType(codeClass.FullName))
                        typeContext.AddInterfaceType(codeClass.FullName, interfaceType);
                });
            });

            return typeContext;
        }
Exemple #2
0
 public void AddInterfaceType(string typeFullName, InterfaceType interfaceType)
 {
     interfaceTypes.Add(typeFullName, interfaceType);
 }
Exemple #3
0
 public bool TryGetInterfaceType(string typeFullName, out InterfaceType interfaceType)
 {
     return interfaceTypes.TryGetValue(typeFullName, out interfaceType);
 }
Exemple #4
0
        private void BuildCodeClass(TypeContext typeContext, CodeClass codeClass, CodeClass owner = null, bool forcedProcessing = false)
        {
            if (codeClass == null) return;
            CodeAttribute attribute;
            InterfaceType interfaceType = null;
            if (owner != null)
            {
                var tsType = typeContext.GetTypeScriptType(owner.FullName);
                if (tsType != null)
                    interfaceType = new InterfaceType(codeClass.Name);
            }
            if (forcedProcessing)
            {
                var values = new TypeScriptInterfaceAttributeValues
                {
                    Name = codeClass.Name,
                    Module = Settings.DefaultModule ?? "T4TS",
                    NamePrefix = Settings.DefaultInterfaceNamePrefix ?? string.Empty
                };
                interfaceType = new InterfaceType(values);
            }

            if (TryGetAttribute(codeClass.Attributes, InterfaceAttributeFullName, out attribute))
            {
                var values = GetInterfaceValues(codeClass, attribute);
                interfaceType = new InterfaceType(values);
            }
            else if (Settings.ProcessDataContracts && TryGetAttribute(codeClass.Attributes, "System.Runtime.Serialization.DataContractAttribute", out attribute))
            {
                var values = new TypeScriptInterfaceAttributeValues
                {
                    Name = codeClass.Name,
                    Module = Settings.DefaultModule ?? "T4TS",
                    NamePrefix = Settings.DefaultInterfaceNamePrefix ?? string.Empty
                };
                interfaceType = new InterfaceType(values);
            }
            if (interfaceType != null)
            {
                // Process parent classes anyway if it has not TypeScriptAttribute or DataContractAttribute
                if (Settings.ProcessParentClasses)
                {
                    CodeClass parentClass = null;
                    if (codeClass.Bases.Count > 0)
                        parentClass = codeClass.Bases.Item(1) as CodeClass;
                    if (parentClass != null && parentClass.FullName != "System.Object")
                    {
                        BuildCodeClass(typeContext, parentClass, null, true);
                    }
                }

                if (!typeContext.ContainsInterfaceType(codeClass.FullName))
                    typeContext.AddInterfaceType(codeClass.FullName, interfaceType);

                foreach (var subCodeElement in codeClass.Members)
                {
                    var subCodeClass = subCodeElement as CodeClass;
                    if (subCodeClass != null && subCodeClass.Access == vsCMAccess.vsCMAccessPublic)
                        BuildCodeClass(typeContext, subCodeClass, codeClass);
                    var subCodeEnum = subCodeElement as CodeEnum;
                    if (subCodeEnum != null && subCodeEnum.Access == vsCMAccess.vsCMAccessPublic)
                        BuildCodeEnum(typeContext, subCodeEnum, codeClass);
                }
            }
        }