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)); }
public GenericInstanceTypeName MakeNullableType() { if (this.IsByReference) { throw DotNetFailure.CannotMakeNullableType(); } return(TypeName.Parse("System.Nullable`1").MakeGenericType(this)); }
public ByReferenceTypeName MakeByReferenceType() { if (this.IsByReference) { throw DotNetFailure.CannotMakeByReferenceType(); } return(new ByReferenceTypeName(this)); }
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); }
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]); } }
// 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)); }
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) )); }
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); } }
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); }
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)); }
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 })); }
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)); }
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)); }
public sealed override MethodName WithName(string name) { throw DotNetFailure.NotSupportedBySpecifications(); }
internal override MethodName WithGenericParameters(GenericParameterName[] parameters) { throw DotNetFailure.NotSupportedBySpecifications(); }
public override MethodName WithReturnParameter(TypeName returnType, IEnumerable <TypeName> requiredModifiers, IEnumerable <TypeName> optionalModifiers) { throw DotNetFailure.NotSupportedBySpecifications(); }
protected override MemberName WithDeclaringTypeOverride(TypeName declaringType) { throw DotNetFailure.NotSupportedBySpecifications(); }