private static ODataOperation CreateODataOperation(IEdmOperation operation, ProcedureLinkBuilder builder, EntityInstanceContext entityInstanceContext) { Contract.Assert(operation != null); Contract.Assert(builder != null); Contract.Assert(entityInstanceContext != null); ODataMetadataLevel metadataLevel = entityInstanceContext.SerializerContext.MetadataLevel; IEdmModel model = entityInstanceContext.EdmModel; if (ShouldOmitOperation(operation, builder, metadataLevel)) { return(null); } Uri target = builder.BuildLink(entityInstanceContext); if (target == null) { return(null); } Uri baseUri = new Uri(entityInstanceContext.Url.CreateODataLink(new MetadataPathSegment())); Uri metadata = new Uri(baseUri, "#" + CreateMetadataFragment(operation)); ODataOperation odataOperation; if (operation is IEdmAction) { odataOperation = new ODataAction(); } else { odataOperation = new ODataFunction(); } odataOperation.Metadata = metadata; // Always omit the title in minimal/no metadata modes. if (metadataLevel == ODataMetadataLevel.FullMetadata) { EmitTitle(model, operation, odataOperation); } // Omit the target in minimal/no metadata modes unless it doesn't follow conventions. if (!builder.FollowsConventions || metadataLevel == ODataMetadataLevel.FullMetadata) { odataOperation.Target = target; } return(odataOperation); }
internal static bool ShouldOmitOperation(IEdmOperation operation, ProcedureLinkBuilder builder, ODataMetadataLevel metadataLevel) { Contract.Assert(builder != null); switch (metadataLevel) { case ODataMetadataLevel.MinimalMetadata: case ODataMetadataLevel.NoMetadata: return(operation.IsBound && builder.FollowsConventions); case ODataMetadataLevel.FullMetadata: default: // All values already specified; just keeping the compiler happy. return(false); } }