public Object Convert(Object item, TypeConversionDirection direction) { var conversionMethodName = String.Empty; switch (direction) { case TypeConversionDirection.DatabaseToProperty: { conversionMethodName = ConversionToPropertyMethodName; } break; case TypeConversionDirection.PropertyToDatabase: { conversionMethodName = ConversionToDatabaseMethodName; } break; default: throw new NotImplementedException("Not a valid TypeConversionDirection."); } return ConverterClass.InvokeMember( conversionMethodName, BindingFlags.InvokeMethod, null, null, new[] { item } ); }
public Object Convert(Object item, TypeConversionDirection direction) { var conversionMethodName = String.Empty; switch (direction) { case TypeConversionDirection.DatabaseToProperty: { conversionMethodName = ConversionToPropertyMethodName; } break; case TypeConversionDirection.PropertyToDatabase: { conversionMethodName = ConversionToDatabaseMethodName; } break; default: throw new NotImplementedException("Not a valid TypeConversionDirection."); } return(ConverterClass.InvokeMember( conversionMethodName, BindingFlags.InvokeMethod, null, null, new[] { item } )); }
ITypeCoercionMember ITypeCoercionMemberDictionary.this[TypeConversionRequirement requirement, TypeConversionDirection direction, IType target] { get { return(this[requirement, direction, target]); } }
IIntermediateTypeCoercionMember IIntermediateTypeCoercionMemberDictionary.Add(TypeConversionRequirement requirement, TypeConversionDirection direction, IType target) { return(this.Add(requirement, direction, target)); }
/// <summary> /// Adds a new <see cref="IIntermediateTypeCoercionMember{TCoercionParent, TIntermediateCoercionParent}"/> /// with the conversion <paramref name="requirement"/>, <paramref name="direction"/> and target. /// </summary> /// <param name="requirement">The <see cref="TypeConversionRequirement"/> /// which determines how the cast is applied.</param> /// <param name="direction">The coercion direction; /// either from or to the type.</param> /// <param name="target"> /// The <see cref="IType"/> which is coerced.</param> /// <returns>A new <see cref="IIntermediateTypeCoercionMember{TType, TIntermediateType}"/> /// instance.</returns> /// <exception cref="System.ArgumentException">thrown when <paramref name="target"/> /// is an interface.</exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// thrown when either <paramref name="requirement"/> or /// <paramref name="direction"/> is out of range.</exception> /// <exception cref="System.ArgumentNullException">thrown when <paramref name="target"/> is null.</exception> public IIntermediateTypeCoercionMember <TType, TIntermediateType> Add(TypeConversionRequirement requirement, TypeConversionDirection direction, IType target) { if (target == null) { throw new ArgumentNullException("target"); } else if (target.Type == TypeKind.Interface) { throw new ArgumentException(Resources.Exception_Argument_CoercionType_CannotBeInterface); } TypeCoercionMember member = this.Parent.GetNewTypeCoercion(requirement, direction, target);// new TypeCoercionMember(this.Parent); switch (requirement) { case TypeConversionRequirement.Explicit: case TypeConversionRequirement.Implicit: break; default: throw new ArgumentOutOfRangeException("requirement"); } switch (direction) { case TypeConversionDirection.ToContainingType: case TypeConversionDirection.FromContainingType: break; default: throw new ArgumentOutOfRangeException("direction"); } this.AddDeclaration(member); return(member); }
/// <summary> /// Returns the <see cref="IIntermediateTypeCoercionMember{TCoercionParent, TIntermediateCoercionParent}"/> /// which meets the <paramref name="requirement"/> in /// the <paramref name="direction"/> for /// the <paramref name="target"/> specified. /// </summary> /// <param name="requirement">The <see cref="TypeConversionRequirement"/> /// necessary for the coercion, either /// explicit or implicit.</param> /// <param name="direction">The coercion direction; /// either from or to the type.</param> /// <param name="target"> /// The <see cref="IType"/> which is coerced.</param> /// <returns>The <see cref="IIntermediateTypeCoercionMember{TCoercionParent, TIntermediateCoercionParent}"/> /// which met the <paramref name="requirement"/> in /// the <paramref name="direction"/> for /// the <paramref name="target"/> specified</returns> /// <exception cref="System.ArgumentException"> /// thrown when there is no explicit/implicit coercion /// from/to <paramref name="target"/>. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// thrown when either <paramref name="requirement"/> or /// <paramref name="direction"/> is out of range.</exception> public IIntermediateTypeCoercionMember <TType, TIntermediateType> this[TypeConversionRequirement requirement, TypeConversionDirection direction, IType target] { get { if (target == null) { throw new ArgumentNullException("target"); } else if (target is IInterfaceType) { throw new ArgumentException(Resources.Exception_Argument_CoercionType_CannotBeInterface); } switch (requirement) { case TypeConversionRequirement.Explicit: case TypeConversionRequirement.Implicit: break; default: throw new ArgumentOutOfRangeException("requirement"); } switch (direction) { case TypeConversionDirection.ToContainingType: case TypeConversionDirection.FromContainingType: break; default: throw new ArgumentOutOfRangeException("direction"); } foreach (var item in this.Values) { if (item.Requirement == requirement && item.Direction == direction && item.CoercionType.Equals(target)) { return(item); } } throw new ArgumentException("target"); } }
public static ITypeCoercionUniqueIdentifier GetTypeOperatorImplicitIdentifier(TypeConversionDirection direction, IType coercionType) { return(GetTypeOperatorIdentifier(TypeConversionRequirement.Implicit, direction, coercionType)); }
public static ITypeCoercionUniqueIdentifier GetTypeOperatorImplicitIdentifier(TypeConversionDirection direction, IType coercionType, string languageSpecificQualifier) { return(GetTypeOperatorIdentifier(TypeConversionRequirement.Implicit, direction, coercionType, languageSpecificQualifier)); }
public static ITypeCoercionUniqueIdentifier GetTypeOperatorIdentifier(TypeConversionRequirement requirement, TypeConversionDirection direction, IType coercionType) { return(new DefaultTypeCoercionUniqueIdentifier(requirement, direction, coercionType)); }
/// <summary> /// Adds a new implicit <see cref="ITypeConversionOverloadMember"/> with the <paramref name="direction"/> and <paramref name="coercionType"/> /// provided. /// </summary> /// <param name="direction">The direction of the conversion.</param> /// <param name="coercionType">The type the type coercion is translated from/to based upon /// <paramref name="direction"/>.</param> /// <returns>A new implicit <see cref="ITypeConversionOverloadMember"/> implementation.</returns> public ITypeConversionOverloadMember AddNewImplicit(TypeConversionDirection direction, ITypeReference coercionType) { return(this.AddNew(TypeConversionRequirement.Implicit, direction, coercionType)); }
/// <summary> /// Adds a new <see cref="ITypeConversionOverloadMember"/> with the <paramref name="requirement"/>, <paramref name="direction"/> and <paramref name="coercionType"/> /// provided. /// </summary> /// <param name="requirement">Whether the new <see cref="ITypeConversionOverloadMember"/> is /// implicit or explicit</param> /// <param name="direction">The direction of the conversion.</param> /// <param name="coercionType">The type the type coercion is translated from/to based upon /// <paramref name="direction"/>.</param> /// <returns>A new <see cref="ITypeConversionOverloadMember"/> implementation.</returns> public ITypeConversionOverloadMember AddNew(TypeConversionRequirement requirement, TypeConversionDirection direction, ITypeReference coercionType) { ITypeConversionOverloadMember typeConv = new TypeConversionOverloadMember(this.TargetDeclaration); typeConv.CoercionType = coercionType; typeConv.Requirement = requirement; typeConv.Direction = direction; this._Add(typeConv.GetUniqueIdentifier(), typeConv); return(typeConv); }
public ITypeCoercionMember <TCoercionParent> this[TypeConversionRequirement requirement, TypeConversionDirection direction, IType target] { get { switch (requirement) { case TypeConversionRequirement.Explicit: case TypeConversionRequirement.Implicit: break; default: throw new ArgumentOutOfRangeException("requirement"); } switch (direction) { case TypeConversionDirection.ToContainingType: case TypeConversionDirection.FromContainingType: break; default: throw new ArgumentOutOfRangeException("direction"); } foreach (var member in this.Values) { if (member.Direction == direction && member.Requirement == requirement && member.CoercionType == target) { return(member); } } throw new ArgumentException(string.Format("There is no {0} transition {1} '{2}'", requirement == TypeConversionRequirement.Explicit ? "explicit" : "implicit", direction == TypeConversionDirection.FromContainingType ? "from" : "to", target), "target"); } }
public ITypeCoercionMember <TType> this[TypeConversionRequirement requirement, TypeConversionDirection direction, IType target] { get { foreach (var coercion in this.Values) { if (coercion.Requirement == requirement && coercion.Direction == direction) { switch (direction) { case TypeConversionDirection.ToContainingType: if (target.IsAssignableFrom(coercion.CoercionType)) { return(coercion); } break; case TypeConversionDirection.FromContainingType: if (coercion.CoercionType.IsAssignableFrom(target)) { return(coercion); } break; default: break; } } } return(null); } }
/// <summary> /// Returns the <see cref="ITypeCoercionMember{TCoercionParent}"/> /// which meets the <paramref name="requirement"/> in /// the <paramref name="direction"/> for /// the <paramref name="target"/> specified. /// </summary> /// <param name="requirement">The <see cref="TypeConversionRequirement"/> /// necessary for the coercion, either /// explicit or implicit.</param> /// <param name="direction">The coercion direction; /// either from or to the type.</param> /// <param name="target"> /// The <see cref="IType"/> which is coerced.</param> /// <returns>The <see cref="ITypeCoercionMember{TCoercionParent}"/> /// which met the <paramref name="requirement"/> in /// the <paramref name="direction"/> for /// the <paramref name="target"/> specified</returns> /// <exception cref="System.ArgumentException"> /// thrown when there is no explicit/implicit coercion /// from/to <paramref name="target"/>. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// thrown when either <paramref name="requirement"/> or /// <paramref name="direction"/> is out of range.</exception> public ITypeCoercionMember <TCoercionParent> this[TypeConversionRequirement requirement, TypeConversionDirection direction, IType target] { get { switch (requirement) { case TypeConversionRequirement.Explicit: switch (direction) { case TypeConversionDirection.ToContainingType: if (!this.HasExplicitCoercionTo(target)) { throw ThrowHelper.ObtainArgumentException(ArgumentWithException.target, ExceptionMessageId.CoercionDoesNotExist, ThrowHelper.GetArgumentExceptionWord(ExceptionWordId.@explicit), ThrowHelper.GetArgumentExceptionWord(ExceptionWordId.to)); } break; case TypeConversionDirection.FromContainingType: if (!this.HasExplicitCoercionFrom(target)) { throw ThrowHelper.ObtainArgumentException(ArgumentWithException.target, ExceptionMessageId.CoercionDoesNotExist, ThrowHelper.GetArgumentExceptionWord(ExceptionWordId.@explicit), ThrowHelper.GetArgumentExceptionWord(ExceptionWordId.from)); } break; default: throw ThrowHelper.ObtainArgumentOutOfRangeException(ArgumentWithException.direction); } break; case TypeConversionRequirement.Implicit: switch (direction) { case TypeConversionDirection.ToContainingType: if (!this.HasImplicitCoercionTo(target)) { throw ThrowHelper.ObtainArgumentException(ArgumentWithException.target, ExceptionMessageId.CoercionDoesNotExist, ThrowHelper.GetArgumentExceptionWord(ExceptionWordId.@implicit), ThrowHelper.GetArgumentExceptionWord(ExceptionWordId.to)); } break; case TypeConversionDirection.FromContainingType: if (!this.HasImplicitCoercionFrom(target)) { throw ThrowHelper.ObtainArgumentException(ArgumentWithException.target, ExceptionMessageId.CoercionDoesNotExist, ThrowHelper.GetArgumentExceptionWord(ExceptionWordId.@implicit), ThrowHelper.GetArgumentExceptionWord(ExceptionWordId.from)); } break; default: throw ThrowHelper.ObtainArgumentOutOfRangeException(ArgumentWithException.direction); } break; default: throw ThrowHelper.ObtainArgumentOutOfRangeException(ArgumentWithException.requirement); } foreach (ITypeCoercionMember <TCoercionParent> member in this.Values) { if (member.CoercionType.Equals(target) && member.Direction == direction && member.Requirement == requirement) { return(member); } } return(null); } }