Example #1
0
 public void WriteTo(WriterContext context)
 {
   Cat c = (Cat)context.Data;
   using (StreamWriter w = new StreamWriter(context.HttpStream, Encoding.UTF8))
   {
     w.Write(c.Name);
   }
 }
Example #2
0
        protected override void WriteTo(object item, XmlWriter writer, WriterContext context)
        {
            if (item == null)
            throw new ArgumentNullException("item");

              XmlSerializer serializer = GetSerializer(item.GetType());
              serializer.Serialize(writer, item);
        }
Example #3
0
 public void WriteTo(WriterContext context)
 {
   Cat c = (Cat)context.Data;
   using (StreamWriter w = new StreamWriter(context.HttpStream, Encoding.UTF8))
   {
     // Absolute meaningless post data
     w.Write(string.Format("<html><body><p>{0}</p></body></html>", c.Name));
   }
 }
Example #4
0
 public void WriteTo(WriterContext context)
 {
     if (context.Data == null)
     return;
       if (!(context.Data is byte[]))
     throw new ArgumentException(string.Format("Expected byte[] in ByteArrayCodec. Got {0}.", context.Data.GetType()));
       using (Stream input = new MemoryStream((byte[])context.Data))
     input.CopyTo(context.HttpStream);
 }
Example #5
0
 public void WriteTo(WriterContext context)
 {
   if (context.Data == null)
     return;
   if (!(context.Data is Stream))
     throw new ArgumentException(string.Format("Expected Stream in StreamCodec. Got {0}.", context.Data.GetType()));
   Stream input = context.Data as Stream;
   input.CopyTo(context.HttpStream);
 }
    public void WriteTo(WriterContext context)
    {
      if (context.Data == null)
        return;

      Type t = context.Data.GetType();
      MultipartFormDataSerializer Serializer = new MultipartFormDataSerializer(t);

      string charset = context.CodecParameters["Charset"];

      Encoding enc = (charset != null ? Encoding.GetEncoding(charset) : context.Session.DefaultEncoding);

      Serializer.Serialize(context.HttpStream, context.Data, enc, CodecArgument as string, context.Session.SerializerSettings);
    }
Example #7
0
        public virtual List <WritingInfo> Write(IMemberDefinition member, IWriterContextService writerContextService, bool writeDocumentation, bool showCompilerGeneratedMembers = false)
        {
            this.writerContextService = writerContextService;
            this.writerContext        = writerContextService.GetWriterContext(member, Language);

            if (member is TypeDefinition)
            {
                this.CurrentType = member as TypeDefinition;
            }

            this.currentWritingInfo = new WritingInfo(member);
            UpdateWritingInfo(this.writerContext, this.currentWritingInfo);
            this.writingInfos = new List <WritingInfo>();
            this.writingInfos.Add(this.currentWritingInfo);

            WriteInternal(member, writeDocumentation, showCompilerGeneratedMembers);

            return(writingInfos);
        }
Example #8
0
        /// <summary>
        /// Handles the specified input.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public Result Handle(Input input)
        {
            var Result    = new Result();
            var tableName = input.TableName;

            if (tableName.IsNullOrEmpty())
            {
                Result.ErrorMessage = "Herhangi bir tablo ismi seçilmelidir";
                return(Result);
            }

            var connectionInfo = FindProcedureContainerDatabaseConnectionInfo(input.TableName);

            if (connectionInfo == null)
            {
                return(Result);
            }

            var info = DbItemNameInfoParser.Parse(tableName);

            var writerContext = new WriterContext
            {
                Config = new TableConfig
                {
                    TableName        = info.Name,
                    SchemaName       = info.SchemaName,
                    DatabaseName     = info.DatabaseName ?? DatabaseNames.BOA,
                    DatabaseEnumName = connectionInfo.DatabaseName,
                    ServerNameForTakeTableInformation = ServerNames.GetServerNameOfConnectionString(connectionInfo.ConnectionStringDev)
                }
            };

            new NamingConvention {
                Context = writerContext
            }.InitializeNames();

            var generator = new SelectByKeySql(writerContext);

            Result.GeneratedSQLCode = generator.Generate();

            return(Result);
        }
Example #9
0
            protected override void Write(BinaryWriter w, object o, WriterContext ctx)
            {
                Array val = (Array)o;

                if (val.GetType().GetElementType().IsPrimitive)
                {
                    w.Write(SecondaryId);
                    _binaryFormatter.Serialize(w.BaseStream, o);
                    return;
                }

                w.Write(PrimaryId);
                WriteObject(w, val.GetType().GetElementType(), ctx);

                Write7BitEncodedInt(w, val.Length);
                for (int i = 0; i < val.Length; i++)
                {
                    WriteObject(w, val.GetValue(i), ctx);
                }
            }
        public void can_continue_on_a_partial_write()
        {
            var buffer  = new byte[] { 1, 2, 3, 4, 5, 6, 7 };
            var mgr     = new BufferManager(100, 10);
            var context = new WriterContext(mgr);

            context.BytesLeftToEnqueue = 4;

            var sut = new ByteBufferWriter(buffer, 0, buffer.Length);

            context.BytesLeftToEnqueue = 4;
            sut.Write(context);
            context.BytesLeftToEnqueue = 10;
            var actual = sut.Write(context);

            actual.Should().BeTrue();
            var packet = context.GetPackets()[1];

            packet.Buffer[packet.Offset + 2].Should().Be(7);
        }
		public override WriterContext GetWriterContext(IMemberDefinition member, ILanguage language)
		{
			AssemblySpecificContext assemblyContext = new AssemblySpecificContext();
			ModuleSpecificContext moduleContext = new ModuleSpecificContext();
			TypeSpecificContext typeContext = new TypeSpecificContext(Utilities.GetDeclaringTypeOrSelf(member));

			DecompiledType decompiledType = GetDecompiledType(member, language);

			Dictionary<string, MethodSpecificContext> methodContexts = new Dictionary<string, MethodSpecificContext>();
			Dictionary<string, Statement> decompiledStatements = new Dictionary<string, Statement>();

			foreach (KeyValuePair<string, DecompiledMember> decompiledPair in decompiledType.DecompiledMembers)
			{
				methodContexts.Add(decompiledPair.Key, decompiledPair.Value.Context);
				decompiledStatements.Add(decompiledPair.Key, decompiledPair.Value.Statement);
			}

			WriterContext writerContext = new WriterContext(assemblyContext, moduleContext, typeContext, methodContexts, decompiledStatements);

			return writerContext;
		}
        public override WriterContext GetWriterContext(IMemberDefinition member, ILanguage language)
        {
            AssemblySpecificContext assemblyContext = new AssemblySpecificContext();
            ModuleSpecificContext   moduleContext   = new ModuleSpecificContext();
            TypeSpecificContext     typeContext     = new TypeSpecificContext(Utilities.GetDeclaringTypeOrSelf(member));

            DecompiledType decompiledType = GetDecompiledType(member, language);

            Dictionary <string, MethodSpecificContext> methodContexts       = new Dictionary <string, MethodSpecificContext>();
            Dictionary <string, Statement>             decompiledStatements = new Dictionary <string, Statement>();

            foreach (KeyValuePair <string, DecompiledMember> decompiledPair in decompiledType.DecompiledMembers)
            {
                methodContexts.Add(decompiledPair.Key, decompiledPair.Value.Context);
                decompiledStatements.Add(decompiledPair.Key, decompiledPair.Value.Statement);
            }

            WriterContext writerContext = new WriterContext(assemblyContext, moduleContext, typeContext, methodContexts, decompiledStatements);

            return(writerContext);
        }
        public override void Visit(RtClass node)
        {
            if (node == null)
            {
                return;
            }
            Visit(node.Documentation);
            var prev = Context;

            Context = WriterContext.Class;
            AppendTabs();
            if (prev == WriterContext.Module)
            {
                Write("export ");
            }
            Write("class ");
            Visit(node.Name);
            if (node.Extendee != null)
            {
                Write(" extends ");
                Visit(node.Extendee);
            }
            if (node.Implementees.Count > 0)
            {
                Write(" implements ");
                SequentialVisit(node.Implementees, ", ");
            }
            Br(); AppendTabs();
            Write("{"); Br();
            Tab();
            var members = node.Members.OrderBy(c => c is RtConstructor ? 0 : 1);

            foreach (var rtMember in members)
            {
                Visit(rtMember);
            }
            UnTab();
            AppendTabs(); WriteLine("}");
            Context = prev;
        }
Example #14
0
        protected void UpdateWritingInfo(WriterContext writerContext, WritingInfo writingInfo)
        {
            foreach (MethodSpecificContext methodContext in writerContext.MethodContexts.Values)
            {
                if (methodContext != null)
                {
                    writingInfo.ControlFlowGraphs.Add(methodContext.Method, methodContext.ControlFlowGraph);
                    writingInfo.MethodsVariableDefinitionToNameMap.Add(methodContext.Method, methodContext.VariableDefinitionToNameMap);
                }
            }

            foreach (IMemberDefinition memberWithExceptionsWhileDecompiling in writerContext.TypeContext.ExceptionWhileDecompiling)
            {
                if (!writingInfo.MembersWithExceptions.Contains(memberWithExceptionsWhileDecompiling.MetadataToken.ToUInt32()))
                {
                    writingInfo.MembersWithExceptions.Add(memberWithExceptionsWhileDecompiling.MetadataToken.ToUInt32());
                }
            }

            writingInfo.AutoImplementedProperties.UnionWith(writerContext.TypeContext.AutoImplementedProperties);
            writingInfo.AutoImplementedEvents.UnionWith(writerContext.TypeContext.AutoImplementedEvents);
        }
Example #15
0
            protected override void Write(BinaryWriter w, object o, WriterContext ctx)
            {
                Color c = (Color)o;

                if (c.IsEmpty || c.IsKnownColor)
                {
                    w.Write(SecondaryId);
                    if (c.IsEmpty)
                    {
                        w.Write(-1);                          //isempty marker
                    }
                    else
                    {
                        w.Write((int)c.ToKnownColor());
                    }
                }
                else
                {
                    w.Write(PrimaryId);
                    w.Write(c.ToArgb());
                }
            }
Example #16
0
        public UpdateSqlCustom(WriterContext context, CustomUpdateMethod customUpdateMethod)
            : base(context)
        {
            CustomUpdate = customUpdateMethod;

            var updateColumns = customUpdateMethod.UpdateColumnNames.Split(',');
            var whereColumns  = customUpdateMethod.WhereColumnNames.Split(',');

            foreach (var columnName in updateColumns)
            {
                if (Context.Table.Columns.All(x => x.ColumnName != columnName))
                {
                    throw new ArgumentException("InvalidColumnName:" + columnName);
                }
            }

            foreach (var columnName in whereColumns)
            {
                if (Context.Table.Columns.All(x => x.ColumnName != columnName))
                {
                    throw new ArgumentException("InvalidColumnName:" + columnName);
                }
            }

            WhereColumns = from c in Context.Table.Columns
                           where whereColumns.Contains(c.ColumnName)
                           select c;

            ProcedureParameters = from c in Context.Table.Columns
                                  where updateColumns.Contains(c.ColumnName) ||
                                  whereColumns.Contains(c.ColumnName) ||
                                  Names.GenericUpdateInformationColumns.Contains(c.ColumnName)
                                  select c;

            _updateColumns = from c in Context.Table.Columns
                             where updateColumns.Contains(c.ColumnName) ||
                             Names.GenericUpdateInformationColumns.Contains(c.ColumnName)
                             select c;
        }
        public void WriteTypeDeclaration(TypeDefinition type, IWriterContextService writerContextService)
        {
            this.writerContextService = writerContextService;
            this.writerContext        = writerContextService.GetWriterContext(type, Language);
            this.currentWritingInfo   = new WritingInfo(type);

            WriteAttributes(type, new string[] { "System.Reflection.DefaultMemberAttribute" });

            membersStack.Push(type);
            if (this.ShouldWriteAsDelegate(type))
            {
                WriteDelegate(type);
                WriteLine();
                membersStack.Pop();
                return;
            }

            WriteTypeDeclaration(type);
            WriteLine();

            membersStack.Pop();
        }
        public void serialize_Simplistic_filter()
        {
            var bufferManager = new BufferManager(8192, 1);
            var context       = new WriterContext(bufferManager);
            var buffer        = bufferManager.Dequeue();

            bufferManager.Enqueue(buffer);
            var expected = new byte[]
            {
                0,                                                                                                 //flags,
                0, 2,                                                                                              // sequence number,
                2,                                                                                                 //destination length,
                (byte)'M', (byte)'Q',
                0, 16,                                                                                             // filter length
                (byte)'l', (byte)'a', (byte)'s', (byte)'t', (byte)'_', (byte)'n', (byte)'a', (byte)'m', (byte)'e', //filter part 1
                (byte)':', (byte)'k', (byte)'a', (byte)'l', (byte)'l', (byte)'e', (byte)';',                       //filter part 2
                6,                                                                                                 //payload length
                (byte)'m', (byte)'o', (byte)'t', (byte)'h', (byte)'e', (byte)'r'                                   //payload
            };

            var sut = new MessageFrame();

            sut.SequenceNumber = 2;
            sut.Destination    = "MQ";
            sut.Properties.Add("last_name", "kalle");
            var payload = Encoding.ASCII.GetBytes("mother");

            sut.PayloadBuffer = new ArraySegment <byte>(payload, 0, payload.Length);
            var actual = sut.Write(context);

            for (int i = 0; i < expected.Length; i++)
            {
                if (expected[i] != buffer.Array[i])
                {
                    throw new InvalidOperationException("Differs at " + i);
                }
            }
        }
Example #19
0
        /// <summary>
        /// Get all instances of the requested type.
        /// </summary>
        /// <param name="context">The context, such as the parent entity, from which these entities are being loaded.</param>
        /// <returns>List of entities.</returns>
        public override IEnumerable <DataElement> GetData(WriterContext context)
        {
            EvaluationSettings settings = new EvaluationSettings
            {
                ContextEntity = context.CurrentEntity,
                TimeZoneName  = context.Settings.TimeZoneName
            };
            ExpressionRunResult result = context.ExternalServices.ExpressionRunner.Run(Expression, settings);

            IEnumerable <IEntity> instances;

            if (result.Value == null)
            {
                instances = Enumerable.Empty <IEntity>();
            }
            else
            {
                instances = result.Value as IEnumerable <IEntity>;
                if (instances == null)
                {
                    IEntity instance = result.Value as IEntity;
                    if (instance != null)
                    {
                        instances = new[] { instance }
                    }
                    ;
                    else
                    {
                        throw new Exception("Expected result to be list of entities.");
                    }
                    // assert false, the cast step should ensure this, or have thrown a ParseException
                }
            }

            return(instances.Select((entity, pos) => new DataElement(entity, pos)));
        }
        public void code_decode_test()
        {
            var bufMgr  = new BufferManager(65535, 1);
            var context = new WriterContext(bufMgr);
            var buf     = bufMgr.Dequeue();

            bufMgr.Enqueue(buf);

            var sut = new MessageFrame();

            sut.SequenceNumber = 22;
            var payload = Encoding.UTF8.GetBytes("Hello world");

            sut.PayloadBuffer = new ArraySegment <byte>(payload, 0, payload.Length);
            sut.Write(context);

            var pos    = 0;
            var len    = context.GetPackets().First().Count;
            var frame2 = new MessageFrame();

            frame2.Read(buf.Array, ref pos, ref len);
            frame2.SequenceNumber.Should().Be(22);
            Encoding.ASCII.GetString(sut.PayloadBuffer.Array, 0, sut.PayloadBuffer.Count).Should().Be("Hello world");
        }
Example #21
0
 public TypeScriptExportVisitor(TextWriter writer, ExportContext exportContext) : base(writer, exportContext)
 {
     Context = WriterContext.None;
 }
Example #22
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				w.Write (PrimaryId);
				ObjectFormatter.WriteObject (w, o.GetType (), ctx);
				string v = (string) converter.ConvertTo (null, Helpers.InvariantCulture,
									 o, typeof (string));
				base.Write (w, v, ctx);
			}
            public void Write(object obj, bool writeEmpty, IntPtr result, ref int index, WriterContext context)
            {
                Type type = obj.GetType();

                factory(typeof(string)).Write(type.Name, writeEmpty, result, ref index, context);
                factory(type).Write(obj, writeEmpty, result, ref index, context);
            }
Example #24
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				object value = Convert.ChangeType (o, ((Enum) o).GetTypeCode ());
				w.Write (PrimaryId);
				WriteObject (w, o.GetType (), ctx);
				WriteObject (w, value, ctx);
			}
Example #25
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				Array val = (Array) o;
				if (val.GetType ().GetElementType ().IsPrimitive) {
					w.Write (SecondaryId);
					_binaryFormatter.Serialize (w.BaseStream, o);
					return;
				}
				
				w.Write (PrimaryId);
				WriteObject (w, val.GetType ().GetElementType (), ctx);
				
				Write7BitEncodedInt (w, val.Length);
				for (int i = 0; i < val.Length; i++)
					WriteObject (w, val.GetValue (i), ctx);
			}
Example #26
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				ArrayList l = (ArrayList) o;
				
				w.Write (PrimaryId);
				Write7BitEncodedInt (w, l.Count);
				for (int i = 0; i < l.Count; i++)
					WriteObject (w, l [i], ctx);
			}
Example #27
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				object [] val = (object []) o;
				
				w.Write (PrimaryId);
				Write7BitEncodedInt (w, val.Length);
				for (int i = 0; i < val.Length; i++)
					WriteObject (w, val [i], ctx);
			}
Example #28
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				w.Write (PrimaryId);
				
				MemoryStream ms = new MemoryStream (128);
				new BinaryFormatter ().Serialize (ms, o);
				
				byte [] buf = ms.GetBuffer ();
				Write7BitEncodedInt (w, buf.Length);
				w.Write (buf, 0, buf.Length);
			}
Example #29
0
			protected abstract void Write (BinaryWriter w, object o, WriterContext ctx);
Example #30
0
 public InsertSql(WriterContext context)
     : base(context)
 {
 }
Example #31
0
            public void WriteObjectStart()
            {
                DoValidation (Condition.NotAProperty);
                PutNewline ();

                Put ("{");

                context = new WriterContext ();
                context.InObject = true;
                ctx_stack.Push (context);

                Indent ();
            }
 public RepositoryBase(WriterContext context)
 {
     _dbContext = context;
 }
Example #33
0
        protected override void WriteTo(object item, XmlWriter writer, WriterContext context)
        {
            SyndicationFeed feed = (SyndicationFeed)item;

            feed.SaveAsAtom10(writer);
        }
Example #34
0
 protected override void WriteTo(object item, XmlWriter writer, WriterContext context)
 {
   SyndicationItem si = (SyndicationItem)item;
   si.SaveAsAtom10(writer);
 }
Example #35
0
 internal RecorderWriter(XElement element, WriterContext context)
 {
     this.element = element;
     this.context = context;
 }
 public int CountSize(object obj, bool writeEmpty, WriterContext context)
 {
     return(baseSerializer.CountSize(obj, writeEmpty, context));
 }
Example #37
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				Triplet t = (Triplet) o;
				w.Write (PrimaryId);
				WriteObject (w, t.First, ctx);
				WriteObject (w, t.Second, ctx);
				WriteObject (w, t.Third, ctx);
			}
Example #38
0
            public void WriteObjectEnd()
            {
                DoValidation (Condition.InObject);
                PutNewline (false);

                ctx_stack.Pop ();
                if (ctx_stack.Count == 1)
                has_reached_end = true;
                else {
                context = ctx_stack.Peek ();
                context.ExpectingValue = false;
                }

                Unindent ();
                Put ("}");
            }
Example #39
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				Hashtable ht = (Hashtable) o;
				
				w.Write (PrimaryId);
				Write7BitEncodedInt (w, ht.Count);
				foreach (DictionaryEntry de in ht) {
					WriteObject (w, de.Key, ctx);
					WriteObject (w, de.Value, ctx);
				}
			}
Example #40
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				IndexedString s = o as IndexedString;

				if (s == null)
					throw new InvalidOperationException ("object is not of the IndexedString type");
				
				base.Write (w, s.Value, ctx);
			}
Example #41
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				Color c = (Color) o;
				
				if (c.IsEmpty || c.IsKnownColor) {
					w.Write (SecondaryId);
					if (c.IsEmpty)
						w.Write (-1); //isempty marker
					else
						w.Write ((int) c.ToKnownColor ());
				} else {
					w.Write (PrimaryId);
					w.Write (c.ToArgb ());
				}
			}
Example #42
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				int i = (int) o;
				if ((int)(byte) i == i) {
					w.Write (SecondaryId);
					w.Write ((byte) i);
				} else {
					w.Write (PrimaryId);
					w.Write (i);
				}
			}
Example #43
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				if (ctx.RegisterCache (o)) {
					w.Write (SecondaryId);
					w.Write (ctx.Key);
				} else {
					w.Write (PrimaryId);
					w.Write (((Type) o).FullName);

					// We should cache the name of the assembly
					w.Write (((Type) o).Assembly.FullName);
				}
			}
Example #44
0
 protected override void Write(BinaryWriter w, object o, WriterContext ctx)
 {
     base.Write(w, o.ToString(), ctx);
 }
Example #45
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				base.Write (w, o.ToString (), ctx);
			}
Example #46
0
            public static void WriteObject(BinaryWriter w, object o, WriterContext ctx)
            {
#if TRACE && !TARGET_J2EE
                if (o != null)
                {
                    Trace.WriteLine(String.Format("Writing {0} (type: {1})", o, o.GetType()));
                    Trace.Indent();
                }
                else
                {
                    Trace.WriteLine("Writing null");
                }
                long pos = w.BaseStream.Position;
#endif

                if (o == null)
                {
                    w.Write((byte)0);
                    return;
                }

                Type t = o.GetType();
#if TRACE
                Trace.WriteLine(String.Format("Looking up formatter for type {0}", t));
#endif

                ObjectFormatter fmt = writeMap [t] as ObjectFormatter;
#if TRACE
                Trace.WriteLine(String.Format("Formatter from writeMap: '{0}'", fmt));
#endif
                if (fmt == null)
                {
                    // Handle abstract types here

                    if (o is Type)
                    {
                        fmt = typeFormatter;
                    }
                    else if (t.IsEnum)
                    {
                        fmt = enumFormatter;
                    }
                    else if (t.IsArray && ((Array)o).Rank == 1)
                    {
                        fmt = singleRankArrayFormatter;
                    }
                    else
                    {
                        TypeConverter converter;
                        converter = TypeDescriptor.GetConverter(o);
#if TRACE
                        Trace.WriteLine(String.Format("Type converter: '{0}' (to string: {1}; from {2}: {3})",
                                                      converter,
                                                      converter != null ? converter.CanConvertTo(typeof(string)) : false,
                                                      t,
                                                      converter != null ? converter.CanConvertFrom(t) : false));
#endif
                        // Do not use the converter if it's an instance of
                        // TypeConverter itself - it reports it is able to
                        // convert to string, but it's only a conversion
                        // consisting of a call to ToString() with no
                        // reverse conversion supported. This leads to
                        // problems when deserializing the object.
                        if (converter == null || converter.GetType() == typeof(TypeConverter) || !converter.CanConvertTo(typeof(string)))
                        {
                            fmt = binaryObjectFormatter;
                        }
                        else
                        {
                            typeConverterFormatter.Converter = converter;
                            fmt = typeConverterFormatter;
                        }
                    }
                }

#if TRACE
                Trace.WriteLine(String.Format("Writing with formatter '{0}'", fmt.GetType()));
#endif
                fmt.Write(w, o, ctx);
#if TRACE && !TARGET_J2EE
                Trace.Unindent();
                Trace.WriteLine(String.Format("Wrote {0} (type: {1}) {2} bytes", o, o.GetType(), w.BaseStream.Position - pos));
#endif
            }
            public int CountSize(object obj, bool writeEmpty, WriterContext context)
            {
                Type type = obj.GetType();

                return(factory(typeof(string)).CountSize(type.Name, writeEmpty, context) + factory(type).CountSize(obj, writeEmpty, context));
            }
Example #48
0
 protected override void Write(BinaryWriter w, object o, WriterContext ctx)
 {
     w.Write(PrimaryId);
     w.Write(((DateTime)o).Ticks);
 }
Example #49
0
 public TypeScriptExportVisitor(TextWriter writer, string tabulation)
     : base(writer, tabulation)
 {
     Context = WriterContext.None;
 }
        public override WriterContext GetWriterContext(IMemberDefinition member, ILanguage language)
        {
            TypeSpecificContext cachedTypeContext;
            DecompiledType      decompiledType;

            if (member is TypeDefinition && member == Utilities.GetOuterMostDeclaringType(member))
            {
                TypeDefinition type = member as TypeDefinition;
                Dictionary <string, DecompiledType> decompiledTypes = GetNestedDecompiledTypes(type, language);

                cachedTypeContext = GetTypeContext(type, language, decompiledTypes);

                AddTypeContextsToCache(decompiledTypes, type, language);

                if (!decompiledTypes.TryGetValue(type.FullName, out decompiledType))
                {
                    throw new Exception("Decompiled type not found in decompiled types cache.");
                }
            }
            else
            {
                decompiledType    = GetDecompiledType(member, language);
                cachedTypeContext = GetTypeContext(decompiledType, language);
            }

            TypeSpecificContext typeContext = new TypeSpecificContext(
                cachedTypeContext.CurrentType,
                cachedTypeContext.MethodDefinitionToNameMap,
                cachedTypeContext.BackingFieldToNameMap,
                cachedTypeContext.UsedNamespaces,
                new HashSet <string>(),
                cachedTypeContext.AssignmentData,
                cachedTypeContext.AutoImplementedProperties,
                cachedTypeContext.AutoImplementedEvents,
                cachedTypeContext.ExplicitlyImplementedMembers,
                cachedTypeContext.ExceptionWhileDecompiling,
                cachedTypeContext.GeneratedFilterMethods,
                cachedTypeContext.GeneratedMethodDefinitionToNameMap
                );

            // If members were taken from the cache, generated filter methods must be added to decompiled type.
            if (typeContext.GeneratedFilterMethods.Count > 0)
            {
                AddGeneratedFilterMethodsToDecompiledType(decompiledType, typeContext, language);
            }

            Dictionary <string, MethodSpecificContext> methodContexts       = new Dictionary <string, MethodSpecificContext>();
            Dictionary <string, Statement>             decompiledStatements = new Dictionary <string, Statement>();

            foreach (KeyValuePair <string, DecompiledMember> decompiledPair in decompiledType.DecompiledMembers)
            {
                methodContexts.Add(decompiledPair.Key, decompiledPair.Value.Context);
                decompiledStatements.Add(decompiledPair.Key, decompiledPair.Value.Statement);
            }

            TypeDefinition declaringType = Utilities.GetDeclaringTypeOrSelf(member);

            AssemblySpecificContext assemblyContext = GetAssemblyContext(declaringType.Module.Assembly, language);
            ModuleSpecificContext   moduleContext   = GetModuleContext(declaringType.Module, language);

            WriterContext writerContext = new WriterContext(assemblyContext, moduleContext, typeContext, methodContexts, decompiledStatements);

            return(writerContext);
        }
Example #51
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				if ((bool)o == true)
					w.Write (PrimaryId);
				else
					w.Write (SecondaryId);
			}
 public WriterRepository(WriterContext context) : base(context)
 {
 }
Example #53
0
 protected abstract void Write(BinaryWriter w, object o, WriterContext ctx);
Example #54
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				w.Write (PrimaryId);
				w.Write ((char) o);
			}
Example #55
0
 protected override void Write(BinaryWriter w, object o, WriterContext ctx)
 {
     w.Write(PrimaryId);
     w.Write((char)o);
 }
Example #56
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				w.Write (PrimaryId);
				w.Write (((DateTime) o).Ticks);
			}
Example #57
0
			public static void WriteObject (BinaryWriter w, object o, WriterContext ctx)
			{
#if TRACE && !TARGET_J2EE
				if (o != null) {
					Trace.WriteLine (String.Format ("Writing {0} (type: {1})", o, o.GetType ()));
					Trace.Indent ();
				} else {
					Trace.WriteLine ("Writing null");
				}
				long pos = w.BaseStream.Position;
#endif
				
				if (o == null) {
					w.Write ((byte) 0);
					return;
				}
				
				Type t = o.GetType ();
#if TRACE
				Trace.WriteLine (String.Format ("Looking up formatter for type {0}", t));
#endif

				ObjectFormatter fmt = writeMap [t] as ObjectFormatter;
#if TRACE
				Trace.WriteLine (String.Format ("Formatter from writeMap: '{0}'", fmt));
#endif
				if (fmt == null) {
					// Handle abstract types here
					
					if (o is Type)
						fmt = typeFormatter;
					else if (t.IsEnum)
						fmt = enumFormatter;
					else if (t.IsArray && ((Array) o).Rank == 1)
						fmt = singleRankArrayFormatter;
					else {
						TypeConverter converter;
						converter = TypeDescriptor.GetConverter (o);
#if TRACE
						Trace.WriteLine (String.Format ("Type converter: '{0}' (to string: {1}; from {2}: {3})",
										converter,
										converter != null ? converter.CanConvertTo (typeof (string)) : false,
										t,
										converter != null ? converter.CanConvertFrom (t) : false));
#endif
						// Do not use the converter if it's an instance of
						// TypeConverter itself - it reports it is able to
						// convert to string, but it's only a conversion
						// consisting of a call to ToString() with no
						// reverse conversion supported. This leads to
						// problems when deserializing the object.
						if (converter == null || converter.GetType () == typeof (TypeConverter) ||
						    !converter.CanConvertTo (typeof (string)) || !converter.CanConvertFrom (typeof (string)))
							fmt = binaryObjectFormatter;
						else {
							typeConverterFormatter.Converter = converter;
							fmt = typeConverterFormatter;
						}
					}
				}

#if TRACE
				Trace.WriteLine (String.Format ("Writing with formatter '{0}'", fmt.GetType ()));
#endif
				fmt.Write (w, o, ctx);
#if TRACE && !TARGET_J2EE
				Trace.Unindent ();
				Trace.WriteLine (String.Format ("Wrote {0} (type: {1}) {2} bytes", o, o.GetType (), w.BaseStream.Position - pos));
#endif
			}
Example #58
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				Pair p = (Pair) o;
				w.Write (PrimaryId);
				WriteObject (w, p.First, ctx);
				WriteObject (w, p.Second, ctx);
			}
 public void Write(object obj, bool writeEmpty, IntPtr result, ref int index, WriterContext context)
 {
     baseSerializer.Write(obj, writeEmpty, result, ref index, context);
 }
Example #60
0
			protected override void Write (BinaryWriter w, object o, WriterContext ctx)
			{
				if (ctx.RegisterCache (o)) {
					w.Write (SecondaryId);
					w.Write (ctx.Key);
				} else {
					w.Write (PrimaryId);
					w.Write ((string)o);
				}
			}