コード例 #1
0
        protected void Add_GetHashCode(string expression)
        {
            CodeWriter cw = new CsCodeWriter();

            cw.Open("unchecked");
            cw.WriteLine(ReturnValue(expression));
            cw.Close();
            Target.AddMethod("GetHashCode", "int")
            .WithOverride()
            .WithBody(cw);
        }
コード例 #2
0
        public void CreateArray(CsCodeWriter c, string prefix)
        {
            c.Open(prefix + "new []");
            var lastIdx = Arguments.Length - 1;

            for (var index = 0; index <= lastIdx; index++)
            {
                var i = Arguments[index];
                if (index < lastIdx)
                {
                    i += ",";
                }
                c.WriteLine(i);
            }

            c.DecIndent();
            c.WriteLine("};");
        }
コード例 #3
0
        private void Add_ReadJson()
        {
            var valueTypeName = Cfg.UnitTypes.Value;
            var cw            = new CsCodeWriter();

            cw.Open("if (reader.ValueType == typeof(string))");
            cw.SingleLineIf($"objectType == typeof({valueTypeName})",
                            ReturnValue($"{valueTypeName}.Parse((string)reader.Value)"));
            cw.Close();
            cw.WriteLine("throw new NotImplementedException();");

            var m = Target.AddMethod("ReadJson", "object", "Reads the JSON representation of the object.")
                    .WithOverride()
                    .WithBody(cw);

            m.AddParam <JsonReader>("reader", Target, "The JsonReader to read from.");
            m.AddParam <Type>("objectType", Target, "Type of the object.");
            m.AddParam <object>("existingValue", Target, "The existing value of object being read.");
            m.AddParam <JsonSerializer>("serializer", Target, "The calling serializer.");
        }