Example #1
0
        /// <summary>
        /// Searches the assemblies for types with the <typeparamref name="TAttributeType"/> attribute and creates
        /// the namespace groups
        /// </summary>
        private void CreateNamespaceGroups()
        {
            Dictionary <string, List <TypeAttributePair <TAttributeType> > > namespaceGroups = new Dictionary <string, List <TypeAttributePair <TAttributeType> > >();

            //Loop assemblies
            foreach (Assembly assembly in _assemblies)
            {
                //Get all the enum types
                List <Type> type = assembly.GetTypes().ToList();
                foreach (Type oneEnum in type)
                {
                    //Add them if they are marked for extraction
                    TAttributeType attr = oneEnum.GetCustomAttribute <TAttributeType>();
                    if (attr != null)
                    {
                        TypeAttributePair <TAttributeType> typeAttrPair = new TypeAttributePair <TAttributeType>(oneEnum, attr);

                        string nameSpace = !string.IsNullOrEmpty(attr.OverrideNamespace) ? attr.OverrideNamespace : _defaultNamespace;

                        if (!namespaceGroups.ContainsKey(nameSpace))
                        {
                            namespaceGroups.Add(nameSpace, new List <TypeAttributePair <TAttributeType> >());
                        }
                        namespaceGroups[nameSpace].Add(typeAttrPair);
                    }
                }
            }

            NamespaceGroups = namespaceGroups;
        }
        /// <summary>
        /// Generates the typescript for a given enum's members
        /// </summary>
        /// <param name="typeAttrPair">The type/attr pair to generate</param>
        protected override void GenerateTypescriptForTypeMembers(TypeAttributePair <JavascriptEnumAttribute> typeAttrPair)
        {
            Type type = typeAttrPair.TargetType;
            JavascriptEnumAttribute attr = typeAttrPair.AttributeValue;

            Array enumVals = type.GetEnumValues();

            for (int i = 0; i < enumVals.Length; i++)
            {
                //I couldn't figure out how to get these two pieces
                //of information in one object, so i just cast them to both
                //The underlying type may just be dynamic (based on the Enum)
                int  intVal  = (int)enumVals.GetValue(i);
                Enum enumVal = enumVals.GetValue(i) as Enum;
                AddEnumField(enumVal, intVal);
            }
        }
        /// <summary>
        /// Generates the members of a given type.  By this point, the class piece has been generated.
        /// </summary>
        /// <param name="typeAttr">The type/attr pair</param>
        protected override void GenerateTypescriptForTypeMembers(TypeAttributePair <JavascriptObjectAttribute> typeAttr)
        {
            Type type = typeAttr.TargetType;

            // Create the field descriptions.  In order for these to work, they need to come directly after the summary
            PropertyInfo[] publicProps = type.GetProperties();

            // Now actually create properties
            foreach (PropertyInfo prop in publicProps)
            {
                string name = prop.Name;

                string tsTypeName      = GetTypescriptTypeName(prop.PropertyType);
                string propDescription = GetMemberDescription(prop.DeclaringType, prop);

                // format: /** description */
                AddFormatLine(2, "/** {0} */", propDescription);
                // format:  this.PropName: type;
                AddFormatLine(2, "{0}: {1};", prop.Name, tsTypeName);
            }
        }
 /// <summary>
 /// Generates the members for a given type/attr pair
 /// </summary>
 /// <param name="typeAttr">The type/attr pair to generate</param>
 protected abstract void GenerateTypescriptForTypeMembers(TypeAttributePair <TAttributeType> typeAttr);