|
|
|
|
@ -126,6 +126,7 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -126,6 +126,7 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
DefaultTypeDefinition newType; |
|
|
|
|
if (currentTypeDefinition != null) { |
|
|
|
|
newType = new DefaultTypeDefinition(currentTypeDefinition, name); |
|
|
|
|
newType.TypeParameters.AddRange(currentTypeDefinition.TypeParameters); |
|
|
|
|
currentTypeDefinition.InnerClasses.Add(newType); |
|
|
|
|
} else { |
|
|
|
|
newType = new DefaultTypeDefinition(usingScope.ProjectContent, usingScope.NamespaceName, name); |
|
|
|
|
@ -149,7 +150,7 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -149,7 +150,7 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
else if (td.ClassType == ClassType.Enum || td.ClassType == ClassType.Struct) |
|
|
|
|
td.IsSealed = true; // enums/structs are implicitly sealed
|
|
|
|
|
|
|
|
|
|
ConvertTypeParameters(td.TypeParameters, typeDeclaration.TypeParameters, typeDeclaration.Constraints); |
|
|
|
|
ConvertTypeParameters(td.TypeParameters, typeDeclaration.TypeParameters, typeDeclaration.Constraints, EntityType.TypeDefinition); |
|
|
|
|
|
|
|
|
|
foreach (AstType baseType in typeDeclaration.BaseTypes) { |
|
|
|
|
td.BaseTypes.Add(ConvertType(baseType)); |
|
|
|
|
@ -175,7 +176,7 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -175,7 +176,7 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
ApplyModifiers(td, delegateDeclaration.Modifiers); |
|
|
|
|
td.IsSealed = true; // delegates are implicitly sealed
|
|
|
|
|
|
|
|
|
|
ConvertTypeParameters(td.TypeParameters, delegateDeclaration.TypeParameters, delegateDeclaration.Constraints); |
|
|
|
|
ConvertTypeParameters(td.TypeParameters, delegateDeclaration.TypeParameters, delegateDeclaration.Constraints, EntityType.TypeDefinition); |
|
|
|
|
|
|
|
|
|
ITypeReference returnType = ConvertType(delegateDeclaration.ReturnType); |
|
|
|
|
List<IParameter> parameters = new List<IParameter>(); |
|
|
|
|
@ -303,7 +304,12 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -303,7 +304,12 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
if (!enumMemberDeclaration.Initializer.IsNull) { |
|
|
|
|
field.ConstantValue = ConvertConstantValue(currentTypeDefinition, enumMemberDeclaration.Initializer); |
|
|
|
|
} else { |
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
IField prevField = currentTypeDefinition.Fields.LastOrDefault(); |
|
|
|
|
if (prevField == null || prevField.ConstantValue == null) { |
|
|
|
|
field.ConstantValue = ConvertConstantValue(currentTypeDefinition, new PrimitiveExpression(0)); |
|
|
|
|
} else { |
|
|
|
|
field.ConstantValue = new IncrementConstantValue(prevField.ConstantValue); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
currentTypeDefinition.Fields.Add(field); |
|
|
|
|
@ -320,7 +326,7 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -320,7 +326,7 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
m.BodyRegion = MakeRegion(methodDeclaration.Body); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ConvertTypeParameters(m.TypeParameters, methodDeclaration.TypeParameters, methodDeclaration.Constraints); |
|
|
|
|
ConvertTypeParameters(m.TypeParameters, methodDeclaration.TypeParameters, methodDeclaration.Constraints, EntityType.Method); |
|
|
|
|
m.ReturnType = ConvertType(methodDeclaration.ReturnType); |
|
|
|
|
ConvertAttributes(m.Attributes, methodDeclaration.Attributes.Where(s => s.AttributeTarget != "return")); |
|
|
|
|
ConvertAttributes(m.ReturnTypeAttributes, methodDeclaration.Attributes.Where(s => s.AttributeTarget == "return")); |
|
|
|
|
@ -339,10 +345,41 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -339,10 +345,41 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
return m; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ConvertTypeParameters(IList<ITypeParameter> output, IEnumerable<TypeParameterDeclaration> typeParameters, IEnumerable<Constraint> constraints) |
|
|
|
|
{ |
|
|
|
|
if (typeParameters.Any()) |
|
|
|
|
throw new NotImplementedException(); |
|
|
|
|
void ConvertTypeParameters(IList<ITypeParameter> output, AstNodeCollection<TypeParameterDeclaration> typeParameters, AstNodeCollection<Constraint> constraints, EntityType ownerType) |
|
|
|
|
{ |
|
|
|
|
// output might be non-empty when type parameters were copied from an outer class
|
|
|
|
|
int index = output.Count; |
|
|
|
|
List<DefaultTypeParameter> list = new List<DefaultTypeParameter>(); |
|
|
|
|
foreach (TypeParameterDeclaration tpDecl in typeParameters) { |
|
|
|
|
DefaultTypeParameter tp = new DefaultTypeParameter(ownerType, index++, tpDecl.Name); |
|
|
|
|
ConvertAttributes(tp.Attributes, tpDecl.Attributes); |
|
|
|
|
tp.Variance = tpDecl.Variance; |
|
|
|
|
list.Add(tp); |
|
|
|
|
output.Add(tp); // tp must be added to list here so that it can be referenced by constraints
|
|
|
|
|
} |
|
|
|
|
foreach (Constraint c in constraints) { |
|
|
|
|
foreach (var tp in list) { |
|
|
|
|
if (tp.Name == c.TypeParameter) { |
|
|
|
|
foreach (AstType type in c.BaseTypes) { |
|
|
|
|
PrimitiveType primType = type as PrimitiveType; |
|
|
|
|
if (primType != null) { |
|
|
|
|
if (primType.Keyword == "new") { |
|
|
|
|
tp.HasDefaultConstructorConstraint = true; |
|
|
|
|
continue; |
|
|
|
|
} else if (primType.Keyword == "class") { |
|
|
|
|
tp.HasReferenceTypeConstraint = true; |
|
|
|
|
continue; |
|
|
|
|
} else if (primType.Keyword == "struct") { |
|
|
|
|
tp.HasValueTypeConstraint = true; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
tp.Constraints.Add(ConvertType(type)); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DefaultExplicitInterfaceImplementation ConvertInterfaceImplementation(AstType interfaceType, string memberName) |
|
|
|
|
@ -627,7 +664,7 @@ namespace ICSharpCode.NRefactory.CSharp
@@ -627,7 +664,7 @@ namespace ICSharpCode.NRefactory.CSharp
|
|
|
|
|
} else { |
|
|
|
|
if (positionalArguments == null) |
|
|
|
|
positionalArguments = new List<IConstantValue>(); |
|
|
|
|
positionalArguments.Add(ConvertAttributeArgument(nae.Expression)); |
|
|
|
|
positionalArguments.Add(ConvertAttributeArgument(expr)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|