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


C# ODataFeed.AddFunction方法代码示例

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


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

示例1: WritingFeedWithFunctionAndAction

        public void WritingFeedWithFunctionAndAction()
        {
            ODataFeed feed = new ODataFeed();
            feed.AddAction(new ODataAction { Metadata = new Uri("http://example.org/odata.svc/$metadata#Action"), Target = new Uri("http://example.org/odata.svc/DoAction"), Title = "ActionTitle" });
            feed.AddFunction(new ODataFunction() { Metadata = new Uri("http://example.org/odata.svc/$metadata#Function"), Target = new Uri("http://example.org/odata.svc/DoFunction"), Title = "FunctionTitle" });

            ODataItem[] itemsToWrite = new ODataItem[]
            {
                feed,
                this.entryWithOnlyData1,
            };

            string result = this.GetWriterOutputForContentTypeAndKnobValue("application/json;odata.metadata=minimal", true, itemsToWrite, Model, EntitySet, EntityType);

            const string expectedPayload = "{\"" +
                                                "@odata.context\":\"http://example.org/odata.svc/$metadata#EntitySet\"," +
                                                 "\"#Action\":{" +
                                                        "\"title\":\"ActionTitle\"," +
                                                        "\"target\":\"http://example.org/odata.svc/DoAction\"" +
                                                    "}," +
                                                    "\"#Function\":{" +
                                                        "\"title\":\"FunctionTitle\"," +
                                                        "\"target\":\"http://example.org/odata.svc/DoFunction\"" +
                                                    "}," +
                                                "\"value\":[" +
                                                    "{" +
                                                         "\"ID\":101,\"Name\":\"Alice\"" +
                                                    "}" +
                                                    "]" +
                                            "}";
            result.Should().Be(expectedPayload);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:32,代码来源:FullPayloadValidateTests.cs

示例2: CreateODataOperationAndAddToFeed

        /// <summary>
        /// Creates a new instance of ODataAction or ODataFunction for the <paramref name="metadataReferencePropertyName"/>.
        /// </summary>
        /// <param name="feed">The feed to add the action or function .</param>
        /// <param name="metadataReferencePropertyName">The name of the metadata reference property being read.</param>
        /// <returns>A new instance of ODataAction or ODataFunction for the <paramref name="metadataReferencePropertyName"/>.</returns>
        private ODataOperation CreateODataOperationAndAddToFeed(ODataFeed feed, string metadataReferencePropertyName)
        {
            string fullyQualifiedOperationName = ODataJsonLightUtils.GetUriFragmentFromMetadataReferencePropertyName(this.ContextUriParseResult.MetadataDocumentUri, metadataReferencePropertyName);
            IEdmOperation firstActionOrFunction = this.JsonLightInputContext.Model.ResolveOperations(fullyQualifiedOperationName).FirstOrDefault();

            bool isAction;

            if (firstActionOrFunction == null)
            {
                // Ignore the unknown function/action.
                return null;
            }

            var operation = ODataJsonLightUtils.CreateODataOperation(this.ContextUriParseResult.MetadataDocumentUri, metadataReferencePropertyName, firstActionOrFunction, out isAction);

            if (isAction)
            {
                feed.AddAction((ODataAction)operation);
            }
            else
            {
                feed.AddFunction((ODataFunction)operation);
            }

            return operation;
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:32,代码来源:ODataJsonLightEntryAndFeedDeserializer.cs

示例3: AddFunctionShouldAddFunctionToFeed

 public void AddFunctionShouldAddFunctionToFeed()
 {
     ODataFeed feed = new ODataFeed();
     feed.Functions.Count().Should().Be(0);
     feed.AddFunction(new ODataFunction());
     feed.Functions.Count().Should().Be(1);
     feed.AddFunction(new ODataFunction());
     feed.Functions.Count().Should().Be(2);
 }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:9,代码来源:ReadOnlyEnumerableTests.cs


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