示例#1
0
        public MethodName GetConversionOperator(OperatorType operatorType,
                                                TypeName returnType,
                                                TypeName conversionType)
        {
            switch (operatorType)
            {
            case OperatorType.Explicit:
            case OperatorType.Implicit:
                break;

            default:
                throw DotNetFailure.ConversionOperatorExpected("operatorType", operatorType);
            }

            TypeName[] parms = null;
            if (conversionType != null)
            {
                parms = new [] { conversionType };
            }

            return(GetMethod("op_" + operatorType,
                             returnType,
                             null,
                             parms));
        }
示例#2
0
        public GenericInstanceTypeName MakeNullableType()
        {
            if (this.IsByReference)
            {
                throw DotNetFailure.CannotMakeNullableType();
            }

            return(TypeName.Parse("System.Nullable`1").MakeGenericType(this));
        }
示例#3
0
        public ByReferenceTypeName MakeByReferenceType()
        {
            if (this.IsByReference)
            {
                throw DotNetFailure.CannotMakeByReferenceType();
            }

            return(new ByReferenceTypeName(this));
        }
示例#4
0
        private T[] CheckArgs <T>(IEnumerable <T> types)
        {
            if (types == null)
            {
                throw new ArgumentNullException("types");
            }
            var typesArray = types.ToArray();

            if (typesArray.Length != this.GenericParameters.Count)
            {
                throw DotNetFailure.GenericParametersLengthMismatch("types");
            }

            return(typesArray);
        }
示例#5
0
        internal sealed override TypeName CloneBind(TypeName declaring,
                                                    MethodName method)
        {
            var parms = IsMethodGenericParameter
                ? method.GenericParameters
                : declaring.GenericParameters;

            if (Position >= parms.Count)
            {
                throw DotNetFailure.CannotBindGenericParameterName();
            }
            else
            {
                return(parms[Position]);
            }
        }
示例#6
0
        // TODO Add GetMethod where there are generic parameters

        public MethodName GetOperator(OperatorType operatorType)
        {
            if (operatorType == OperatorType.Unknown)
            {
                throw DotNetFailure.UnknownConversionOperatorCannotBeUsed("operatorType", operatorType);
            }
            if (operatorType == OperatorType.Explicit ||
                operatorType == OperatorType.Implicit)
            {
                throw DotNetFailure.UnknownConversionOperatorCannotBeUsed("operatorType", operatorType);
            }

            if (MethodName.IsBinaryOperator(operatorType))
            {
                return(GetBinaryOperator(operatorType, this, this, this));
            }
            return(GetUnaryOperator(operatorType, this, this));
        }
示例#7
0
        public MethodName GetBinaryOperator(OperatorType operatorType,
                                            TypeName leftOperandType,
                                            TypeName rightOperandType,
                                            TypeName resultType)
        {
            if (!MethodName.IsBinaryOperator(operatorType))
            {
                throw DotNetFailure.BinaryOperatorRequired("operatorType", operatorType);
            }

            string name = MethodName.GetOperator(operatorType);

            return(new DefaultMethodName(
                       this,
                       name,
                       DefaultMethodName.SetParameters(new[] { leftOperandType ?? this, rightOperandType ?? this }),
                       DefaultMethodName.SetReturnType(resultType ?? this)
                       ));
        }
示例#8
0
        public MetadataName ConvertTo(SymbolType type)
        {
            switch (type)
            {
            case SymbolType.Field:
                return(Field);

            case SymbolType.Property:
                return(Property);

            case SymbolType.Event:
                return(Event);

            case SymbolType.Method:
                return(Method);

            case SymbolType.Type:
                return(Type);

            case SymbolType.Namespace:
                return(Namespace);

            case SymbolType.Module:
                return(Module);

            case SymbolType.Assembly:
                return(Assembly);

            case SymbolType.Parameter:
            case SymbolType.InternedLocation:
            case SymbolType.Resource:
            case SymbolType.Local:
            case SymbolType.Alias:
            case SymbolType.Attribute:
            case SymbolType.Unknown:
            case SymbolType.Label:
                throw DotNetFailure.CannotConvertToSymbolType(nameof(type), type);

            default:
                throw Failure.NotDefinedEnum(nameof(type), type);
            }
        }
示例#9
0
        protected override MemberName WithDeclaringTypeOverride(TypeName declaringType)
        {
            if (declaringType.IsTypeSpecification)
            {
                var git = declaringType as GenericInstanceTypeName;
                if (git != null)
                {
                    declaringType = git.ElementType;
                }
                else
                {
                    throw DotNetFailure.NotSupportedBySpecifications();
                }
            }

            var result = new DefaultTypeName(_name, (DefaultTypeName)declaringType);

            CopyGenericsTo(result);
            return(result);
        }
示例#10
0
        public GenericInstanceTypeName MakeGenericType(params TypeName[] arguments)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException("arguments");
            }
            if (arguments.Length == 0)
            {
                throw Failure.EmptyCollection("arguments");
            }
            if (arguments.Any(t => t == null))
            {
                throw Failure.CollectionContainsNullElement("arguments");
            }
            if (arguments.Length != this.GenericParameterCount)
            {
                throw DotNetFailure.GenericParametersLengthMismatch("arguments");
            }

            return(new GenericInstanceTypeName(this, arguments));
        }
示例#11
0
        public MethodName GetUnaryOperator(OperatorType operatorType,
                                           TypeName resultType,
                                           TypeName operandType
                                           )
        {
            string name;

            switch (operatorType)
            {
            case OperatorType.Decrement:
            case OperatorType.Increment:
            case OperatorType.False:
            case OperatorType.True:
            case OperatorType.OnesComplement:
                name = "op_" + operatorType;
                break;

            case OperatorType.UnaryNegation:
                name = "op_Negate";
                break;

            default:
                throw DotNetFailure.UnaryOperatorExpected("operandType", operandType);
            }

            if (resultType == null)
            {
                throw new ArgumentNullException("resultType");
            }

            if (operandType == null)
            {
                throw new ArgumentNullException("operandType");
            }

            return(GetMethod(name, resultType, null, new[] { operandType }));
        }
示例#12
0
        public TypeName GetType(string fullName)
        {
            if (fullName == null)
            {
                throw new ArgumentNullException("fullName");
            }
            if (fullName.Length == 0)
            {
                throw Failure.EmptyString("fullName");
            }

            TypeName tn;

            if (!TypeName.TryParse(fullName, out tn))
            {
                throw Failure.NotParsable("fullName", typeof(TypeName));
            }
            if (tn.IsTypeSpecification)
            {
                throw DotNetFailure.ArgumentCannotBeSpecificationType("fullName");
            }

            return(tn.WithAssembly(this));
        }
示例#13
0
        public TypeName GetNestedType(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (name.Length == 0)
            {
                throw Failure.EmptyString(nameof(name));
            }
            if (IsTypeSpecification && !IsGenericType)
            {
                throw DotNetFailure.NotSupportedBySpecifications();
            }

            TypeName tn;

            if (!TypeName.TryParse(name, TypeNameParseOptions.AssumeGenericParameters, out tn))
            {
                throw Failure.NotParsable(nameof(name), typeof(TypeName));
            }

            return(GetNestedType(tn));
        }
示例#14
0
 public sealed override MethodName WithName(string name)
 {
     throw DotNetFailure.NotSupportedBySpecifications();
 }
示例#15
0
 internal override MethodName WithGenericParameters(GenericParameterName[] parameters)
 {
     throw DotNetFailure.NotSupportedBySpecifications();
 }
示例#16
0
 public override MethodName WithReturnParameter(TypeName returnType, IEnumerable <TypeName> requiredModifiers, IEnumerable <TypeName> optionalModifiers)
 {
     throw DotNetFailure.NotSupportedBySpecifications();
 }
示例#17
0
 protected override MemberName WithDeclaringTypeOverride(TypeName declaringType)
 {
     throw DotNetFailure.NotSupportedBySpecifications();
 }