public override RtClass GenerateNode(Type element, RtClass result, TypeResolver resolver)
        {
            result = base.GenerateNode(element, result, resolver);
            if (result == null) return null;

            // We add some docs to keep you oriented
            result.Documentation = new RtJsdocNode(){Description = "Result of AngularControllerGenerator activity"};

            // Here we just create ng.IHttpService type name because it is used several times
            var httpServiceType = new RtSimpleTypeName("IHttpService") { Namespace = "angular" };

            // Here we are declaring constructor for our angular service using $http as parameter
            // It is quite simple so no more details
            RtConstructor constructor = new RtConstructor();
            constructor.Arguments.Add(new RtArgument(){Type = httpServiceType,Identifier = new RtIdentifier("$http")});
            constructor.Body = new RtRaw("this.http = $http;");

            // Here we declaring class field for storing $http instance
            RtField httpServiceField = new RtField()
            {
                Type = httpServiceType,
                Identifier = new RtIdentifier("http"),
                AccessModifier = AccessModifier.Private,
                Documentation = new RtJsdocNode() { Description = "Keeps $http instance received on construction"}
            };

            // Here we are adding our constructor and field to resulting class
            result.Members.Add(httpServiceField);
            result.Members.Add(constructor);

            // Also we will add controller registration to our app instance
            // To automatically get it registered in Angular's IoC
            const string initializerFormat =
                "if (window['app']) window['app'].factory('Api.{0}', ['$http', ($http: angular.IHttpService) => new {1}($http)]);";

            RtRaw registration = new RtRaw(String.Format(initializerFormat,element.Name,result.Name));
            
            // Since RtModule.compilationUnits is not typed and could contain any type then we 
            // simply add RtRaw node here with registration glue code
            // app variable is declared in /Scripts/ReinforcedTypings/App.ts since it is used in 
            // corresponding client script
            Context.Location.CurrentModule.CompilationUnits.Add(registration);

            // That's all. here we return node that will be written to target file.
            // Check result in /Scripts/ReinforcedTypings/GeneratedTypings.ts
            return result;
        }
 public override void Visit(RtSimpleTypeName node)
 {
 }
Ejemplo n.º 3
0
        internal RtTypeName ResolveTypeNameInner(Type t, Dictionary <string, RtTypeName> materializedGenerics = null)
        {
            var substitution = t.Substitute(_context.Location.CurrentType);

            if (substitution != null)
            {
                return(substitution);                      // order important!
            }
            if (t.IsGenericParameter)
            {
                var genAt = t.GetCustomAttribute <TsGenericAttribute>(false);
                if (genAt != null)
                {
                    if (genAt.StrongType != null)
                    {
                        return(ResolveTypeName(genAt.StrongType));
                    }
                    if (genAt.Type != null)
                    {
                        return(new RtSimpleTypeName(genAt.Type));
                    }
                }
                return(new RtSimpleTypeName(t.Name));
            }

            if (materializedGenerics == null && _resolveCache.ContainsKey(t))
            {
                return(_resolveCache[t]);
            }

            var td = ConfigurationRepository.Instance.ForType(t);

            if (td != null)
            {
                var ns = t.Namespace;
                if (!td.IncludeNamespace)
                {
                    ns = string.Empty;
                }
                var result = t.GetName(GetConcreteGenericArguments(t, materializedGenerics));

                if (_context.Global.UseModules)
                {
                    var import = _refInspector.EnsureImport(t, result.TypeName, _file);
                    if (_context.Global.DiscardNamespacesWhenUsingModules)
                    {
                        ns = string.Empty;
                    }
                    if (import == null || !import.IsWildcard)
                    {
                        return(Cache(t, result));
                    }

                    result.Prefix = string.IsNullOrEmpty(ns) ? import.WildcardAlias : string.Format("{0}.{1}", import.WildcardAlias, ns);
                    return(Cache(t, result));
                }
                else
                {
                    _refInspector.EnsureReference(t, _file);
                    if (!string.IsNullOrEmpty(td.Namespace))
                    {
                        ns = td.Namespace;
                    }
                    result.Prefix = ns;
                    return(Cache(t, result));
                }
            }
            if (t.IsNullable())
            {
                return(ResolveTypeName(t.GetArg()));
            }
            if (t.IsTuple())
            {
                var args = t.GetGenericArguments().Select(ResolveTypeName);
                return(Cache(t, new RtTuple(args)));
            }
            if (t.IsDictionary())
            {
                if (!t.IsGenericType)
                {
                    _context.Warnings.Add(ErrorMessages.RTW0007_InvalidDictionaryKey.Warn(AnyType, t));
                    return(Cache(t, new RtDictionaryType(AnyType, AnyType)));
                }
                var gargs = t.GetGenericArguments();
                var key   = ResolveTypeName(gargs[0]);
                if (key != NumberType && key != StringType)
                {
                    _context.Warnings.Add(ErrorMessages.RTW0007_InvalidDictionaryKey.Warn(key, t));
                }
                var value = ResolveTypeName(gargs[1]);
                return(Cache(t, new RtDictionaryType(key, value)));
            }
            if (t.IsNongenericEnumerable())
            {
                return(Cache(t, new RtArrayType(AnyType)));
            }
            if (t.IsEnumerable())
            {
                if (t.IsArray)
                {
                    return(Cache(t, new RtArrayType(ResolveTypeName(t.GetElementType()))));
                }
                var enumerable =
                    t.GetInterfaces()
                    .FirstOrDefault(c => c.IsGenericType && c.GetGenericTypeDefinition() == typeof(IEnumerable <>));
                if (enumerable == null)
                {
                    if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                    {
                        enumerable = t;
                    }
                }
                if (enumerable == null)
                {
                    return(Cache(t, new RtArrayType(AnyType)));
                }
                return(Cache(t, new RtArrayType(ResolveTypeName(enumerable.GetArg()))));
            }

            if (typeof(MulticastDelegate).IsAssignableFrom(t.BaseType))
            {
                var methodInfo = t.GetMethod("Invoke");
                return(Cache(t, ConstructFunctionType(methodInfo)));
            }


            if (t.IsGenericType && !t.IsGenericTypeDefinition)
            {
                var def        = t.GetGenericTypeDefinition();
                var tsFriendly = ResolveTypeNameInner(def) as RtSimpleTypeName;
                if (tsFriendly != null && tsFriendly != AnyType)
                {
                    var parametrized = new RtSimpleTypeName(tsFriendly.TypeName,
                                                            t.GetGenericArguments().Select(c => ResolveTypeNameInner(c, null)).ToArray())
                    {
                        Prefix = tsFriendly.Prefix
                    };
                    return(Cache(t, parametrized));
                }
            }

            _context.Warnings.Add(ErrorMessages.RTW0003_TypeUnknown.Warn(t.FullName));

            return(Cache(t, AnyType));
        }
Ejemplo n.º 4
0
        internal RtTypeName ResolveTypeNameInner(Type t, Dictionary <string, RtTypeName> materializedGenerics = null, bool usePromiseType = true)
        {
            var substitution = Context.Project.Substitute(t, this);

            if (substitution != null)
            {
                return(substitution);                      // order important!
            }
            if (Context.CurrentBlueprint != null)
            {
                var localSubstitution = Context.CurrentBlueprint.Substitute(t, this);
                if (localSubstitution != null)
                {
                    return(localSubstitution);
                }
            }
            if (t.IsGenericParameter)
            {
                var genAt = t.GetCustomAttribute <TsGenericAttribute>(false);
                if (genAt != null)
                {
                    if (genAt.StrongType != null)
                    {
                        return(ResolveTypeName(genAt.StrongType));
                    }
                    if (genAt.Type != null)
                    {
                        return(new RtSimpleTypeName(genAt.Type));
                    }
                }
                return(new RtSimpleTypeName(t.Name));
            }

            if (materializedGenerics == null && _resolveCache.ContainsKey(t))
            {
                return(_resolveCache[t]);
            }

            var bp = Context.Project.Blueprint(t, false);

            if (bp != null && bp.ThirdParty != null)
            {
                var result = bp.GetName(bp.IsExportedExplicitly ? null : GetConcreteGenericArguments(t, materializedGenerics));
                if (Context.Global.UseModules)
                {
                    _file.EnsureImport(t, result.TypeName);
                }
                _file.EnsureReference(t);
                return(Cache(t, result));
            }
            else
            {
                var declaration = bp == null ? null : bp.TypeAttribute;
                if (declaration != null)
                {
                    var ns = t.Namespace;
                    if (!string.IsNullOrEmpty(declaration.Namespace))
                    {
                        ns = declaration.Namespace;
                    }
                    if (!declaration.IncludeNamespace)
                    {
                        ns = string.Empty;
                    }
                    var result = bp.GetName(bp.IsExportedExplicitly ? null : GetConcreteGenericArguments(t, materializedGenerics));

                    if (Context.Global.UseModules)
                    {
                        var import = _file.EnsureImport(t, result.TypeName);
                        if (Context.Global.DiscardNamespacesWhenUsingModules)
                        {
                            ns = string.Empty;
                        }
                        if (import == null || !import.IsWildcard)
                        {
                            result.Prefix = ns;
                            return(Cache(t, result));
                        }

                        result.Prefix = string.IsNullOrEmpty(ns)
                            ? import.WildcardAlias
                            : string.Format("{0}.{1}", import.WildcardAlias, ns);
                        return(Cache(t, result));
                    }
                    else
                    {
                        _file.EnsureReference(t);
                        if (!string.IsNullOrEmpty(declaration.Namespace))
                        {
                            ns = declaration.Namespace;
                        }
                        result.Prefix = ns;
                        return(Cache(t, result));
                    }
                }
            }

            if (t.IsNullable())
            {
                return(ResolveTypeName(t.GetArg()));
            }
            if (t.IsTuple())
            {
                var args = t._GetGenericArguments().Select(ResolveTypeName);
                return(Cache(t, new RtTuple(args)));
            }
            if (t.IsDictionary())
            {
                if (!t._IsGenericType())
                {
                    Context.Warnings.Add(ErrorMessages.RTW0007_InvalidDictionaryKey.Warn(AnyType, t));
                    return(Cache(t, new RtDictionaryType(AnyType, AnyType)));
                }
                var  gargs     = t._GetGenericArguments();
                bool isKeyEnum = gargs[0]._IsEnum();
                var  key       = ResolveTypeName(gargs[0]);
                if (key != NumberType && key != StringType && !isKeyEnum)
                {
                    Context.Warnings.Add(ErrorMessages.RTW0007_InvalidDictionaryKey.Warn(key, t));
                }
                var value = ResolveTypeName(gargs[1]);
                return(Cache(t, new RtDictionaryType(key, value, isKeyEnum)));
            }
            if (t.IsNongenericEnumerable())
            {
                return(Cache(t, new RtArrayType(AnyType)));
            }
            if (t.IsEnumerable())
            {
                if (t.IsArray)
                {
                    return(Cache(t, new RtArrayType(ResolveTypeName(t.GetElementType()))));
                }
                var enumerable =
                    t._GetInterfaces()
                    .FirstOrDefault(c => c._IsGenericType() && c.GetGenericTypeDefinition() == typeof(IEnumerable <>));
                if (enumerable == null)
                {
                    if (t._IsGenericType() && t.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                    {
                        enumerable = t;
                    }
                }
                if (enumerable == null)
                {
                    return(Cache(t, new RtArrayType(AnyType)));
                }
                return(Cache(t, new RtArrayType(ResolveTypeName(enumerable.GetArg()))));
            }
            if (t._IsAsyncType())
            {
                var deliveredTypeOfTask =
                    t._IsGenericType() ? ResolveTypeName(t.GetArg(), usePromiseType) : ResolveTypeName(typeof(void));

                if (usePromiseType || Context.Global.AutoAsync)
                {
                    return(Cache(t, new RtAsyncType(deliveredTypeOfTask)));
                }
                else
                {
                    // Unfold the generics value of the task but do NOT cache. Caching would interfere with
                    // parameter resolving, which always uses promise type.
                    return(deliveredTypeOfTask);
                }
            }

            if (typeof(MulticastDelegate)._IsAssignableFrom(t._BaseType()))
            {
                var methodInfo = t._GetMethod("Invoke");
                return(Cache(t, ConstructFunctionType(methodInfo, materializedGenerics)));
            }


            if (t._IsGenericType() && !t._IsGenericTypeDefinition())
            {
                var def        = t.GetGenericTypeDefinition();
                var tsFriendly = ResolveTypeNameInner(def) as RtSimpleTypeName;
                if (tsFriendly != null && tsFriendly != AnyType && tsFriendly != UnknownType)
                {
                    var parametrized = new RtSimpleTypeName(tsFriendly.TypeName,
                                                            t._GetGenericArguments().Select(c => ResolveTypeNameInner(c, null)).ToArray())
                    {
                        Prefix = tsFriendly.Prefix
                    };
                    return(Cache(t, parametrized));
                }
            }

            if (t._IsEnum())
            {
                return(Cache(t, NumberType));
            }

            Context.Warnings.Add(ErrorMessages.RTW0003_TypeUnknown.Warn(t.FullName, _anyOrUnknown));

            return(Cache(t, _anyOrUnknown));
        }
Ejemplo n.º 5
0
 public abstract void Visit(RtSimpleTypeName node);
        /// <summary>
        ///     Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to
        ///     WriterWrapper (3rd argument) using TypeResolver if necessary
        /// </summary>
        /// <param name="element">Element code to be generated to output</param>
        /// <param name="result">Resulting node</param>
        /// <param name="resolver">Type resolver</param>
        public override RtField GenerateNode(MemberInfo element, RtField result, TypeResolver resolver)
        {
            if (Context.CurrentBlueprint.IsIgnored(element))
            {
                return(null);
            }
            result.IsStatic = element.IsStatic();
            result.Order    = Context.CurrentBlueprint.GetOrder(element);

            var doc = Context.Documentation.GetDocumentationMember(element);

            if (doc != null)
            {
                RtJsdocNode jsdoc = new RtJsdocNode();
                if (doc.HasInheritDoc())
                {
                    jsdoc.AddTag(DocTag.Inheritdoc);
                }
                if (doc.HasSummary())
                {
                    jsdoc.Description = doc.Summary.Text;
                }
                result.Documentation = jsdoc;
            }

            var        t                = GetType(element);
            RtTypeName type             = null;
            var        propName         = new RtIdentifier(element.Name);
            bool       isNameOverridden = false;
            var        tp               = Context.CurrentBlueprint.ForMember <TsPropertyAttribute>(element);

            if (tp != null)
            {
                if (tp.StrongType != null)
                {
                    type = resolver.ResolveTypeName(tp.StrongType);
                }
                else if (!string.IsNullOrEmpty(tp.Type))
                {
                    type = new RtSimpleTypeName(tp.Type);
                }

                type = tp.TypeInferers.Infer(element, resolver) ?? type;

                if (!string.IsNullOrEmpty(tp.Name))
                {
                    propName.IdentifierName = tp.Name;
                    isNameOverridden        = true;
                }
            }

            if (!Context.SpecialCase)
            {
                propName.IsNullable = HasToBeNullable(tp, t) ||
                                      Context.Global.AutoOptionalProperties && element.IsReferenceForcedNullable();
            }

            if (type == null)
            {
                type = resolver.ResolveTypeName(t);
            }

            if (!isNameOverridden)
            {
                if (element is PropertyInfo)
                {
                    propName.IdentifierName =
                        Context.ConditionallyConvertPropertyNameToCamelCase(propName.IdentifierName);
                }
                propName.IdentifierName = Context.CurrentBlueprint.CamelCaseFromAttribute(element, propName.IdentifierName);
                propName.IdentifierName = Context.CurrentBlueprint.PascalCaseFromAttribute(element, propName.IdentifierName);
            }

            if (this.Context.Location.CurrentClass != null)
            {
                this.FillInitialization(element, result, resolver, t, tp);
            }
            result.Identifier     = propName;
            result.AccessModifier = Context.SpecialCase ? AccessModifier.Public : element.GetModifier();
            result.Type           = type;
            AddDecorators(result, Context.CurrentBlueprint.DecoratorsFor(element));
            return(result);
        }
        /// <summary>
        ///     Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to
        ///     WriterWrapper (3rd argument) using TypeResolver if necessary
        /// </summary>
        /// <param name="element">Element code to be generated to output</param>
        /// <param name="result">Resulting node</param>
        /// <param name="resolver">Type resolver</param>
        public override RtArgument GenerateNode(ParameterInfo element, RtArgument result, TypeResolver resolver)
        {
            if (Context.CurrentBlueprint.IsIgnored(element))
            {
                return(null);
            }
            var        name = element.Name;
            RtTypeName type;
            var        isNullable = false;

            var fa           = Context.CurrentBlueprint.ForMember(element);
            var defaultValue = GetDefaultValue(element, fa);

            if (fa != null)
            {
                if (!string.IsNullOrEmpty(fa.Name))
                {
                    name = fa.Name;
                }

                if (!string.IsNullOrEmpty(fa.Type))
                {
                    type = new RtSimpleTypeName(fa.Type);
                }
                else if (fa.StrongType != null)
                {
                    type       = resolver.ResolveTypeName(fa.StrongType);
                    isNullable = element.IsOptional;
                }
                else
                {
                    type = resolver.ResolveTypeName(element.ParameterType);
                }
                type = fa.TypeInferers.Infer(element, resolver) ?? type;
            }
            else
            {
                type       = resolver.ResolveTypeName(element.ParameterType);
                isNullable = element.IsOptional;
            }
            if (element.GetCustomAttribute <ParamArrayAttribute>() != null)
            {
                result.IsVariableParameters = true;
            }
            result.Identifier = new RtIdentifier(name);
            result.Type       = type;
            if (isNullable && defaultValue == null)
            {
                result.Identifier.IsNullable = true;
            }
            if (defaultValue != null)
            {
                //if parameter is having enum type then simple string value assignment is now right
                //so for Enum type result.DefaultValue should be equal to ENUME_NAME+"."+DefaultValue
                if (element.ParameterType._IsEnum())
                {
                    result.DefaultValue = result.Type + "." + defaultValue;
                }
                else
                {
                    result.DefaultValue = defaultValue;
                }
            }
            AddDecorators(result, Context.CurrentBlueprint.DecoratorsFor(element));
            return(result);
        }
        /// <summary>
        ///     Main code generator method. This method should write corresponding TypeScript code for element (1st argument) to
        ///     WriterWrapper (3rd argument) using TypeResolver if necessary
        /// </summary>
        /// <param name="element">Element code to be generated to output</param>
        /// <param name="result">Resulting node</param>
        /// <param name="resolver">Type resolver</param>
        public override RtField GenerateNode(MemberInfo element, RtField result, TypeResolver resolver)
        {
            if (element.IsIgnored())
            {
                return(null);
            }
            result.IsStatic = element.IsStatic();
            result.Order    = element.GetOrder();

            var doc = Context.Documentation.GetDocumentationMember(element);

            if (doc != null)
            {
                RtJsdocNode jsdoc = new RtJsdocNode {
                    Description = doc.Summary.Text
                };
                result.Documentation = jsdoc;
            }

            var        t                = GetType(element);
            RtTypeName type             = null;
            var        propName         = new RtIdentifier(element.Name);
            bool       isNameOverridden = false;
            var        tp               = ConfigurationRepository.Instance.ForMember <TsPropertyAttribute>(element);

            if (tp != null)
            {
                if (tp.StrongType != null)
                {
                    type = resolver.ResolveTypeName(tp.StrongType);
                }
                else if (!string.IsNullOrEmpty(tp.Type))
                {
                    type = new RtSimpleTypeName(tp.Type);
                }

                type = tp.TypeInferers.Infer(element, resolver) ?? type;

                if (!string.IsNullOrEmpty(tp.Name))
                {
                    propName.IdentifierName = tp.Name;
                    isNameOverridden        = true;
                }
                if (tp.NilForceNullable.HasValue && !Context.SpecialCase)
                {
                    propName.IsNullable = tp.NilForceNullable.Value;
                }
            }

            if (type == null)
            {
                type = resolver.ResolveTypeName(t);
            }
            if (tp != null && !tp.NilForceNullable.HasValue)
            {
                if (!propName.IsNullable && t.IsNullable() && !Context.SpecialCase)
                {
                    propName.IsNullable = true;
                }
            }
            if (!isNameOverridden)
            {
                if (element is PropertyInfo)
                {
                    propName.IdentifierName =
                        Context.ConditionallyConvertPropertyNameToCamelCase(propName.IdentifierName);
                }
                propName.IdentifierName = element.CamelCaseFromAttribute(propName.IdentifierName);
                propName.IdentifierName = element.PascalCaseFromAttribute(propName.IdentifierName);
            }
            result.Identifier     = propName;
            result.AccessModifier = Context.SpecialCase ? AccessModifier.Public : element.GetModifier();
            result.Type           = type;
            AddDecorators(result, ConfigurationRepository.Instance.DecoratorsFor(element));
            return(result);
        }
        private RtTypeName ResolveTypeNameInner(Type t)
        {
            if (_resolveCache.ContainsKey(t))
            {
                return(_resolveCache[t]);
            }

            var td = ConfigurationRepository.Instance.ForType(t);

            if (td != null)
            {
                var ns = t.Namespace;
                if (!td.IncludeNamespace)
                {
                    ns = string.Empty;
                }
                if (!string.IsNullOrEmpty(td.Namespace))
                {
                    ns = td.Namespace;
                }

                var result = t.GetName(GetConcreteGenericArguments(t));
                result.Namespace = ns;
                return(Cache(t, result));
            }
            if (t.IsNullable())
            {
                return(ResolveTypeName(t.GetArg()));
            }
            if (t.IsDictionary())
            {
                if (!t.IsGenericType)
                {
                    return(Cache(t, new RtDictionaryType(AnyType, AnyType)));
                }
                var gargs = t.GetGenericArguments();
                var key   = ResolveTypeName(gargs[0]);
                var value = ResolveTypeName(gargs[1]);
                return(Cache(t, new RtDictionaryType(key, value)));
            }
            if (t.IsNongenericEnumerable())
            {
                return(Cache(t, new RtArrayType(AnyType)));
            }
            if (t.IsEnumerable())
            {
                if (t.IsArray)
                {
                    return(Cache(t, new RtArrayType(ResolveTypeName(t.GetElementType()))));
                }
                var enumerable =
                    t.GetInterfaces()
                    .FirstOrDefault(c => c.IsGenericType && c.GetGenericTypeDefinition() == typeof(IEnumerable <>));
                if (enumerable == null)
                {
                    if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                    {
                        enumerable = t;
                    }
                }
                if (enumerable == null)
                {
                    return(Cache(t, new RtArrayType(AnyType)));
                }
                return(Cache(t, new RtArrayType(ResolveTypeName(enumerable.GetArg()))));
            }

            if (t.IsGenericParameter)
            {
                var genAt = t.GetCustomAttribute <TsGenericAttribute>(false);
                if (genAt != null)
                {
                    if (genAt.StrongType != null)
                    {
                        return(Cache(t, ResolveTypeName(genAt.StrongType)));
                    }
                    if (genAt.Type != null)
                    {
                        return(Cache(t, new RtSimpleTypeName(genAt.Type)));
                    }
                }
                return(Cache(t, new RtSimpleTypeName(t.Name)));
            }

            if (typeof(MulticastDelegate).IsAssignableFrom(t.BaseType))
            {
                var methodInfo = t.GetMethod("Invoke");
                return(Cache(t, ConstructFunctionType(methodInfo)));
            }


            if (t.IsGenericType && !t.IsGenericTypeDefinition)
            {
                var def        = t.GetGenericTypeDefinition();
                var tsFriendly = ResolveTypeNameInner(def) as RtSimpleTypeName;
                if (tsFriendly != null && tsFriendly != AnyType)
                {
                    var parametrized = new RtSimpleTypeName(tsFriendly.TypeName,
                                                            t.GetGenericArguments().Select(ResolveTypeNameInner).ToArray())
                    {
                        Namespace = tsFriendly.Namespace
                    };
                    return(Cache(t, parametrized));
                }
            }

            _context.Warnings.Add(ErrorMessages.RTW0003_TypeUnknown.Warn(t.FullName));

            return(Cache(t, AnyType));
        }
Ejemplo n.º 10
0
        public override RtClass GenerateNode(Type element, RtClass result, TypeResolver resolver)
        {
            result = base.GenerateNode(element, result, resolver);
            if (result == null)
            {
                return(null);
            }

            // We add some docs to keep you oriented
            result.Documentation = new RtJsdocNode()
            {
                Description = "Result of AngularControllerGenerator activity"
            };

            // Here we just create ng.IHttpService type name because it is used several times
            var httpServiceType = new RtSimpleTypeName("IHttpService")
            {
                Namespace = "angular"
            };

            // Here we are declaring constructor for our angular service using $http as parameter
            // It is quite simple so no more details
            RtConstructor constructor = new RtConstructor();

            constructor.Arguments.Add(new RtArgument()
            {
                Type = httpServiceType, Identifier = new RtIdentifier("$http")
            });
            constructor.Body = new RtRaw("this.http = $http;");

            // Here we declaring class field for storing $http instance
            RtField httpServiceField = new RtField()
            {
                Type           = httpServiceType,
                Identifier     = new RtIdentifier("http"),
                AccessModifier = AccessModifier.Private,
                Documentation  = new RtJsdocNode()
                {
                    Description = "Keeps $http instance received on construction"
                }
            };

            // Here we are adding our constructor and field to resulting class
            result.Members.Add(httpServiceField);
            result.Members.Add(constructor);

            // Also we will add controller registration to our app instance
            // To automatically get it registered in Angular's IoC
            const string initializerFormat =
                "if (window['app']) window['app'].factory('Api.{0}', ['$http', ($http: angular.IHttpService) => new {1}($http)]);";

            RtRaw registration = new RtRaw(String.Format(initializerFormat, element.Name, result.Name));

            // Since RtModule.compilationUnits is not typed and could contain any type then we
            // simply add RtRaw node here with registration glue code
            // app variable is declared in /Scripts/ReinforcedTypings/App.ts since it is used in
            // corresponding client script
            Context.Location.CurrentModule.CompilationUnits.Add(registration);

            // That's all. here we return node that will be written to target file.
            // Check result in /Scripts/ReinforcedTypings/GeneratedTypings.ts
            return(result);
        }