예제 #1
0
        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");
            }
        }
예제 #2
0
            /// <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);
            }
예제 #3
0
            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);
                }
            }
예제 #4
0
        internal static IGeneralMemberUniqueIdentifier GetTypeCoercionOperatorIdentifier(ICliMetadataMethodDefinitionTableRow methodDef, IType owner, _ICliManager manager)
        {
            var coercionParameter = methodDef.Signature.Parameters.FirstOrDefault();

            if (coercionParameter == null)
            {
                return(null);
            }
            var coercionType = manager.ObtainTypeReference(coercionParameter.ParameterType, owner, null, owner == null ? null : owner.Assembly);
            var returnType   = manager.ObtainTypeReference(methodDef.Signature.ReturnType, owner, null, owner == null ? null : owner.Assembly);

            if (coercionType == null || returnType == null)
            {
                return(null);
            }
            var genericOwner = owner as IGenericType;
            TypeConversionRequirement requirement = (methodDef.Name == CliCommon.TypeCoercionNames.Implicit) ? TypeConversionRequirement.Implicit : (methodDef.Name == CliCommon.TypeCoercionNames.Explicit) ? TypeConversionRequirement.Explicit : TypeConversionRequirement.Unknown;

            if (genericOwner == null)
            {
                goto nonGenericResolution;
            }
            else
            {
                if (owner.IsGenericConstruct)
                {
                    if (TypesAreEquivalent(owner, coercionType))
                    {
                        return(TypeSystemIdentifiers.GetTypeOperatorFromIdentifier(requirement, returnType));
                    }
                    else if (TypesAreEquivalent(owner, returnType))
                    {
                        return(TypeSystemIdentifiers.GetTypeOperatorToIdentifier(requirement, coercionType));
                    }
                    else
                    {
                        goto nonGenericResolution;
                    }
                }
                else
                {
                    goto nonGenericResolution;
                }
            }
nonGenericResolution:
            if (owner == coercionType)
            {
                return(TypeSystemIdentifiers.GetTypeOperatorFromIdentifier(requirement, returnType));
            }
            else if (owner == returnType)
            {
                return(TypeSystemIdentifiers.GetTypeOperatorToIdentifier(requirement, coercionType));
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
            /// <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");
                }
            }
예제 #7
0
 ITypeCoercionMember ITypeCoercionMemberDictionary.this[TypeConversionRequirement requirement, TypeConversionDirection direction, IType target]
 {
     get { return(this[requirement, direction, target]); }
 }
예제 #8
0
 IIntermediateTypeCoercionMember IIntermediateTypeCoercionMemberDictionary.Add(TypeConversionRequirement requirement, TypeConversionDirection direction, IType target)
 {
     return(this.Add(requirement, direction, target));
 }
예제 #9
0
 public static ITypeCoercionUniqueIdentifier GetTypeOperatorFromIdentifier(TypeConversionRequirement requirement, IType coercionType)
 {
     return(GetTypeOperatorIdentifier(requirement, TypeConversionDirection.FromContainingType, coercionType));
 }
예제 #10
0
 public static ITypeCoercionUniqueIdentifier GetTypeOperatorFromIdentifier(TypeConversionRequirement requirement, IType coercionType, string languageSpecificQualifier)
 {
     return(GetTypeOperatorIdentifier(requirement, TypeConversionDirection.FromContainingType, coercionType, languageSpecificQualifier));
 }
예제 #11
0
 public static ITypeCoercionUniqueIdentifier GetTypeOperatorIdentifier(TypeConversionRequirement requirement, TypeConversionDirection direction, IType coercionType)
 {
     return(new DefaultTypeCoercionUniqueIdentifier(requirement, direction, coercionType));
 }
예제 #12
0
 public static ITypeCoercionUniqueIdentifier GetTypeOperatorIdentifier(TypeConversionRequirement requirement, TypeConversionDirection direction, IType coercionType, string languageSpecificQualifier)
 {
     return(new DefaultTypeCoercionUniqueIdentifier(requirement, direction, coercionType, languageSpecificQualifier));
 }
예제 #13
0
        /// <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);
            }
        }