本文整理汇总了C#中ImportContext.Import方法的典型用法代码示例。如果您正苦于以下问题:C# ImportContext.Import方法的具体用法?C# ImportContext.Import怎么用?C# ImportContext.Import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImportContext
的用法示例。
在下文中一共展示了ImportContext.Import方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportFromObject
protected override object ImportFromObject(ImportContext context, JsonReader reader)
{
reader.Read();
object target = Activator.CreateInstance(base.OutputType);
INonObjectMemberImporter importer = target as INonObjectMemberImporter;
while (reader.TokenClass != JsonTokenClass.EndObject)
{
string name = reader.ReadMember();
PropertyDescriptor descriptor = this._properties.Find(name, true);
if ((descriptor == null) || descriptor.IsReadOnly)
{
if ((importer == null) || !importer.Import(context, name, reader))
{
reader.Skip();
}
}
else
{
if (this._importers != null)
{
int index = this._properties.IndexOf(descriptor);
IObjectMemberImporter importer2 = this._importers[index];
if (importer2 != null)
{
importer2.Import(context, reader, target);
continue;
}
}
descriptor.SetValue(target, context.Import(descriptor.PropertyType, reader));
}
}
return ImporterBase.ReadReturning(reader, target);
}
示例2: ImportScalarAsArray
private object ImportScalarAsArray(ImportContext context, JsonReader reader)
{
Type elementType = base.OutputType.GetElementType();
Array array = Array.CreateInstance(elementType, 1);
array.SetValue(context.Import(elementType, reader), 0);
return array;
}
示例3: AssertImport
private static void AssertImport(object expected, string input)
{
JsonTextReader reader = new JsonTextReader(new StringReader(input));
Type expectedType = expected.GetType();
ImportContext context = new ImportContext();
object o = context.Import(expectedType, reader);
Assert.IsInstanceOfType(expectedType, o);
Assert.AreEqual(expected, o);
}
示例4: ImportValue
private object ImportValue(ImportContext context, JsonReader reader)
{
Debug.Assert(context != null);
Debug.Assert(reader != null);
return reader.TokenClass == JsonTokenClass.Object
? ImportFromObject(context, reader)
: reader.TokenClass == JsonTokenClass.Array
? ImportArray(context, reader)
: context.Import(AnyType.Value, reader);
}
示例5: ImportFromArray
protected override object ImportFromArray(ImportContext context, JsonReader reader)
{
reader.Read();
MemoryStream stream = new MemoryStream();
Type type = typeof(byte);
while (reader.TokenClass != JsonTokenClass.EndArray)
{
stream.WriteByte((byte) context.Import(type, reader));
}
return ImporterBase.ReadReturning(reader, stream.ToArray());
}
示例6: ImportFromArray
protected override object ImportFromArray(ImportContext context, JsonReader reader)
{
reader.Read();
ArrayList list = new ArrayList();
Type elementType = base.OutputType.GetElementType();
while (reader.TokenClass != JsonTokenClass.EndArray)
{
list.Add(context.Import(elementType, reader));
}
return ImporterBase.ReadReturning(reader, list.ToArray(elementType));
}
示例7: Import
public void Import()
{
JsonRecorder writer = new JsonRecorder();
writer.WriteStartArray();
writer.WriteString("foo");
writer.WriteString("bar");
writer.WriteEndArray();
JsonReader reader = writer.CreatePlayer();
ImportContext context = new ImportContext();
IList list = (IList) context.Import(typeof(IList), reader);
Assert.AreEqual(new object[] { "foo", "bar" }, CollectionHelper.ToArray(list));
}
示例8: ImportValue
private object ImportValue(ImportContext context, JsonReader reader)
{
if (reader.TokenClass == JsonTokenClass.Object)
{
return this.ImportFromObject(context, reader);
}
if (reader.TokenClass != JsonTokenClass.Array)
{
return context.Import(AnyType.Value, reader);
}
return this.ImportArray(context, reader);
}
示例9: Import
public void Import()
{
JsonRecorder writer = new JsonRecorder();
writer.WriteStartObject();
writer.WriteMember("foo");
writer.WriteString("bar");
writer.WriteEndObject();
JsonReader reader = writer.CreatePlayer();
ImportContext context = new ImportContext();
IDictionary map = (IDictionary) context.Import(typeof(IDictionary), reader);
Assert.IsNotNull(map);
Assert.AreEqual(1, map.Count);
Assert.AreEqual("bar", map["foo"]);
}
示例10: ImportFromArray
protected override object ImportFromArray(ImportContext context, JsonReader reader)
{
Debug.Assert(context != null);
Debug.Assert(reader != null);
reader.Read();
MemoryStream ms = new MemoryStream();
Type byteType = typeof(byte);
while (reader.TokenClass != JsonTokenClass.EndArray)
ms.WriteByte((byte) context.Import(byteType, reader));
return ReadReturning(reader, ms.ToArray());
}
示例11: ImportFromObject
protected override object ImportFromObject(ImportContext context, JsonReader reader)
{
Debug.Assert(context != null);
Debug.Assert(reader != null);
reader.Read();
object o = Activator.CreateInstance(OutputType);
while (reader.TokenClass != JsonTokenClass.EndObject)
{
string memberName = reader.ReadMember();
PropertyDescriptor property = _properties.Find(memberName, true);
if (property != null && !property.IsReadOnly)
property.SetValue(o, context.Import(property.PropertyType, reader));
else
reader.Skip();
}
return ReadReturning(reader, o);
}
示例12: Clone
internal static ParameterDefinition Clone(ParameterDefinition param, ImportContext context)
{
ParameterDefinition np = new ParameterDefinition (
param.Name,
param.Sequence,
param.Attributes,
context.Import (param.ParameterType));
if (param.HasConstant)
np.Constant = param.Constant;
if (param.MarshalSpec != null)
np.MarshalSpec = param.MarshalSpec;
foreach (CustomAttribute ca in param.CustomAttributes)
np.CustomAttributes.Add (CustomAttribute.Clone (ca, context));
return np;
}
示例13: AssertImport
private static void AssertImport(Array expected, string s)
{
JsonReader reader = CreateReader(s);
ImportContext context = new ImportContext();
object o = context.Import(expected.GetType(), reader);
Assert.IsTrue(reader.EOF);
if (expected == null)
Assert.IsNull(o);
Assert.AreEqual(expected, o);
}
示例14: Import
private static object Import(string input)
{
JsonTextReader reader = new JsonTextReader(new StringReader(input));
ImportContext context = new ImportContext();
object value = context.Import(typeof(DateTime), reader);
Assert.IsTrue(reader.EOF, "Reader must be at EOF.");
if (value != null)
Assert.IsInstanceOfType(typeof(DateTime), value);
return value;
}
示例15: ImportFromObject
protected override object ImportFromObject(ImportContext context, JsonReader reader)
{
Debug.Assert(context != null);
Debug.Assert(reader != null);
reader.Read();
object obj = Activator.CreateInstance(OutputType);
INonObjectMemberImporter otherImporter = obj as INonObjectMemberImporter;
while (reader.TokenClass != JsonTokenClass.EndObject)
{
string memberName = reader.ReadMember();
PropertyDescriptor property = _properties.Find(memberName, true);
//
// Skip over the member value and continue with reading if
// the property was not found or if the property found cannot
// be set.
//
if (property == null || property.IsReadOnly)
{
if (otherImporter == null || !otherImporter.Import(context, memberName, reader))
reader.Skip();
continue;
}
//
// Check if the property defines a custom import scheme.
// If yes, ask it to import the value into the property
// and then continue with the next.
//
if (_importers != null)
{
int index = _properties.IndexOf(property);
IObjectMemberImporter importer = _importers[index];
if (importer != null)
{
importer.Import(context, reader, obj);
continue;
}
}
//
// Import from reader based on the property type and
// then set the value of the property.
//
property.SetValue(obj, context.Import(property.PropertyType, reader));
}
return ReadReturning(reader, obj);
}