Ejemplo n.º 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Scripter()
        {
            this.Types = new HashSet <TsType>();

            // Add mappings for primitives
            this.TypeLookup = new Dictionary <Type, TsType>()
            {
                { typeof(void), TsPrimitive.Void },
                { typeof(object), TsPrimitive.Any },
                { typeof(string), TsPrimitive.String },
                { typeof(bool), TsPrimitive.Boolean },
                { typeof(byte), TsPrimitive.Number },
                { typeof(short), TsPrimitive.Number },
                { typeof(int), TsPrimitive.Number },
                { typeof(long), TsPrimitive.Number },
                { typeof(float), TsPrimitive.Number },
                { typeof(double), TsPrimitive.Number },
            };

            this.RegisterTypeMapping(CreateGenericDictionaryType(), typeof(Dictionary <,>));
            this.RegisterTypeMapping(TsPrimitive.Any, typeof(ValueType));

            // initialize the scripter with default implementations
            this.Reader    = new TypeReader();
            this.Formatter = new TsFormatter();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Scripter(Compilation compilation)
        {
            Types        = new HashSet <TsType>();
            _compilation = compilation;

            // Add mappings for primitives
            TypeLookup = new Dictionary <ITypeSymbol, TsType>(new TypeSymbolEqualityComparer())
            {
                { _compilation.GetSpecialType(SpecialType.System_Void), TsPrimitive.Void },
                { _compilation.GetSpecialType(SpecialType.System_Object), TsPrimitive.Any },
                { _compilation.GetSpecialType(SpecialType.System_String), TsPrimitive.String },
                { _compilation.GetSpecialType(SpecialType.System_Boolean), TsPrimitive.Boolean },
                { _compilation.GetSpecialType(SpecialType.System_Byte), TsPrimitive.Number },
                { _compilation.GetSpecialType(SpecialType.System_Single), TsPrimitive.Number },
                { _compilation.GetSpecialType(SpecialType.System_Int16), TsPrimitive.Number },
                { _compilation.GetSpecialType(SpecialType.System_Int32), TsPrimitive.Number },
                { _compilation.GetSpecialType(SpecialType.System_Int64), TsPrimitive.Number },
                { _compilation.GetSpecialType(SpecialType.System_UInt16), TsPrimitive.Number },
                { _compilation.GetSpecialType(SpecialType.System_UInt32), TsPrimitive.Number },
                { _compilation.GetSpecialType(SpecialType.System_UInt64), TsPrimitive.Number },
                { _compilation.GetSpecialType(SpecialType.System_Decimal), TsPrimitive.Number },
                { _compilation.GetSpecialType(SpecialType.System_Double), TsPrimitive.Number },
                { _compilation.GetSpecialType(SpecialType.System_DateTime), TsPrimitive.Date },
            };

            AddAdditionalTypesAsKnown(new[]
            {
                new Tuple <Type, TsPrimitive>(typeof(Guid), TsPrimitive.String),
                new Tuple <Type, TsPrimitive>(typeof(Uri), TsPrimitive.String),
                new Tuple <Type, TsPrimitive>(typeof(Task), TsPrimitive.Void),
            });

            // initialize the scripter with default implementations
            Formatter = new LowerCamelCaseFormatter(false);
        }
Ejemplo n.º 3
0
 void IDisposable.Dispose()
 {
     if (mFormatter != null)
     {
         mFormatter.Context.IndentLevel--;
         mFormatter = null;
     }
 }
Ejemplo n.º 4
0
 public StringBuilderContext(TsFormatter writer)
 {
     Writer         = writer;
     PriorContext   = writer.Context;
     IndentLevel    = PriorContext != null ? PriorContext.IndentLevel : 0;
     StringBuilder  = new StringBuilder();
     Writer.Context = this;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Configures the scripter to use a particular formatter
 /// </summary>
 /// <param name="formatter">The formatter</param>
 /// <returns></returns>
 public Scripter UsingFormatter(TsFormatter formatter)
 {
     this.Formatter = formatter;
     return(this);
 }
Ejemplo n.º 6
0
 public IndentContext(TsFormatter formatter)
 {
     mFormatter = formatter;
     mFormatter.Context.IndentLevel++;
 }