src/Shared/EntityFramework/Core/Metadata/Edm/Facet.cs
// <summary>
// Creates a Facet instance with the specified value for the given
// facet description.
// </summary>
// <param name="facetDescription"> The object describing this facet </param>
// <param name="value"> The value of the facet </param>
// <param name="bypassKnownValues"> true to bypass caching and known values; false otherwise. </param>
// <exception cref="System.ArgumentNullException">Thrown if facetDescription argument is null</exception>
Creates a Facet instance with the specified value for the given
facet description.
Creates a Facet instance with the specified value for the given facet description .
internal static Facet Create(FacetDescription facetDescription, object value, bool bypassKnownValues)
        {
            DebugCheck.NotNull(facetDescription);
            if (!bypassKnownValues)
            {
                if (ReferenceEquals(value, null))
                {
                    return facetDescription.NullValueFacet;
                }
                if (Equals(facetDescription.DefaultValue, value))
                {
                    return facetDescription.DefaultValueFacet;
                }
                if (facetDescription.FacetType.Identity == "Edm.Boolean")
                {
                    var boolValue = (bool)value;
                    return facetDescription.GetBooleanFacet(boolValue);
                }
            }
            var result = new Facet(facetDescription, value);
            if (value != null
                && !Helper.IsUnboundedFacetValue(result)
                && !Helper.IsVariableFacetValue(result)
                && result.FacetType.ClrType != null)
            {
                var valueType = value.GetType();
                Debug.Assert(
                    valueType == result.FacetType.ClrType
                    || result.FacetType.ClrType.IsAssignableFrom(valueType),
                    string.Format(
                        CultureInfo.CurrentCulture, "The facet {0} has type {1}, but a value of type {2} was supplied.", result.Name,
                        result.FacetType.ClrType, valueType)
                    );
            }
            return result;
        }
internal static Facet Create ( FacetDescription facetDescription , object value , bool bypassKnownValues ) { DebugCheck . NotNull ( facetDescription ) ; if ( ! bypassKnownValues ) { if ( ReferenceEquals ( value , null ) ) { return facetDescription . NullValueFacet ; } if ( Equals ( facetDescription . DefaultValue , value ) ) { return facetDescription . DefaultValueFacet ; } if ( facetDescription . FacetType . Identity == " " ) { var boolValue = ( bool ) value ; return facetDescription . GetBooleanFacet ( boolValue ) ; } } var result = new Facet ( facetDescription , value ) ; if ( value != null && ! Helper . IsUnboundedFacetValue ( result ) && ! Helper . IsVariableFacetValue ( result ) && result . FacetType . ClrType != null ) { var valueType = value . GetType ( ) ; Debug . Assert ( valueType == result . FacetType . ClrType || result . FacetType . ClrType . IsAssignableFrom ( valueType ) , string . Format ( CultureInfo . CurrentCulture , " " , result . Name , result . FacetType . ClrType , valueType ) ) ; } return result ; }
Creates a Facet instance with the specified value for the given
facet description.
Creates a Facet instance with the specified value for the given facet description .
// Reuse facets with a null value. // Reuse facets with a default value. // Special case boolean facets. // Check the type of the value only if we know what the correct CLR type is
Thrown if facetDescription argument is null
Thrown if facetDescription argument is null
facetDescription
FacetDescription
The object describing this facet
The object describing this facet
value
object
The value of the facet
The value of the facet
bypassKnownValues
bool
true to bypass caching and known values; false otherwise.
true to bypass caching and known values ; false otherwise .