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


C# ImportContext.Register方法代码示例

本文整理汇总了C#中Jayrock.Json.Conversion.ImportContext.Register方法的典型用法代码示例。如果您正苦于以下问题:C# ImportContext.Register方法的具体用法?C# ImportContext.Register怎么用?C# ImportContext.Register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Jayrock.Json.Conversion.ImportContext的用法示例。


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

示例1: Registration

 public void Registration()
 {
     ImportContext context = new ImportContext();
     ThingImporter importer = new ThingImporter();
     context.Register(importer);
     Assert.AreSame(importer, context.FindImporter(typeof(Thing)));
 }
开发者ID:bubbafat,项目名称:Hebo,代码行数:7,代码来源:TestImportContext.cs

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

示例3: TransportComponent

        private TransportComponent()
        {
            JsonExportContext = JsonConvert.CreateExportContext();
              JsonExportContext.Register(new TransportMessageExporter());

              JsonImportContext = JsonConvert.CreateImportContext();
              JsonImportContext.Register(new TransportMessageImporter());

              TransportListeners.Add(this);
        }
开发者ID:hcilab-um,项目名称:tPad,代码行数:10,代码来源:TransportComponent.cs

示例4: 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);
        }
开发者ID:db48x,项目名称:KeeFox,代码行数:51,代码来源:TestComponentImporter.cs

示例5: 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;
        }
开发者ID:shalstvedt,项目名称:client,代码行数:29,代码来源:nuiState.cs

示例6: MemberImportCustomization

        public void MemberImportCustomization()
        {
            ArrayList calls = new ArrayList();

            TestTypeDescriptor logicalType = new TestTypeDescriptor();
            PropertyDescriptorCollection properties = logicalType.GetProperties();

            properties.Add(new TestPropertyDescriptor("prop1", typeof(object), new Hashtable()));

            TestObjectMemberImporter memberImporter = new TestObjectMemberImporter(calls);
            Hashtable services = new Hashtable();
            services.Add(typeof(IObjectMemberImporter), memberImporter);
            properties.Add(new TestPropertyDescriptor("prop2", typeof(object), services));

            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.WriteEndObject();

            JsonReader reader = writer.CreatePlayer();
            Thing thing = (Thing) context.Import(typeof(Thing), reader);

            Assert.AreEqual(1, calls.Count);

            Assert.AreSame(memberImporter, calls[0]);
            Assert.AreEqual(new object[] { context, reader, thing }, memberImporter.ImportArgs);
            Assert.AreEqual("value2", memberImporter.ImportedValue);
        }
开发者ID:krbvroc1,项目名称:KeeFox,代码行数:35,代码来源:TestComponentImporter.cs

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

示例8: 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();
        }
开发者ID:db48x,项目名称:KeeFox,代码行数:87,代码来源:Program.cs

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

示例10: Register

            public Builder Register(ImportContext context)
            {
                if (context == null) throw new ArgumentNullException("context");

                context.Register(new ComponentImporter(_type, ToCustomType()));
                return this;
            }
开发者ID:db48x,项目名称:KeeFox,代码行数:7,代码来源:JsonType.cs

示例11: NavigatePush

        /************************************************************************/
        /* NAVIGATE                                                             */
        /************************************************************************/
        //! move into next pipeline 
#if TEST
        public PipelineDescriptor NavigatePush(int moduleIdx)
        {
            ImportContext impctx = new ImportContext();
            impctx.Register(new ListImporter<ModuleDescriptor>());
            impctx.Register(new ListImporter<ConnectionDescriptor>());
            impctx.Register(new ListImporter<EndpointDescriptor>());

            PipelineDescriptor newPipeline = ((Response<PipelineDescriptor>)impctx.Import(
                typeof(Response<PipelineDescriptor>),
                JsonText.CreateReader(test_Pipeline1JSON))).GetResponse();

            NuiState.Instance.level++;
            currentPipeline = newPipeline;

            return newPipeline;
        }
开发者ID:RyanWangTHU,项目名称:ccv2,代码行数:21,代码来源:nuiState.cs


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