Exemple #1
0
        public ICodeBlockBuilder ForEach(INamedReference collection, Action <INamedReference, ICodeBlockBuilder> itemVariableAndInnerBlock)
        {
            var variableName = new NamedReference($"v{Guid.NewGuid():N}");

            Write("foreach(var ").Write(variableName).Write(" in ").Write(collection).Write(")").NewLine();

            InnerBlock(i => itemVariableAndInnerBlock(variableName, i));

            return(NewLine());
        }
Exemple #2
0
        /// <summary>
        /// var new_var_name = assignment;
        /// </summary>
        /// <param name="assignment"></param>
        /// <returns></returns>
        public INamedReference Var(Action <ICodeBlockBuilder> assignment)
        {
            var variableName = new NamedReference($"v{Guid.NewGuid():N}");

            Write("var ").Write(variableName).Write(" = ");
            assignment(this);

            EndStatement();

            return(variableName);
        }
        protected INamedReference GetTypeReference(Type t)
        {
            INamedReference reference;

            if (!m_typeReferences.TryGetValue(t, out reference))
            {
                m_registeredTypes.Add(t);
                var sb = new StringBuilder();
                CreateTypeString(t, sb);
                reference = new NamedReference(sb.ToString());
                m_typeReferences.Add(t, reference);
            }

            return(reference);
        }