本文整理汇总了C#中Jayrock.Json.Conversion.ImportContext类的典型用法代码示例。如果您正苦于以下问题:C# ImportContext类的具体用法?C# ImportContext怎么用?C# ImportContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImportContext类属于Jayrock.Json.Conversion命名空间,在下文中一共展示了ImportContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportFromString
protected override object ImportFromString(ImportContext context, JsonReader reader)
{
Debug.Assert(context != null);
Debug.Assert(reader != null);
string s = reader.Text.Trim();
if (s.Length > 0)
{
char ch = s[0];
if (Char.IsDigit(ch) || ch == '+' || ch == '-')
throw Error(s, null);
}
try
{
return ReadReturning(reader, Enum.Parse(OutputType, s, true));
}
catch (ArgumentException e)
{
//
// Value is either an empty string ("") or only contains
// white space. Value is a name, but not one of the named
// constants defined for the enumeration.
//
throw Error(s, e);
}
}
示例2: Registration
public void Registration()
{
ImportContext context = new ImportContext();
ThingImporter importer = new ThingImporter();
context.Register(importer);
Assert.AreSame(importer, context.FindImporter(typeof(Thing)));
}
示例3: AssertInStock
private static void AssertInStock(Type expected, Type type)
{
ImportContext context = new ImportContext();
IImporter importer = context.FindImporter(type);
Assert.IsNotNull(importer, "No importer found for {0}", type.FullName);
Assert.IsInstanceOfType(expected, importer, type.FullName);
}
示例4: CreateObject
public ObjectConstructionResult CreateObject(ImportContext context, JsonReader reader)
{
if (context == null) throw new ArgumentNullException("context");
if (reader == null) throw new ArgumentNullException("reader");
return CreateObject(context, JsonBuffer.From(reader).GetMembersArray());
}
示例5: RegistrationIsPerContext
public void RegistrationIsPerContext()
{
ImportContext context = new ImportContext();
ThingImporter exporter = new ThingImporter();
context.Register(exporter);
context = new ImportContext();
Assert.AreNotSame(exporter, context.FindImporter(typeof(Thing)));
}
示例6: TransportComponent
private TransportComponent()
{
JsonExportContext = JsonConvert.CreateExportContext();
JsonExportContext.Register(new TransportMessageExporter());
JsonImportContext = JsonConvert.CreateImportContext();
JsonImportContext.Register(new TransportMessageImporter());
TransportListeners.Add(this);
}
示例7: 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;
}
示例8: 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);
}
示例9: ReflectImport
private object ReflectImport(ImportContext context, JsonReader reader)
{
if (context == null)
throw new ArgumentNullException("context");
if (reader == null)
throw new ArgumentNullException("reader");
IJsonImportable o = CreateObject();
o.Import(context, reader);
return o;
}
示例10: CreateObject
public virtual ObjectConstructionResult CreateObject(ImportContext context)
{
if (context == null) throw new ArgumentNullException("context");
JsonBufferWriter tailw = _tailw;
_tailw = null;
if (tailw != null)
tailw.WriteEndObject();
JsonBuffer tail = (tailw != null ? tailw.GetBuffer() : StockJsonBuffers.EmptyObject);
object obj = OnCreateObject(context);
return new ObjectConstructionResult(obj, tail.CreateReader());
}
示例11: 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;
}
示例12: 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));
}
示例13: Import
public virtual bool Import(ImportContext context, string name, JsonReader reader)
{
if (context == null) throw new ArgumentNullException("context");
if (reader == null) throw new ArgumentNullException("reader");
JsonBufferWriter tailw = _tailw;
if (tailw == null)
{
tailw = _tailw = new JsonBufferWriter();
tailw.WriteStartObject();
}
tailw.WriteMember(name);
tailw.WriteFromReader(reader);
return true;
}
示例14: 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);
}
}
示例15: ImportFromArray
protected override object ImportFromArray(ImportContext context, JsonReader reader)
{
if (context == null) throw new ArgumentNullException("context");
if (reader == null) throw new ArgumentNullException("reader");
object collection = CreateCollection();
reader.ReadToken(JsonTokenClass.Array);
ImportElements(collection, context, reader);
if (reader.TokenClass != JsonTokenClass.EndArray)
throw new Exception("Implementation error.");
reader.Read();
return collection;
}