Example #1
0
 public void GenerateByteDeclarations()
 {
     // indent to method code body's indention level
     using (mFile.EnterCodeBlock(indentCount: 3))
     {
         GenerateByteDeclarationsCode();
     }
 }
Example #2
0
            public void Generate(bool isSigned = false)
            {
                // indent to method code body's indention level, plus one (l-value statement should be on the line before)
                using (mFile.EnterCodeBlock(indentCount: 3 + 1))
                {
                    GenerateCode(isSigned);

                    mFile.EndStmt();
                }
            }
Example #3
0
        void WriteDeclInheritance()
        {
            int entry_pos = 0;

            // indent the inheritance entries +1 more than the type decl (ie, public struct...)
            using (mFile.EnterCodeBlock())
            {
                entry_pos = WriteDeclInheritanceEntry(entry_pos, SupportsIComparable,
                                                      BuildDeclInheritanceTextCRTP("IComparable"));

                entry_pos = WriteDeclInheritanceEntry(entry_pos, SupportsIEquatable,
                                                      BuildDeclInheritanceTextCRTP("IEquatable"));
            }
        }
Example #4
0
        public static void GenerateObjectPropertyStreamMethod(TextTemplating.TextTransformation ttFile,
                                                              TagElementStreamSubjectType subject, PrimitiveCodeDefinition codeDef, bool hasTNameParam = true)
        {
            if (ttFile == null)
            {
                throw new ArgumentNullException(nameof(ttFile));
            }
            if (codeDef == null)
            {
                throw new ArgumentNullException(nameof(codeDef));
            }

            ttFile.PushIndent("\t");
            ttFile.PushIndent("\t");

            bool is_opt =
                subject == TagElementStreamSubjectType.ElementOpt ||
                subject == TagElementStreamSubjectType.AttributeOpt
            ;

            string method_name = subject.ToString();

            ttFile.WriteLine(
                "public {5} Stream{0}<T>({2} T theObj, Exprs.Expression<Func<T, {1} >> propExpr {3} {4})",
                method_name,
                codeDef.Keyword,
                hasTNameParam.UseStringOrEmpty("TName name,"),
                is_opt.UseStringOrEmpty(", Predicate<{0}> predicate = null", codeDef.Keyword),
                codeDef.IsInteger.UseStringOrEmpty(", NumeralBase numBase=kDefaultRadix"),
                !is_opt ? "void" : "bool"
                );

            ttFile.WriteLine("{");
            ttFile.PushIndent("\t");

            if (hasTNameParam)
            {
                ttFile.WriteLine("Contract.Requires(ValidateNameArg(name));");
                ttFile.WriteLine("");
            }

            if (is_opt)
            {
                ttFile.WriteLine("if (predicate == null)");
                using (var cb1 = ttFile.EnterCodeBlock())
                    ttFile.WriteLine("predicate = x => true;");

                ttFile.NewLine();
                ttFile.WriteLine("bool executed = false;");
            }

            ttFile.WriteLine("var property = Reflection.Util.PropertyFromExpr(propExpr);");
            ttFile.WriteLine("if (IsReading)");
            using (var cb1 = ttFile.EnterCodeBlock(TextTransformationCodeBlockType.Brackets))
            {
                ttFile.WriteLine("var value = default( {0} );", codeDef.Keyword);
                ttFile.WriteLine("{1}Read{0}({2} ref value {3});",
                                 method_name,
                                 is_opt.UseStringOrEmpty("executed = "),
                                 hasTNameParam.UseStringOrEmpty("name,"),
                                 codeDef.IsInteger.UseStringOrEmpty(", numBase")
                                 );
                if (is_opt)
                {
                    ttFile.WriteLine("if (executed)");
                }
                using (var cb2 = ttFile.EnterCodeBlock(TextTransformationCodeBlockType.Brackets))
                    ttFile.WriteLine("property.SetValue(theObj, value, null);");
            }

            ttFile.WriteLine("else if (IsWriting)");
            using (var cb1 = ttFile.EnterCodeBlock())
            {
                ttFile.WriteLine("{2}Write{0}{3}({4} ({1})property.GetValue(theObj, null) {5}{6});",
                                 method_name,                                           // 0
                                 codeDef.Keyword,                                       // 1
                                 is_opt.UseStringOrEmpty("executed = "),                // 2
                                 is_opt.UseStringOrEmpty("OnTrue"),                     // 3
                                 hasTNameParam.UseStringOrEmpty("name,"),               // 4
                                 is_opt.UseStringOrEmpty(", predicate"),                // 5
                                 codeDef.IsInteger.UseStringOrEmpty(", numBase")        // 6
                                 );
            };

            if (is_opt)
            {
                ttFile.NewLine();
                ttFile.WriteLine("return executed;");
            }

            ttFile.PopIndent();
            ttFile.WriteLine("}");

            ttFile.PopIndent();
            ttFile.PopIndent();
        }