Exemplo n.º 1
0
 private string _CreateParamSignature(ParamMetadata paramInfo)
 {
     return(string.Format("{0}{1}: {2}{3};", paramInfo.name, paramInfo.isNullable ? "?" : "",
                          paramInfo.dataType == DataType.None
             ? _dotNet2TS.RegisterType(paramInfo.ParameterType)
             : DotNet2TS.GetTSTypeNameFromDataType(paramInfo.dataType),
                          paramInfo.dataType != DataType.None && paramInfo.isArray ? "[]" : ""));
 }
Exemplo n.º 2
0
        private string GetFieldDataType(Field fieldInfo)
        {
            var fieldName = fieldInfo.fieldName;
            var fieldType = "any";
            var dataType  = fieldInfo.dataType;

            fieldType = DotNet2TS.GetTSTypeNameFromDataType(dataType);
            return(fieldType);
        }
Exemplo n.º 3
0
        private string GetFieldDataType(Field fieldInfo)
        {
            var fieldName = fieldInfo.fieldName;
            var fieldType = "any";
            var dataType  = fieldInfo.dataType;

            if (fieldInfo.fieldType == FieldType.Navigation)
            {
                fieldType = fieldInfo._TypeScriptDataType;
            }
            else if (fieldInfo.fieldType == FieldType.Object)
            {
                fieldType = fieldInfo._TypeScriptDataType;
            }
            else
            {
                fieldType = DotNet2TS.GetTSTypeNameFromDataType(dataType);
            }
            return(fieldType);
        }
Exemplo n.º 4
0
 public ComplexTypeBuilder(DotNet2TS dotNet2TS)
 {
     _dotNet2TS    = dotNet2TS;
     _complexTypes = new Dictionary <string, string>();
 }
Exemplo n.º 5
0
        public string CreateTypeScript(string comment = null)
        {
            if (_dotNet2TS != null)
            {
                _dotNet2TS.newClientTypeAdded -= _dotnet2TS_newClientTypeAdded;
            }
            _dotNet2TS = new DotNet2TS(_serviceContainer);
            _dotNet2TS.newClientTypeAdded += _dotnet2TS_newClientTypeAdded;
            _sb.Length = 0;
            if (!string.IsNullOrWhiteSpace(comment))
            {
                addComment(_sb, comment);
            }
            WriteStringLine(createHeader());
            WriteLine();

            processMethodArgs();
            var isvcMethods = createISvcMethods();

            //create typed Lists and Dictionaries
            var listTypes = createClientTypes();
            //get interface declarations for all client types
            var sbInterfaceDefs = _dotNet2TS.GetInterfaceDeclarations();

            if (!string.IsNullOrWhiteSpace(sbInterfaceDefs))
            {
                WriteStringLine(@"//******BEGIN INTERFACE REGION******");
                WriteStringLine(sbInterfaceDefs);
                WriteStringLine(@"//******END INTERFACE REGION******");
                WriteLine();
            }
            if (!string.IsNullOrWhiteSpace(isvcMethods))
            {
                WriteStringLine(isvcMethods);
                WriteLine();
            }

            if (!string.IsNullOrWhiteSpace(listTypes))
            {
                WriteStringLine(@"//******BEGIN LISTS REGION******");
                WriteStringLine(listTypes);
                WriteStringLine(@"//******END LISTS REGION******");
                WriteLine();
            }

            //this.WriteStringLine(this.createQueryNames());

            var ctbuilder = new ComplexTypeBuilder(_dotNet2TS);

            _dbSets.ForEach(dbSetInfo =>
            {
                dbSetInfo.fieldInfos.ForEach(fieldInfo =>
                {
                    if (fieldInfo.fieldType == FieldType.Object)
                    {
                        ctbuilder.CreateComplexType(dbSetInfo, fieldInfo, 0);
                    }
                });
            });

            var complexTypes = ctbuilder.GetComplexTypes();

            if (!string.IsNullOrWhiteSpace(complexTypes))
            {
                WriteStringLine(@"//******BEGIN COMPLEX TYPES REGION*****");
                WriteStringLine(complexTypes);
                WriteStringLine(@"//******END COMPLEX TYPES REGION******");
                WriteLine();
            }

            _dbSets.ForEach(dbSetInfo =>
            {
                var res = createEntityType(dbSetInfo);
                //write interface definition for entity
                WriteStringLine(res.Key);
                WriteLine();
                WriteStringLine(createDbSetType(res.Value, dbSetInfo));
                WriteLine();
            });

            WriteStringLine(createIAssocs());
            WriteLine();
            WriteStringLine(createDbContextType());
            WriteLine();
            return(_sb.ToString());
        }