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


C# ImportContext类代码示例

本文整理汇总了C#中ImportContext的典型用法代码示例。如果您正苦于以下问题:C# ImportContext类的具体用法?C# ImportContext怎么用?C# ImportContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ImportContext类属于命名空间,在下文中一共展示了ImportContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImportFromNumber

 protected override object ImportFromNumber(ImportContext context, JsonReader reader)
 {
     object obj2;
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     string text = reader.Text;
     try
     {
         obj2 = ImporterBase.ReadReturning(reader, this.ConvertFromString(text));
     }
     catch (FormatException exception)
     {
         throw this.NumberError(exception, text);
     }
     catch (OverflowException exception2)
     {
         throw this.NumberError(exception2, text);
     }
     return obj2;
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:26,代码来源:NumberImporterBase.cs

示例2: 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

示例3: ImportFromNumber

 protected override object ImportFromNumber(ImportContext context, JsonReader reader)
 {
     double num;
     object obj2;
     string text = reader.Text;
     try
     {
         num = Convert.ToDouble(text, CultureInfo.InvariantCulture);
     }
     catch (FormatException exception)
     {
         throw NumberError(exception, text);
     }
     catch (OverflowException exception2)
     {
         throw NumberError(exception2, text);
     }
     try
     {
         obj2 = ImporterBase.ReadReturning(reader, UnixTime.ToDateTime(num));
     }
     catch (ArgumentException exception3)
     {
         throw NumberError(exception3, text);
     }
     return obj2;
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:27,代码来源:DateTimeImporter.cs

示例4: ImportFromString

 protected override object ImportFromString(ImportContext context, JsonReader reader)
 {
     object obj2;
     try
     {
         Match match = Regex.Match(reader.Text, @"\A \/ Date \( ([0-9]+) \) \/ \z", RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);
         if (match.Success)
         {
             DateTime time;
             try
             {
                 time = UnixTime.ToDateTime((double) (((double) long.Parse(match.Groups[1].Value, NumberStyles.None, CultureInfo.InvariantCulture)) / 1000.0));
             }
             catch (OverflowException exception)
             {
                 throw StringError(exception);
             }
             return ImporterBase.ReadReturning(reader, time);
         }
         obj2 = ImporterBase.ReadReturning(reader, XmlConvert.ToDateTime(reader.Text, XmlDateTimeSerializationMode.Local));
     }
     catch (FormatException exception2)
     {
         throw StringError(exception2);
     }
     return obj2;
 }
开发者ID:huaminglee,项目名称:myyyyshop,代码行数:27,代码来源:DateTimeImporter.cs

示例5: 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

示例6: ImportValue

 protected override object ImportValue(ImportContext context, JsonReader reader)
 {
     if (reader == null)
         throw new ArgumentNullException("reader");
     
     bool value;
     
     if (reader.TokenClass == JsonTokenClass.Number)
     {
         try
         {
             value = Convert.ToInt64(reader.Text, CultureInfo.InvariantCulture) != 0;
         }
         catch (FormatException e)
         {
             throw new JsonException(string.Format("The JSON Number {0} must be an integer to be convertible to System.Boolean.", reader.Text), e);
         }
     }
     else if (reader.TokenClass == JsonTokenClass.Boolean)
     {
         value = reader.Text == JsonBoolean.TrueText;
     }
     else
     {
         throw new JsonException(string.Format("Found {0} where expecting a JSON Boolean.", reader.TokenClass));
     }
     
     return value ? BooleanObject.True : BooleanObject.False;
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:29,代码来源:BooleanImporter.cs

示例7: ImportFromNumber

        protected override object ImportFromNumber(ImportContext context, JsonReader reader)
        {
            Debug.Assert(context != null);
            Debug.Assert(reader != null);

            string text = reader.Text;

            double time;

            try
            {
                time = Convert.ToDouble(text, CultureInfo.InvariantCulture);
            }
            catch (FormatException e)
            {
                throw NumberError(e, text);
            }
            catch (OverflowException e)
            {
                throw NumberError(e, text);
            }

            try
            {
                return ReadReturning(reader, UnixTime.ToDateTime(time));
            }
            catch (ArgumentException e)
            {
                throw NumberError(e, text);
            }
        }
开发者ID:atifaziz,项目名称:Jayrock,代码行数:31,代码来源:DateTimeImporter.cs

示例8: ImportFromBoolean

 protected override object ImportFromBoolean(ImportContext context, JsonReader reader)
 {
     Debug.Assert(context != null);
     Debug.Assert(reader != null);
     
     return BooleanObject.Box(reader.ReadBoolean());
 }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:7,代码来源:BooleanImporter.cs

示例9: Execute

		public void Execute()
		{
			this.result.CloseWindow = false;
			this.result.DataChanged = true;

			ImportContext context = new ImportContext(this);

			if (this.EnsureFileLoaded())
			{
				this.actionIndex = 0;
				foreach (var action in this.actions)
				{
					try
					{
						action.DoImport(this.objectSet, context);
					}
					catch (Exception ex)
					{
						this.log.AppendFormat("发生错误:{0} 已终止了操作,堆栈:\r\n{1}\r\n", ex.Message, ex.StackTrace);
						break;
					}

					this.actionIndex++;
				}
			}

			this.log.AppendLine("导入操作结束");
			this.status.CurrentStep = this.status.MaxStep;
			this.status.StatusText = "结束";
			this.status.Response();
			this.result.ProcessLog = this.log.ToString();
		}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:32,代码来源:ImportExecutor.cs

示例10: ImportValue

        protected override object ImportValue(ImportContext context, JsonReader reader)
        {
            if (context == null)
                throw new ArgumentNullException("reader");

            if (reader == null)
                throw new ArgumentNullException("reader");
            
            if (reader.TokenClass != JsonTokenClass.Number && reader.TokenClass != JsonTokenClass.String)
                throw new JsonException(string.Format("Found {0} where expecting a number.", reader.TokenClass));

            string text = reader.Text;
            
            try
            {
                return ConvertFromString(text);
            }
            catch (FormatException e)
            {
                throw NumberError(e, text);
            }
            catch (OverflowException e)
            {
                throw NumberError(e, text);
            }
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:26,代码来源:NumberImporter.cs

示例11: ImportFromString

        protected override object ImportFromString(ImportContext context, JsonReader reader)
        {
            Debug.Assert(context != null);
            Debug.Assert(reader != null);

            return ReadReturning(reader, reader.Text);
        }
开发者ID:liuxing7954,项目名称:cangku_1,代码行数:7,代码来源:StringImporter.cs

示例12: ImportFromObject

        protected override object ImportFromObject(ImportContext context, JsonReader reader)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (reader == null)
                throw new ArgumentNullException("reader");

            //
            // Reader must be sitting on an object.
            //

            if (reader.TokenClass != JsonTokenClass.Object)
                throw new JsonException("Expecting object.");

            reader.Read();

            //
            // Create the NameValueCollection object being deserialized.
            // If a hint was supplied, then that's what we will create
            // here because it could be that the caller wants to
            // return a subtype of NameValueCollection.
            //

            NameValueCollection collection = CreateCollection();

            //
            // Loop through all members of the object.
            //

            while (reader.TokenClass != JsonTokenClass.EndObject)
            {
                string name = reader.ReadMember();

                //
                // If the value is an array, then it's a multi-value
                // entry otherwise a single-value one.
                //

                if (reader.TokenClass == JsonTokenClass.Array)
                {
                    reader.Read();

                    while (reader.TokenClass != JsonTokenClass.EndArray)
                    {
                        collection.Add(name, GetValueAsString(reader));
                        reader.Read();
                    }
                }
                else
                {
                    collection.Add(name, GetValueAsString(reader));
                }

                reader.Read(); // EndArray/String
            }

            return ReadReturning(reader, collection);
        }
开发者ID:GroupXTech,项目名称:Yatse2,代码行数:59,代码来源:NameValueCollectionImporter.cs

示例13: CreateObject

 public void CreateObject()
 {
     ObjectSurrogateConstructor ctor = new ObjectSurrogateConstructor(typeof(Surrogate));
     ImportContext context = new ImportContext();
     ObjectConstructionResult result = ctor.CreateObject(context, JsonText.CreateReader("{y:2000,m:12,d:4}"));
     Assert.IsNotNull(result);
     Assert.AreEqual(new DateTime(2000, 12, 4), result.Object);
 }
开发者ID:db48x,项目名称:KeeFox,代码行数:8,代码来源:TestObjectSurrogateConstructor.cs

示例14: 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

示例15: Import

 public virtual object Import(ImportContext context, JsonReader reader)
 {
     if (context == null) 
         throw new ArgumentNullException("context");
     if (reader == null) 
         throw new ArgumentNullException("reader");
     
     return JsonBuffer.From(reader);
 }
开发者ID:db48x,项目名称:KeeFox,代码行数:9,代码来源:JsonBufferImporter.cs


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