Ejemplo n.º 1
0
        protected override object GetValueCore(object component)
        {
            if (m_propertyDescriptor != null)
            {
                object value;

                try
                {
                    value = m_propertyDescriptor.GetValue(component);
                }
                catch (DataException)
                {
                    // We have to return null if the datarow is deleted from the DataTable.
                    // When the System.Data.DataRow have RowState == detached, it can be because it has been deleted
                    // or it being inserted, nothing special found to differentiate that 2 state.  So doing a try catch.
                    value = null;
                }

                CultureInfo converterCulture = this.ConverterCulture;

                if (converterCulture == null)
                {
                    converterCulture = CultureInfo.InvariantCulture;
                }

                return(this.GetBindingConverter(component).Convert(
                           value, this.DataType,
                           this.ConverterParameter, converterCulture));
            }

            if (m_bindingPathValueExtractorForRead == null)
            {
                CultureInfo converterCulture = this.ConverterCulture;

                if (converterCulture == null)
                {
                    converterCulture = CultureInfo.InvariantCulture;
                }

                PropertyPath propertyPath = null;

                if (!string.IsNullOrEmpty(this.ValuePath))
                {
                    propertyPath = new PropertyPath(this.ValuePath, BindingPathValueExtractor.EmptyObjectArray);
                }

                m_bindingPathValueExtractorForRead = new BindingPathValueExtractor(
                    this.ValueXPath, propertyPath, false,
                    this.DataType,
                    this.GetBindingConverter(component),
                    this.ConverterParameter, converterCulture);
            }

            return(m_bindingPathValueExtractorForRead.GetValueFromItem(component));
        }
Ejemplo n.º 2
0
        protected override void SetValueCore(object component, object value)
        {
            if (m_propertyDescriptor != null)
            {
                CultureInfo converterCulture = this.ConverterCulture;

                if (converterCulture == null)
                {
                    converterCulture = CultureInfo.InvariantCulture;
                }

                object convertedValue = this.GetBindingConverter(component).ConvertBack(
                    value,
                    m_propertyDescriptor.PropertyType,
                    this.ConverterParameter,
                    converterCulture);

                m_propertyDescriptor.SetValue(component, convertedValue);
            }
            else
            {
                if (m_bindingPathValueExtractorForWrite == null)
                {
                    CultureInfo converterCulture = this.ConverterCulture;

                    if (converterCulture == null)
                    {
                        converterCulture = CultureInfo.InvariantCulture;
                    }

                    PropertyPath propertyPath = null;

                    if (!string.IsNullOrEmpty(this.ValuePath))
                    {
                        propertyPath = new PropertyPath(this.ValuePath, BindingPathValueExtractor.EmptyObjectArray);
                    }

                    m_bindingPathValueExtractorForWrite = new BindingPathValueExtractor(
                        this.ValueXPath, propertyPath, true,
                        this.DataType,
                        this.GetBindingConverter(component), this.ConverterParameter, converterCulture);
                }

                m_bindingPathValueExtractorForWrite.SetValueToItem(component, value);
            }

            base.SetValueCore(component, value);
        }
    protected override void SetValueCore( object component, object value )
    {
      if( m_propertyDescriptor != null )
      {
        CultureInfo converterCulture = this.ConverterCulture;

        if( converterCulture == null )
          converterCulture = CultureInfo.InvariantCulture;

        object convertedValue = this.GetBindingConverter( component ).ConvertBack(
          value,
          m_propertyDescriptor.PropertyType,
          this.ConverterParameter,
          converterCulture );

        m_propertyDescriptor.SetValue( component, convertedValue );
      }
      else
      {
        if( m_bindingPathValueExtractorForWrite == null )
        {
          CultureInfo converterCulture = this.ConverterCulture;

          if( converterCulture == null )
            converterCulture = CultureInfo.InvariantCulture;

          PropertyPath propertyPath = null;

          if( !string.IsNullOrEmpty( this.ValuePath ) )
            propertyPath = new PropertyPath( this.ValuePath, BindingPathValueExtractor.EmptyObjectArray );

          m_bindingPathValueExtractorForWrite = new BindingPathValueExtractor(
            this.ValueXPath, propertyPath, true,
            this.DataType,
            this.GetBindingConverter( component ), this.ConverterParameter, converterCulture );
        }

        m_bindingPathValueExtractorForWrite.SetValueToItem( component, value );
      }

      base.SetValueCore( component, value );
    }
    protected override object GetValueCore( object component )
    {
      if( m_propertyDescriptor != null )
      {
        object value;

        try
        {
          value = m_propertyDescriptor.GetValue( component );
        }
        catch( DataException )
        {
          // We have to return null if the datarow is deleted from the DataTable.
          // When the System.Data.DataRow have RowState == detached, it can be because it has been deleted
          // or it being inserted, nothing special found to differentiate that 2 state.  So doing a try catch.
          value = null;
        }

        CultureInfo converterCulture = this.ConverterCulture;

        if( converterCulture == null )
          converterCulture = CultureInfo.InvariantCulture;

        return this.GetBindingConverter( component ).Convert(
          value, this.DataType,
          this.ConverterParameter, converterCulture );
      }

      if( m_bindingPathValueExtractorForRead == null )
      {
        CultureInfo converterCulture = this.ConverterCulture;

        if( converterCulture == null )
          converterCulture = CultureInfo.InvariantCulture;

        PropertyPath propertyPath = null;

        if( !string.IsNullOrEmpty( this.ValuePath ) )
          propertyPath = new PropertyPath( this.ValuePath, BindingPathValueExtractor.EmptyObjectArray );

        m_bindingPathValueExtractorForRead = new BindingPathValueExtractor(
          this.ValueXPath, propertyPath, false,
          this.DataType,
          this.GetBindingConverter( component ),
          this.ConverterParameter, converterCulture );
      }

      return m_bindingPathValueExtractorForRead.GetValueFromItem( component );
    }