本文整理汇总了C#中ExportContext.Export方法的典型用法代码示例。如果您正苦于以下问题:C# ExportContext.Export方法的具体用法?C# ExportContext.Export怎么用?C# ExportContext.Export使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExportContext
的用法示例。
在下文中一共展示了ExportContext.Export方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportValue
protected override void ExportValue(ExportContext context, object value, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(value != null);
Debug.Assert(writer != null);
if (_properties.Count == 0)
{
writer.WriteString(value.ToString());
}
else
{
writer.WriteStartObject();
foreach (PropertyDescriptor property in _properties)
{
object propertyValue = property.GetValue(value);
if (!JsonNull.LogicallyEquals(propertyValue))
{
writer.WriteMember(property.Name);
context.Export(propertyValue, writer);
}
}
writer.WriteEndObject();
}
}
示例2: ExportValue
protected override void ExportValue(ExportContext context, object value, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(value != null);
Debug.Assert(writer != null);
context.Export(value, writer);
}
示例3: TableExportedViaDataView
public void TableExportedViaDataView()
{
DataTable table = new DataTable();
ExportContext context = new ExportContext();
TestDataViewExporter exporter = new TestDataViewExporter();
context.Register(exporter);
context.Export(table, new JsonRecorder());
Assert.AreSame(table.DefaultView, exporter.LastExported);
}
示例4: TableExportedViaItsExporter
public void TableExportedViaItsExporter()
{
DataSet ds = new DataSet();
ds.Tables.Add(new DataTable("Table1"));
ExportContext context = new ExportContext();
TestDataTableExporter exporter = new TestDataTableExporter();
context.Register(exporter);
context.Export(ds, new JsonRecorder());
Assert.AreSame(ds.Tables[0], exporter.LastExported);
}
示例5: ExportMembers
private static void ExportMembers(ExportContext context, IEnumerable<KeyValuePair<string, object>> members, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(members != null);
Debug.Assert(writer != null);
foreach (var member in members)
{
writer.WriteMember(member.Key);
context.Export(member.Value, writer);
}
}
示例6: ExportView
internal static void ExportView(ExportContext context, DataView view, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(view != null);
Debug.Assert(writer != null);
writer.WriteStartObject();
writer.WriteMember("columns");
writer.WriteStartArray();
foreach (DataColumn column in view.Table.Columns)
context.Export(column.ColumnName, writer);
writer.WriteEndArray();
writer.WriteMember("rows");
writer.WriteStartArray();
foreach (DataRowView row in view)
context.Export(row.Row.ItemArray, writer);
writer.WriteEndArray();
writer.WriteEndObject();
}
示例7: ExportValue
protected override void ExportValue(ExportContext context, object value, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(value != null);
Debug.Assert(writer != null);
IEnumerable items = (IEnumerable) value;
writer.WriteStartArray();
foreach (object item in items)
context.Export(item, writer);
writer.WriteEndArray();
}
示例8: ExportCollection
private static void ExportCollection(ExportContext context, NameValueCollection collection, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(collection != null);
Debug.Assert(writer != null);
writer.WriteStartObject();
for (int i = 0; i < collection.Count; i++)
{
writer.WriteMember(collection.GetKey(i));
string[] values = collection.GetValues(i);
if (values == null)
writer.WriteNull();
else if (values.Length > 1)
context.Export(values, writer);
else
context.Export(values[0], writer);
}
writer.WriteEndObject();
}
示例9: ExportRow
internal static void ExportRow(ExportContext context, DataRow row, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(row != null);
Debug.Assert(writer != null);
writer.WriteStartObject();
foreach (DataColumn column in row.Table.Columns)
{
writer.WriteMember(column.ColumnName);
context.Export(row[column], writer);
}
writer.WriteEndObject();
}
示例10: ExportRecord
internal static void ExportRecord(ExportContext context, ICustomTypeDescriptor record, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(record != null);
Debug.Assert(writer != null);
writer.WriteStartObject();
foreach (PropertyDescriptor property in record.GetProperties())
{
writer.WriteMember(property.Name);
context.Export(property.GetValue(record), writer);
}
writer.WriteEndObject();
}
示例11: ExportValue
protected override void ExportValue(ExportContext context, object value, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(value != null);
Debug.Assert(writer != null);
writer.WriteStartObject();
IDictionary dictionary = (IDictionary) value;
foreach (DictionaryEntry entry in DictionaryHelper.GetEntries(dictionary))
{
writer.WriteMember(entry.Key.ToString());
context.Export(entry.Value, writer);
}
writer.WriteEndObject();
}
示例12: ExportValue
protected override void ExportValue(ExportContext context, object value, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(value != null);
Debug.Assert(writer != null);
writer.WriteStartObject();
IDictionary dictionary = (IDictionary) value;
foreach (DictionaryEntry entry in dictionary)
{
writer.WriteMember(entry.Key.ToString());
context.Export(entry.Value, writer);
}
/*
FIXME: Use IDictionaryEnumerator.Entry instead and enumerate manually (faster and more robust).
It is faster because unboxing is avoided by going over
IDictionaryEnumerator.Entry rather than
IDictionaryEnumerator.Current. It is more robust because many
people may get the implementation of IDictionary.GetEnumerator
wrong, especially if they are implementing IDictionary<K, V> in
2.0. If they simply return the enumerator from the wrapped
dictionary then Current will return KeyValuePair<K, V> instead
of DictionaryEntry and therefore cause a casting exception.
using (IDictionaryEnumerator e = dictionary.GetEnumerator())
{
while (e.MoveNext())
{
writer.WriteMember(e.Entry.Key.ToString());
context.Export(e.Entry.Value, writer);
}
}
*/
writer.WriteEndObject();
}
示例13: ExportValue
protected override void ExportValue(ExportContext context, object value, JsonWriter writer)
{
Debug.Assert(context != null);
Debug.Assert(value != null);
Debug.Assert(writer != null);
if (_properties.Count == 0)
{
writer.WriteString(value.ToString());
}
else
{
ObjectReferenceTracker tracker = null;
try
{
writer.WriteStartObject();
int index = 0;
foreach (PropertyDescriptor property in _properties)
{
IObjectMemberExporter exporter = _exporters != null && index < _exporters.Length ?
_exporters[index] : null;
if (exporter != null)
{
exporter.Export(context, writer, value);
}
else
{
object propertyValue = property.GetValue(value);
if (!JsonNull.LogicallyEquals(propertyValue))
{
writer.WriteMember(property.Name);
if (tracker == null)
{
//
// We are about to enter a deeper scope so
// start tracking the current object being
// exported. This will help to detect
// recursive references that may occur
// through this exporter deeper in the tree.
//
tracker = TrackObject(context, value);
}
context.Export(propertyValue, writer);
}
}
}
writer.WriteEndObject();
}
finally
{
if (tracker != null)
tracker.Pop(value);
}
}
}
示例14: MemberExportCustomization
public void MemberExportCustomization()
{
ArrayList calls = new ArrayList();
TestTypeDescriptor logicalType = new TestTypeDescriptor();
PropertyDescriptorCollection properties = logicalType.GetProperties();
Hashtable services;
TestObjectMemberExporter memexp1 = new TestObjectMemberExporter(calls);
services = new Hashtable();
services.Add(typeof(IObjectMemberExporter), memexp1);
properties.Add(new TestPropertyDescriptor("prop1", services));
TestObjectMemberExporter memexp2 = new TestObjectMemberExporter(calls);
services = new Hashtable();
services.Add(typeof(IObjectMemberExporter), memexp2);
properties.Add(new TestPropertyDescriptor("prop2", services));
ComponentExporter exporter = new ComponentExporter(typeof(Thing), logicalType);
ExportContext context = new ExportContext();
context.Register(exporter);
JsonRecorder writer = new JsonRecorder();
Thing thing = new Thing();
context.Export(thing, writer);
Assert.AreEqual(2, calls.Count);
object[] args = { context, writer, thing };
Assert.AreSame(memexp1, calls[0]);
Assert.AreEqual(args, ((TestObjectMemberExporter) calls[0]).ExportArgs);
Assert.AreSame(memexp2, calls[1]);
Assert.AreEqual(args, ((TestObjectMemberExporter) calls[1]).ExportArgs);
}
示例15: MemberExportCustomization
public void MemberExportCustomization()
{
TestObjectMemberExporter memberExporter = new TestObjectMemberExporter();
Hashtable services = new Hashtable();
services.Add(typeof(IObjectMemberExporter), memberExporter);
TestTypeDescriptor logicalType = new TestTypeDescriptor();
PropertyDescriptorCollection properties = logicalType.GetProperties();
properties.Add(new TestPropertyDescriptor("prop", services));
ComponentExporter exporter = new ComponentExporter(typeof(Thing), logicalType);
ExportContext context = new ExportContext();
context.Register(exporter);
JsonRecorder writer = new JsonRecorder();
Thing thing = new Thing();
context.Export(thing, writer);
Assert.AreSame(context, memberExporter.ExportContext);
Assert.AreSame(writer, memberExporter.ExportWriter);
Assert.AreSame(thing, memberExporter.ExportSource);
}