本文整理汇总了C#中ODataEntry.GetAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# ODataEntry.GetAnnotation方法的具体用法?C# ODataEntry.GetAnnotation怎么用?C# ODataEntry.GetAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODataEntry
的用法示例。
在下文中一共展示了ODataEntry.GetAnnotation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEntryTypeNameForWriting
/// <summary>
/// Determines the entity type name to write to the payload.
/// </summary>
/// <param name="expectedTypeName">The expected type name, e.g. the base type of the set or the nav prop.</param>
/// <param name="entry">The ODataEntry whose type is to be written.</param>
/// <returns>Type name to write to the payload, or null if no type name should be written.</returns>
internal override string GetEntryTypeNameForWriting(string expectedTypeName, ODataEntry entry)
{
Debug.Assert(entry != null, "entry != null");
SerializationTypeNameAnnotation typeNameAnnotation = entry.GetAnnotation<SerializationTypeNameAnnotation>();
if (typeNameAnnotation != null)
{
return typeNameAnnotation.TypeName;
}
return entry.TypeName;
}
示例2: GetEntryTypeNameForWriting
/// <summary>
/// Determines the entity type name to write to the payload.
/// </summary>
/// <param name="expectedTypeName">The expected type name, e.g. the base type of the set or the nav prop.</param>
/// <param name="entry">The ODataEntry whose type is to be written.</param>
/// <returns>Type name to write to the payload, or null if no type name should be written.</returns>
internal override string GetEntryTypeNameForWriting(string expectedTypeName, ODataEntry entry)
{
Debug.Assert(entry != null, "entry != null");
SerializationTypeNameAnnotation typeNameAnnotation = entry.GetAnnotation<SerializationTypeNameAnnotation>();
if (typeNameAnnotation != null)
{
return typeNameAnnotation.TypeName;
}
// We only write entity type names in Json Light if it's more derived (different) from the expected type name.
string entryTypeName = entry.TypeName;
if (expectedTypeName != entryTypeName)
{
return entryTypeName;
}
return null;
}
示例3: WriteEntryMetadata
/// <summary>
/// Write the ATOM metadata for an entry
/// </summary>
/// <param name="writer">The Xml writer to write to.</param>
/// <param name="baseUri">The base Uri of the document or null if none was specified.</param>
/// <param name="entry">The entry for which to write the metadata.</param>
/// <param name="epmEntryMetadata">The ATOM metadata for the entry which came from EPM.</param>
internal static void WriteEntryMetadata(XmlWriter writer, Uri baseUri, ODataEntry entry, AtomEntryMetadata epmEntryMetadata)
{
DebugUtils.CheckNoExternalCallers();
Debug.Assert(writer != null, "writer != null");
// TODO, ckerer: implement the rule around authors (an entry has to have an author directly or in the <entry:source> unless the feed has an author).
// currently we make all entries have an author.
AtomEntryMetadata customEntryMetadata = entry.GetAnnotation<AtomEntryMetadata>();
AtomEntryMetadata entryMetadata = ODataAtomWriterMetadataEpmMergeUtils.MergeCustomAndEpmEntryMetadata(customEntryMetadata, epmEntryMetadata);
if (entryMetadata == null)
{
// write all required metadata elements with default content
// <atom:title></atom:title>
ODataAtomWriterUtils.WriteEmptyElement(writer, AtomConstants.AtomNamespacePrefix, AtomConstants.AtomTitleElementName, AtomConstants.AtomNamespace);
// <atom:updated>dateTimeOffset</atom:updated>
// NOTE: the <updated> element is required and if not specified the best we can do is to create a default
// one with the current date/time.
ODataAtomWriterUtils.WriteElementWithTextContent(writer, AtomConstants.AtomNamespacePrefix, AtomConstants.AtomUpdatedElementName, AtomConstants.AtomNamespace, ODataAtomConvert.ToString(DateTimeOffset.UtcNow));
WriteEmptyAuthor(writer);
}
else
{
// <atom:title>text</atom:title>
// NOTE: writes an empty element even if no title was specified since the title is required
ODataAtomWriterMetadataUtils.WriteTextConstruct(writer, AtomConstants.AtomNamespacePrefix, AtomConstants.AtomTitleElementName, AtomConstants.AtomNamespace, entryMetadata.Title);
AtomTextConstruct summary = entryMetadata.Summary;
if (summary != null)
{
// <atom:summary>text</atom:summary>
ODataAtomWriterMetadataUtils.WriteTextConstruct(writer, AtomConstants.AtomNamespacePrefix, AtomConstants.AtomSummaryElementName, AtomConstants.AtomNamespace, summary);
}
DateTimeOffset? published = entryMetadata.Published;
if (published.HasValue)
{
// <atom:published>dateTimeOffset</atom:published>
ODataAtomWriterUtils.WriteElementWithTextContent(writer, AtomConstants.AtomNamespacePrefix, AtomConstants.AtomPublishedElementName, AtomConstants.AtomNamespace, ODataAtomConvert.ToString(published.Value));
}
// <atom:updated>date</atom:updated>
// NOTE: the <updated> element is required and if not specified the best we can do is to create a default
// one with the current date/time.
DateTimeOffset updated = entryMetadata.Updated.HasValue ? entryMetadata.Updated.Value : DateTimeOffset.UtcNow;
ODataAtomWriterUtils.WriteElementWithTextContent(
writer,
AtomConstants.AtomNamespacePrefix,
AtomConstants.AtomUpdatedElementName,
AtomConstants.AtomNamespace,
ODataAtomConvert.ToString(updated));
bool wroteAuthor = false;
IEnumerable<AtomPersonMetadata> authors = entryMetadata.Authors;
if (authors != null)
{
foreach (AtomPersonMetadata author in authors)
{
if (author == null)
{
throw new ODataException(Strings.ODataAtomWriterMetadataUtils_AuthorMetadataMustNotContainNull);
}
// <atom:author>author data</atom:author>
writer.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomAuthorElementName, AtomConstants.AtomNamespace);
WritePersonMetadata(writer, baseUri, author);
writer.WriteEndElement();
wroteAuthor = true;
}
}
if (!wroteAuthor)
{
// write empty authors since they are required
WriteEmptyAuthor(writer);
}
IEnumerable<AtomPersonMetadata> contributors = entryMetadata.Contributors;
if (contributors != null)
{
foreach (AtomPersonMetadata contributor in contributors)
{
if (contributor == null)
{
throw new ODataException(Strings.ODataAtomWriterMetadataUtils_ContributorMetadataMustNotContainNull);
}
// <atom:contributor>contributor data</atom:contributor>
writer.WriteStartElement(AtomConstants.AtomNamespacePrefix, AtomConstants.AtomContributorElementName, AtomConstants.AtomNamespace);
WritePersonMetadata(writer, baseUri, contributor);
writer.WriteEndElement();
//.........这里部分代码省略.........