本文整理汇总了C#中Jayrock.Json.Conversion.ImportContext.Import方法的典型用法代码示例。如果您正苦于以下问题:C# ImportContext.Import方法的具体用法?C# ImportContext.Import怎么用?C# ImportContext.Import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jayrock.Json.Conversion.ImportContext
的用法示例。
在下文中一共展示了ImportContext.Import方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateObject
public virtual ObjectConstructionResult CreateObject(ImportContext context, JsonReader reader)
{
if (context == null)
throw new ArgumentNullException("context");
if (reader == null)
throw new ArgumentNullException("reader");
IObjectSurrogateConstructor ctor = (IObjectSurrogateConstructor) context.Import(_surrogateType, reader);
return ctor.CreateObject(context);
}
示例2: Import
public object Import(ImportContext context, Jayrock.Json.JsonReader reader)
{
ActiveReaderMessage arMessage = null;
Dispatcher.Invoke(DispatcherPriority.Background,
(Action)delegate()
{
arMessage = (ActiveReaderMessage)context.Import<ActiveReaderMessage>(reader); ;
});
return arMessage;
}
示例3: Import
/// <summary>
/// The import.
/// </summary>
/// <param name="context">
/// The context.
/// </param>
/// <param name="reader">
/// The reader.
/// </param>
/// <returns>
/// The import.
/// </returns>
public object Import(ImportContext context, JsonReader reader)
{
// var properties = new EvolutionaryProperties();
// reader.StepOut();
// JsonToken token = reader.Token;
this.properties = new EvolutionaryProperties();
PropertyValue[] o = context.Import<PropertyValue[]>(reader);
this.SetProperties(o);
return this.properties;
}
示例4: ImportFromArray
protected override object ImportFromArray(ImportContext context, JsonReader reader)
{
Debug.Assert(context != null);
Debug.Assert(reader != null);
reader.Read();
ArrayList list = new ArrayList();
Type elementType = OutputType.GetElementType();
while (reader.TokenClass != JsonTokenClass.EndArray)
list.Add(context.Import(elementType, reader));
return ReadReturning(reader, list.ToArray(elementType));
}
示例5: ImportElements
protected override void ImportElements(object collection, ImportContext context, JsonReader reader)
{
if (collection == null) throw new ArgumentNullException("collection");
if (context == null) throw new ArgumentNullException("context");
if (reader == null) throw new ArgumentNullException("reader");
object[] args = null;
while (reader.TokenClass != JsonTokenClass.EndArray)
{
if (args == null) // on-demand
args = new object[1];
args[0] = context.Import(ElementType, reader);
InvokeAdd(collection, args);
}
}
示例6: Import
private static object Import(Type expectedType, string s)
{
JsonReader reader = CreateReader(s);
ImportContext context = new ImportContext();
object o = context.Import(expectedType, reader);
Assert.IsTrue(reader.EOF, "Reader must be at EOF.");
Assert.IsNotNull(o);
Assert.IsInstanceOfType(expectedType, o);
return o;
}
示例7: MemberImportCustomization
public void MemberImportCustomization()
{
TestTypeDescriptor logicalType = new TestTypeDescriptor();
PropertyDescriptorCollection properties = logicalType.GetProperties();
properties.Add(new TestPropertyDescriptor("prop1", typeof(object), new Hashtable()));
ArrayList calls2 = new ArrayList();
TestObjectMemberImporter memberImporter2 = new TestObjectMemberImporter(calls2);
Hashtable services2 = new Hashtable();
services2.Add(typeof(IObjectMemberImporter), memberImporter2);
properties.Add(new TestPropertyDescriptor("prop2", typeof(object), services2));
// Third property added to exercise issue #27:
// http://code.google.com/p/jayrock/issues/detail?id=27
ArrayList calls3 = new ArrayList();
TestObjectMemberImporter memberImporter3 = new TestObjectMemberImporter(calls3);
Hashtable services3 = new Hashtable();
services3.Add(typeof(IObjectMemberImporter), memberImporter3);
properties.Add(new TestPropertyDescriptor("prop3", typeof(object), services3));
ComponentImporter importer = new ComponentImporter(typeof(Thing), logicalType);
ImportContext context = new ImportContext();
context.Register(importer);
JsonRecorder writer = new JsonRecorder();
writer.WriteStartObject();
writer.WriteMember("prop1");
writer.WriteString("value1");
writer.WriteMember("prop2");
writer.WriteString("value2");
writer.WriteMember("prop3");
writer.WriteString("value3");
writer.WriteEndObject();
JsonReader reader = writer.CreatePlayer();
Thing thing = (Thing) context.Import(typeof(Thing), reader);
Assert.AreEqual(1, calls2.Count);
Assert.AreSame(memberImporter2, calls2[0]);
Assert.AreEqual(new object[] { context, reader, thing }, memberImporter2.ImportArgs);
Assert.AreEqual("value2", memberImporter2.ImportedValue);
Assert.AreEqual(1, calls3.Count);
Assert.AreSame(memberImporter3, calls3[0]);
Assert.AreEqual(new object[] { context, reader, thing }, memberImporter3.ImportArgs);
Assert.AreEqual("value3", memberImporter3.ImportedValue);
}
示例8: Import
protected virtual void Import(ImportContext context, JsonReader reader)
{
if (context == null)
throw new ArgumentNullException("context");
if (reader == null)
throw new ArgumentNullException("reader");
// FIXME: Consider making this method exception-safe.
// Right now this is a problem because of reliance on
// DictionaryBase.
Clear();
reader.ReadToken(JsonTokenClass.Object);
while (reader.TokenClass != JsonTokenClass.EndObject)
Put(reader.ReadMember(), context.Import(reader));
reader.Read();
}
示例9: Import
public object Import(ImportContext context, Jayrock.Json.JsonReader reader)
{
WhatUpMessage pMessage = (WhatUpMessage)context.Import<WhatUpMessage>(reader); ;
return pMessage;
}
示例10: GetPipeline
/************************************************************************/
/* GET */
/************************************************************************/
#if TEST
public PipelineDescriptor GetPipeline(string pipelineName)
{
PipelineDescriptor pipeline = null;
ImportContext impctx = new ImportContext();
impctx.Register(new ListImporter<ModuleDescriptor>());
impctx.Register(new ListImporter<EndpointDescriptor>());
impctx.Register(new ListImporter<ConnectionDescriptor>());
switch (pipelineName)
{
case "root":
pipeline = (PipelineDescriptor)impctx.Import(
typeof(PipelineDescriptor),
JsonText.CreateReader(test_RootPipelineJSON));
break;
case "pipeline1":
pipeline = (PipelineDescriptor)impctx.Import(
typeof(PipelineDescriptor),
JsonText.CreateReader(test_Pipeline1JSON));
break;
}
return pipeline;
}
示例11: ParseRequest
protected virtual object ParseRequest(TextReader input)
{
if (input == null)
throw new ArgumentNullException("input");
JsonReader reader = (JsonReader) _serviceProvider.GetService(typeof(JsonReader));
if (reader == null)
reader = new JsonTextReader(input);
ImportContext importContext = new ImportContext();
JsonObject request = new JsonObject();
Method method = null;
JsonReader paramsReader = null;
object args = null;
reader.ReadToken(JsonTokenClass.Object);
while (reader.TokenClass != JsonTokenClass.EndObject)
{
string memberName = reader.ReadMember();
switch (memberName)
{
case "id" :
{
request["id"] = importContext.Import(reader);
break;
}
case "method" :
{
string methodName = reader.ReadString();
request["method"] = methodName;
method = _service.GetClass().GetMethodByName(methodName);
if (paramsReader != null)
{
//
// If the parameters were already read in and
// buffer, then deserialize them now that we know
// the method we're dealing with.
//
args = ReadParameters(method, paramsReader, importContext);
paramsReader = null;
}
break;
}
case "params" :
{
//
// Is the method already known? If so, then we can
// deserialize the parameters right away. Otherwise
// we record them until hopefully the method is
// encountered.
//
if (method != null)
{
args = ReadParameters(method, reader, importContext);
}
else
{
JsonRecorder recorder = new JsonRecorder();
recorder.WriteFromReader(reader);
paramsReader = recorder.CreatePlayer();
}
break;
}
default:
{
reader.Skip();
break;
}
}
}
reader.Read();
if (args != null)
request["params"] = args;
return request;
}
示例12: Run
private static void Run()
{
ImportContext impctx = new ImportContext();
//
// Import a strongly-typed collection of integers...
//
impctx.Register(new ListImporter<int>());
List<int> numbers = (List<int>) impctx.Import(typeof(List<int>),
JsonText.CreateReader("[ 1, 2, 3 ]"));
numbers.ForEach(Console.WriteLine);
Console.WriteLine();
//
// Import a Shape object containing a strongly-typed collection of
// Point objects.
//
impctx.Register(new ListImporter<Point>());
Shape shape = (Shape) impctx.Import(typeof(Shape), JsonText.CreateReader(@"{
name: 'square',
points: [
{ x: 10, y: 10 },
{ x: 20, y: 10 },
{ x: 20, y: 20 },
{ x: 10, y: 20 }
]
}"));
JsonConvert.Export(shape, CreatePrettyWriter(Console.Out));
Console.WriteLine();
//
// Import CookieCollection using duck-typing. In other words,
// as long as CookieCollection walks and quacks like a
// collection of Cookie elements then it's good enough for
// DuckCollectionImporter. DuckCollectionImporter can infer
// that CookieCollection contains Cookie elements.
//
impctx.Register(new DuckCollectionImporter(typeof(CookieCollection)));
const string cookiesText = @"[
{ name: 'one', value: 1, expires: '2099-01-02' },
{ name: 'two', value: 2, expires: '2088-03-04' },
{ name: 'three', value: 3, expires: '2077-05-06' }
]";
CookieCollection cookies = (CookieCollection) impctx.Import(typeof(CookieCollection), JsonText.CreateReader(cookiesText));
JsonConvert.Export(cookies, CreatePrettyWriter(Console.Out));
Console.WriteLine();
//
// Now repeat, but replace with a new CookieCollection importer
// that is identical in behavior but based on generics. Here,
// the difference is that DuckCollectionImporter<,> does not
// have to guess the element type as it is provided as a type
// argument.
//
impctx.Register(new DuckCollectionImporter<CookieCollection, Cookie>());
cookies = (CookieCollection)impctx.Import(typeof(CookieCollection), JsonText.CreateReader(cookiesText));
JsonConvert.Export(cookies, CreatePrettyWriter(Console.Out));
Console.WriteLine();
//
// Those Cookie objects have a lot of properties. Say our JSON
// text only needs a subset. Here, we register an exporter that
// provides a custom view of the type. We only expose the name,
// value and expiration time. What's more, we rename the
// Expires property so that it appears as "expiration" in JSON.
//
ExportContext expctx = new ExportContext();
JsonType.
BuildFor(typeof(Cookie)).
AddProperty("Name").
AddProperty("Value").
AddProperty("Expires").As("expiration").
Register(expctx);
expctx.Export(cookies, CreatePrettyWriter(Console.Out));
Console.WriteLine();
}
示例13: NavigatePop
//! move out of current pipeline
public PipelineDescriptor NavigatePop()
{
ImportContext impctx = new ImportContext();
impctx.Register(new ListImporter<ModuleDescriptor>());
impctx.Register(new ListImporter<ConnectionDescriptor>());
impctx.Register(new ListImporter<EndpointDescriptor>());
PipelineDescriptor newPipeline = (PipelineDescriptor)impctx.Import(
typeof(PipelineDescriptor),
JsonText.CreateReader(test_RootPipelineJSON));
NuiState.Instance.level--;
currentPipeline = newPipeline;
return newPipeline;
}
示例14:
void IObjectMemberImporter.Import(ImportContext context, JsonReader reader, object target)
{
ImportContext = context;
ImportReader = reader;
ImportTarget = target;
ImportedValue = context.Import(typeof(object), reader);
}
示例15: MemberImportCustomization
public void MemberImportCustomization()
{
TestObjectMemberImporter memberImporter = new TestObjectMemberImporter();
Hashtable services = new Hashtable();
services.Add(typeof(IObjectMemberImporter), memberImporter);
TestTypeDescriptor logicalType = new TestTypeDescriptor();
PropertyDescriptorCollection properties = logicalType.GetProperties();
TestPropertyDescriptor property = new TestPropertyDescriptor("prop", typeof(object), services);
properties.Add(property);
ComponentImporter importer = new ComponentImporter(typeof(Thing), logicalType);
ImportContext context = new ImportContext();
context.Register(importer);
JsonRecorder writer = new JsonRecorder();
writer.WriteStartObject();
writer.WriteMember("prop");
writer.WriteString("value");
writer.WriteEndObject();
JsonReader reader = writer.CreatePlayer();
Thing thing = (Thing) context.Import(typeof(Thing), reader);
Assert.AreSame(context, memberImporter.ImportContext);
Assert.AreSame(reader, memberImporter.ImportReader);
Assert.AreSame(thing, memberImporter.ImportTarget);
Assert.AreEqual("value", memberImporter.ImportedValue);
}