Exemplo n.º 1
0
 public string Stringify(ContractEnumDesc contractDesc)
 {
     return(_template.Render(_contextMaker.Make(new
     {
         contractDesc.Description,
         contractDesc.IsDeprecated,
         contractDesc.DeprecationCause,
         JsonConverter = contractDesc.JsonConverterType?.Name,
         EnumName = _options.ContractNameTempate(contractDesc),
         Fields = contractDesc.Values.Select(_fieldStringify.Stringify),
     })));
 }
 public string Stringify(GenericDesc genericDesc)
 {
     return(_template.Render(_contextMaker.Make(new
     {
         Genericargs = GenericargsStringify(genericDesc.Arguments),
         genericDesc.Description,
         genericDesc.IsDeprecated,
         genericDesc.DeprecationCause,
         ClassName = _options.ContractNameTempate(genericDesc),
         Fields = genericDesc.Fields.Select(_fieldStringify.Stringify),
         genericDesc.CanBePartial,
     })));
 }
Exemplo n.º 3
0
        public string Stringify(ContractDesc contractDesc)
        {
            var baseClass = contractDesc.Base == null ? null : _fieldStringify.FieldTypeStringify(contractDesc.Base);

            return(_template.Render(_contextMaker.Make(new
            {
                contractDesc.Description,
                contractDesc.IsDeprecated,
                contractDesc.DeprecationCause,
                ClassName = _options.ContractNameTempate(contractDesc),
                Fields = contractDesc.Fields.Select(_fieldStringify.Stringify),
                contractDesc.CanBePartial,
                HasBase = contractDesc.Base != null,
                BaseClass = baseClass,
                CustomAttrs = contractDesc.CustomAttributes.Select(_ => _.AttributeStr)
            })));
        }
Exemplo n.º 4
0
        public string FieldTypeStringify(ITypeDesc type, bool isNullable = false)
        {
            switch (type)
            {
            case NullableDesc t:
                return(FieldTypeStringify(t.ElementType, true));

            case ContractDesc t:
                return(_options.ContractNameTempate(t));

            case ConstructedGenericDesc t:
                return($"{_options.ContractNameTempate(t)}<{GenericArgsStringify(t.Arguments)}>");

            case GenericParametrDesc t:
                return(t.Name);

            case ContractEnumDesc t:
                return(nullableType(_options.ContractNameTempate(t)));

            case ArrayDesc t:
                return($"{FieldTypeStringify(t.ElementType)}[]");

            case DictionaryDesc t:
                return($"Dictionary<{FieldTypeStringify(t.KeyType)}, {FieldTypeStringify(t.ValueType)}>");

            case PrimitiveDesc t:
                string ptype;
                switch (t.Type)
                {
                case PrimitiveDesc.Primitives.BOOLEAN:
                    ptype = nullableType("bool");
                    break;

                case PrimitiveDesc.Primitives.INT:
                    ptype = nullableType("int");
                    break;

                case PrimitiveDesc.Primitives.LONG:
                    ptype = nullableType("long");
                    break;

                case PrimitiveDesc.Primitives.DECIMAL:
                    ptype = nullableType("decimal");
                    break;

                case PrimitiveDesc.Primitives.FLOAT:
                    ptype = nullableType("float");
                    break;

                case PrimitiveDesc.Primitives.USHORT:
                    ptype = nullableType("ushort");
                    break;

                case PrimitiveDesc.Primitives.STRING:
                    ptype = "string";
                    break;

                case PrimitiveDesc.Primitives.DATETIME:
                    ptype = nullableType("DateTime");
                    break;

                case PrimitiveDesc.Primitives.BYTE:
                    ptype = nullableType("byte");
                    break;

                default:
                    throw new BuilderException("unknow primitive type");
                }

                return(ptype);

            default:
                return(typeof(object).Name);
            }

            string nullableType(string ptype)
            {
                return(isNullable ? $"{ptype}?" : ptype);
            }
        }