当前位置: 首页>>代码示例>>C#>>正文


C# ImportContext.Import方法代码示例

本文整理汇总了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);
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:33,代码来源:ComponentImporter.cs

示例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;
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:7,代码来源:ArrayImporter.cs

示例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);
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:9,代码来源:TestNumberImporter.cs

示例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);
        }
开发者ID:RyanWangTHU,项目名称:ccv2,代码行数:11,代码来源:ExpandoObjectImporter.cs

示例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());
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:11,代码来源:ByteArrayImporter.cs

示例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));
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:11,代码来源:ArrayImporter.cs

示例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));
 }
开发者ID:bubbafat,项目名称:Hebo,代码行数:12,代码来源:TestListImporter.cs

示例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);
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:12,代码来源:ExpandoObjectImporter.cs

示例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"]);
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:14,代码来源:TestDictionaryImporter.cs

示例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());
        }
开发者ID:liuxing7954,项目名称:cangku_1,代码行数:15,代码来源:ByteArrayImporter.cs

示例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);
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:23,代码来源:ComponentImporter.cs

示例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;
        }
开发者ID:KenMacD,项目名称:deconfuser,代码行数:19,代码来源:ParameterDefinition.cs

示例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);
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:13,代码来源:TestArrayImporter.cs

示例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;
 }
开发者ID:atifaziz,项目名称:Jayrock,代码行数:10,代码来源:TestDateTimeImporter.cs

示例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);
        }
开发者ID:Ghawken,项目名称:FrontView,代码行数:58,代码来源:ComponentImporter.cs


注:本文中的ImportContext.Import方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。