public override bool TryConvert(System.Dynamic.ConvertBinder binder, out object result) { if (binder.Type == typeof(IDataRecord)) { result = _row; return(true); } return(base.TryConvert(binder, out result)); }
public override bool TryConvert(System.Dynamic.ConvertBinder binder, out object result) { result = null; try { //convert value to requested type result = Convert.ChangeType(value, binder.Type); //conversion successful return(true); } catch { //Convertion failed. reset. result = null; } return(base.TryConvert(binder, out result)); }
public override bool TryConvert(System.Dynamic.ConvertBinder binder, out object result) { if (binder.ReturnType == typeof(string)) { result = null; } else if (binder.ReturnType.IsValueType) { result = Activator.CreateInstance(binder.ReturnType); } else { result = null; } return(true); }
/// <summary> /// handles any conversion call. /// </summary> /// <param name="binder"></param> /// <param name="result"></param> /// <returns>true if successful.</returns> public override bool TryConvert(System.Dynamic.ConvertBinder binder, out object result) { result = null; if (binder.Type.IsInterface) { _interfaceTypes.Insert(0, binder.Type); result = Impromptu.DynamicActLike(Target, _interfaceTypes.ToArray()); return(true); } if (binder.Type.IsInstanceOfType(Target)) { result = Target; } return(false); }
/// <summary> /// Dynamic try conversion operation /// </summary> /// <param name="binder">The binder</param> /// <param name="result">The result</param> /// <returns>True if converted</returns> public override bool TryConvert(System.Dynamic.ConvertBinder binder, out object result) { try { if (binder.Type == typeof(DataValue)) { result = this; } else { result = Convert.ChangeType(this.Value, binder.Type); } return(true); } catch (InvalidCastException) { } return(base.TryConvert(binder, out result)); }
public virtual bool TryConvert(System.Dynamic.ConvertBinder binder, out object result) { throw null; }
public virtual System.Dynamic.DynamicMetaObject BindConvert(System.Dynamic.ConvertBinder binder) { throw null; }
public override bool TryConvert(System.Dynamic.ConvertBinder binder, out object result) { result = this; return(true); }
public virtual bool TryConvert(System.Dynamic.ConvertBinder binder, out object result) { result = default(object); return(default(bool)); }
public virtual System.Dynamic.DynamicMetaObject BindConvert(System.Dynamic.ConvertBinder binder) { return(default(System.Dynamic.DynamicMetaObject)); }
/// <summary> /// Provides implementation for type conversion operations. Classes derived from the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for operations that convert an object from one type to another. /// </summary> /// <param name="binder">Provides information about the conversion operation. The binder.Type property provides the type to which the object must be converted. For example, for the statement (String)sampleObject in C# (CType(sampleObject, Type) in Visual Basic), where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, binder.Type returns the <see cref="T:System.String" /> type. The binder.Explicit property provides information about the kind of conversion that occurs. It returns true for explicit conversion and false for implicit conversion.</param> /// <param name="result">The result of the type conversion operation.</param> /// <returns> /// true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.) /// </returns> public override bool TryConvert(System.Dynamic.ConvertBinder binder, out object result) { result = StUtil.Utilities.TypeUtilities.ConvertType(base.Target, binder.Type); return(true); }