Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / EntityModel / SchemaObjectModel / ModelFunction.cs / 1305376 / ModelFunction.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Globalization;
using System.Xml;
using System.Xml.Schema;
using System.Data;
using System.IO;
using System.Data.Metadata.Edm;
using System.Data.Entity;
namespace System.Data.EntityModel.SchemaObjectModel
{
///
/// class representing the Schema element in the schema
///
internal class ModelFunction : Function
{
protected TypeUsageBuilder _typeUsageBuilder;
#region Public Methods
///
/// ctor for a schema function
///
public ModelFunction(Schema parentElement)
:
base(parentElement)
{
_isComposable = true;
_typeUsageBuilder = new TypeUsageBuilder(this);
}
#endregion
public override SchemaType Type
{
get
{
return this._type;
}
}
internal TypeUsage TypeUsage
{
get
{
if (_typeUsageBuilder.TypeUsage == null)
{
return null;
}
else if (CollectionKind != CollectionKind.None)
{
return TypeUsage.Create(new CollectionType(_typeUsageBuilder.TypeUsage));
}
else
{
return _typeUsageBuilder.TypeUsage;
}
}
}
internal void ValidateAndSetTypeUsage(ScalarType scalar)
{
_typeUsageBuilder.ValidateAndSetTypeUsage(scalar, false);
}
#region Protected Properties
protected override bool HandleElement(XmlReader reader)
{
if (base.HandleElement(reader))
{
return true;
}
else if (CanHandleElement(reader, XmlConstants.DefiningExpression))
{
HandleDefiningExpressionElment(reader);
return true;
}
else if (CanHandleElement(reader, XmlConstants.Parameter))
{
HandleParameterElement(reader);
return true;
}
return false;
}
protected override void HandleReturnTypeAttribute(XmlReader reader)
{
base.HandleReturnTypeAttribute(reader);
_isComposable = true;
}
protected override bool HandleAttribute(XmlReader reader)
{
if (base.HandleAttribute(reader))
{
return true;
}
else if (_typeUsageBuilder.HandleAttribute(reader))
{
return true;
}
return false;
}
internal override void ResolveTopLevelNames()
{
if (null != UnresolvedReturnType)
{
if (Schema.ResolveTypeName(this, UnresolvedReturnType, out _type))
{
if (_type is ScalarType)
{
_typeUsageBuilder.ValidateAndSetTypeUsage(_type as ScalarType, false);
}
}
}
foreach (Parameter parameter in this.Parameters)
{
parameter.ResolveTopLevelNames();
}
if (ReturnType != null)
{
ReturnType.ResolveTopLevelNames();
}
}
#endregion
private void HandleDefiningExpressionElment(XmlReader reader)
{
Debug.Assert(reader != null);
FunctionCommandText commandText = new FunctionCommandText(this);
commandText.Parse(reader);
_commandText = commandText;
}
internal override void Validate()
{
base.Validate();
if (_type != null && _type is ScalarType == false && _typeUsageBuilder.HasUserDefinedFacets)
{
//Non-scalar return type should not have Facets
AddError(ErrorCode.ModelFuncionFacetOnNonScalarType, EdmSchemaErrorSeverity.Error, Strings.FacetsOnNonScalarType(_type.FQName));
}
if (_type == null && _typeUsageBuilder.HasUserDefinedFacets)
{
//Type attribute not specified but facets exist
AddError(ErrorCode.ModelFunctionIncorrectlyPlacedFacet, EdmSchemaErrorSeverity.Error, Strings.FacetDeclarationRequiresTypeAttribute);
}
if (_type == null && _returnType == null)
{
//Return type not declared as either attribute or subelement
AddError(ErrorCode.ModelFunctionReturnTypeNotDeclared, EdmSchemaErrorSeverity.Error, Strings.ReturnTypeMustBeDeclared(FQName));
}
if (_type != null && _isRefType && !(_type is SchemaEntityType))
{
//Ref type refers to non entity type
AddError(ErrorCode.ReferenceToNonEntityType, EdmSchemaErrorSeverity.Error, Strings.ReferenceToNonEntityType(_type.FQName));
}
foreach (var param in _parameters)
{
param.ValidateForModelFunction();
}
if (_returnType != null)
{
_returnType.ValidateForModelFunction();
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....]
// @backupOwner [....]
//---------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Globalization;
using System.Xml;
using System.Xml.Schema;
using System.Data;
using System.IO;
using System.Data.Metadata.Edm;
using System.Data.Entity;
namespace System.Data.EntityModel.SchemaObjectModel
{
///
/// class representing the Schema element in the schema
///
internal class ModelFunction : Function
{
protected TypeUsageBuilder _typeUsageBuilder;
#region Public Methods
///
/// ctor for a schema function
///
public ModelFunction(Schema parentElement)
:
base(parentElement)
{
_isComposable = true;
_typeUsageBuilder = new TypeUsageBuilder(this);
}
#endregion
public override SchemaType Type
{
get
{
return this._type;
}
}
internal TypeUsage TypeUsage
{
get
{
if (_typeUsageBuilder.TypeUsage == null)
{
return null;
}
else if (CollectionKind != CollectionKind.None)
{
return TypeUsage.Create(new CollectionType(_typeUsageBuilder.TypeUsage));
}
else
{
return _typeUsageBuilder.TypeUsage;
}
}
}
internal void ValidateAndSetTypeUsage(ScalarType scalar)
{
_typeUsageBuilder.ValidateAndSetTypeUsage(scalar, false);
}
#region Protected Properties
protected override bool HandleElement(XmlReader reader)
{
if (base.HandleElement(reader))
{
return true;
}
else if (CanHandleElement(reader, XmlConstants.DefiningExpression))
{
HandleDefiningExpressionElment(reader);
return true;
}
else if (CanHandleElement(reader, XmlConstants.Parameter))
{
HandleParameterElement(reader);
return true;
}
return false;
}
protected override void HandleReturnTypeAttribute(XmlReader reader)
{
base.HandleReturnTypeAttribute(reader);
_isComposable = true;
}
protected override bool HandleAttribute(XmlReader reader)
{
if (base.HandleAttribute(reader))
{
return true;
}
else if (_typeUsageBuilder.HandleAttribute(reader))
{
return true;
}
return false;
}
internal override void ResolveTopLevelNames()
{
if (null != UnresolvedReturnType)
{
if (Schema.ResolveTypeName(this, UnresolvedReturnType, out _type))
{
if (_type is ScalarType)
{
_typeUsageBuilder.ValidateAndSetTypeUsage(_type as ScalarType, false);
}
}
}
foreach (Parameter parameter in this.Parameters)
{
parameter.ResolveTopLevelNames();
}
if (ReturnType != null)
{
ReturnType.ResolveTopLevelNames();
}
}
#endregion
private void HandleDefiningExpressionElment(XmlReader reader)
{
Debug.Assert(reader != null);
FunctionCommandText commandText = new FunctionCommandText(this);
commandText.Parse(reader);
_commandText = commandText;
}
internal override void Validate()
{
base.Validate();
if (_type != null && _type is ScalarType == false && _typeUsageBuilder.HasUserDefinedFacets)
{
//Non-scalar return type should not have Facets
AddError(ErrorCode.ModelFuncionFacetOnNonScalarType, EdmSchemaErrorSeverity.Error, Strings.FacetsOnNonScalarType(_type.FQName));
}
if (_type == null && _typeUsageBuilder.HasUserDefinedFacets)
{
//Type attribute not specified but facets exist
AddError(ErrorCode.ModelFunctionIncorrectlyPlacedFacet, EdmSchemaErrorSeverity.Error, Strings.FacetDeclarationRequiresTypeAttribute);
}
if (_type == null && _returnType == null)
{
//Return type not declared as either attribute or subelement
AddError(ErrorCode.ModelFunctionReturnTypeNotDeclared, EdmSchemaErrorSeverity.Error, Strings.ReturnTypeMustBeDeclared(FQName));
}
if (_type != null && _isRefType && !(_type is SchemaEntityType))
{
//Ref type refers to non entity type
AddError(ErrorCode.ReferenceToNonEntityType, EdmSchemaErrorSeverity.Error, Strings.ReferenceToNonEntityType(_type.FQName));
}
foreach (var param in _parameters)
{
param.ValidateForModelFunction();
}
if (_returnType != null)
{
_returnType.ValidateForModelFunction();
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- BooleanProjectedSlot.cs
- GridViewColumnHeaderAutomationPeer.cs
- WindowInteropHelper.cs
- SafeThemeHandle.cs
- HttpProcessUtility.cs
- baseshape.cs
- CodeGenerator.cs
- EventMap.cs
- ProcessModelSection.cs
- TextMetrics.cs
- Int32Collection.cs
- ListViewSelectEventArgs.cs
- SQLStringStorage.cs
- SignatureHelper.cs
- SiteMapNode.cs
- SchemaImporterExtensionsSection.cs
- RowSpanVector.cs
- PowerStatus.cs
- DynamicResourceExtensionConverter.cs
- ImageSource.cs
- CodeThrowExceptionStatement.cs
- HttpModuleCollection.cs
- PagesSection.cs
- SendMailErrorEventArgs.cs
- DataBoundControl.cs
- TdsParser.cs
- OleDbPropertySetGuid.cs
- RootProfilePropertySettingsCollection.cs
- ParsedAttributeCollection.cs
- HebrewCalendar.cs
- TrackingAnnotationCollection.cs
- Native.cs
- TabletCollection.cs
- DocumentPropertiesDialog.cs
- Events.cs
- ResourceBinder.cs
- Vector3DAnimation.cs
- WpfXamlMember.cs
- TreeNodeStyleCollection.cs
- CachedBitmap.cs
- FrugalMap.cs
- SqlServices.cs
- Vector3D.cs
- SoundPlayer.cs
- XmlDocumentFragment.cs
- HttpListenerException.cs
- DefaultValueTypeConverter.cs
- XPathParser.cs
- CreateUserWizardAutoFormat.cs
- DataServiceProviderMethods.cs
- SoapServerMessage.cs
- CatalogZoneBase.cs
- columnmapkeybuilder.cs
- XamlPathDataSerializer.cs
- BamlResourceDeserializer.cs
- PageVisual.cs
- DescendantBaseQuery.cs
- SqlDataSourceSelectingEventArgs.cs
- DataGridViewColumnEventArgs.cs
- DesignerLabelAdapter.cs
- RSACryptoServiceProvider.cs
- WindowsPen.cs
- CompilerGlobalScopeAttribute.cs
- Int64.cs
- RegexFCD.cs
- Timer.cs
- SafeCancelMibChangeNotify.cs
- FirstMatchCodeGroup.cs
- CommandConverter.cs
- AnimationTimeline.cs
- RuleSet.cs
- SmtpNtlmAuthenticationModule.cs
- BuildResult.cs
- ConfigurationHelpers.cs
- _DisconnectOverlappedAsyncResult.cs
- DesignerGenericWebPart.cs
- OdbcCommandBuilder.cs
- CancellationTokenSource.cs
- HighlightVisual.cs
- JsonReaderWriterFactory.cs
- PaperSource.cs
- ListBindingHelper.cs
- SR.cs
- SqlSupersetValidator.cs
- ConsoleCancelEventArgs.cs
- SQLInt16.cs
- TdsParserStaticMethods.cs
- SystemInformation.cs
- NetMsmqBindingCollectionElement.cs
- ApplyImportsAction.cs
- HttpHandlerActionCollection.cs
- IdentifierElement.cs
- ProcessThreadDesigner.cs
- PhysicalAddress.cs
- KeyValuePair.cs
- CacheForPrimitiveTypes.cs
- CodeArgumentReferenceExpression.cs
- connectionpool.cs
- NativeMethodsCLR.cs
- ColumnMapVisitor.cs