本文整理汇总了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);
}
示例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;
}
示例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);
}