diff --git a/ICSharpCode.NRefactory/CSharp/Analysis/DefiniteAssignmentAnalysis.cs b/ICSharpCode.NRefactory/CSharp/Analysis/DefiniteAssignmentAnalysis.cs index 900a2a967f..c544d2d6c1 100644 --- a/ICSharpCode.NRefactory/CSharp/Analysis/DefiniteAssignmentAnalysis.cs +++ b/ICSharpCode.NRefactory/CSharp/Analysis/DefiniteAssignmentAnalysis.cs @@ -23,6 +23,7 @@ using System.Linq; using System.Threading; using ICSharpCode.NRefactory.CSharp.Resolver; using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.NRefactory.TypeSystem.Implementation; using ICSharpCode.NRefactory.Utils; namespace ICSharpCode.NRefactory.CSharp.Analysis diff --git a/ICSharpCode.NRefactory/CSharp/Ast/AstLocation.cs b/ICSharpCode.NRefactory/CSharp/Ast/AstLocation.cs index 2d0a5a7962..624eb9bf31 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/AstLocation.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/AstLocation.cs @@ -133,5 +133,15 @@ namespace ICSharpCode.NRefactory.CSharp { return !(left < right); } + + public static implicit operator AstLocation(ICSharpCode.Editor.TextLocation location) + { + return new AstLocation(location.Line, location.Column); + } + + public static implicit operator ICSharpCode.Editor.TextLocation(AstLocation location) + { + return new ICSharpCode.Editor.TextLocation(location.Line, location.Column); + } } } diff --git a/ICSharpCode.NRefactory/CSharp/Parser/ParsedFile.cs b/ICSharpCode.NRefactory/CSharp/Parser/ParsedFile.cs index 36b9d1c305..4874a40198 100644 --- a/ICSharpCode.NRefactory/CSharp/Parser/ParsedFile.cs +++ b/ICSharpCode.NRefactory/CSharp/Parser/ParsedFile.cs @@ -115,7 +115,7 @@ namespace ICSharpCode.NRefactory.CSharp return FindEntity(topLevelTypeDefinitions, location); } - public ITypeDefinition GetTypeDefinition(AstLocation location) + public ITypeDefinition GetInnerMostTypeDefinition(AstLocation location) { ITypeDefinition parent = null; ITypeDefinition type = GetTopLevelTypeDefinition(location); @@ -128,7 +128,7 @@ namespace ICSharpCode.NRefactory.CSharp public IMember GetMember(AstLocation location) { - ITypeDefinition type = GetTypeDefinition(location); + ITypeDefinition type = GetInnerMostTypeDefinition(location); if (type == null) return null; return FindEntity(type.Methods, location) diff --git a/ICSharpCode.NRefactory/CSharp/Refactoring/RefactoringContext.cs b/ICSharpCode.NRefactory/CSharp/Refactoring/RefactoringContext.cs index a73d973733..6d2aa2cf79 100644 --- a/ICSharpCode.NRefactory/CSharp/Refactoring/RefactoringContext.cs +++ b/ICSharpCode.NRefactory/CSharp/Refactoring/RefactoringContext.cs @@ -1,4 +1,4 @@ -// +// // RefactoringContext.cs // // Author: @@ -25,9 +25,9 @@ // THE SOFTWARE. using System; using System.Linq; -using ICSharpCode.NRefactory.TypeSystem; -using System.Collections.Generic; using ICSharpCode.NRefactory.CSharp.Resolver; +using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.NRefactory.TypeSystem.Implementation; namespace ICSharpCode.NRefactory.CSharp.Refactoring { @@ -127,12 +127,12 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring } } - public static class ExtensionMethods + public static class RefactoringExtensions { #region ConvertTypes public static ICSharpCode.NRefactory.CSharp.AstType ConvertToAstType (this IType type) { - var builder = new TypeSystemAstBuilder (); + var builder = new TypeSystemAstBuilder (MinimalResolveContext.Instance); return builder.ConvertType (type); } #endregion diff --git a/ICSharpCode.NRefactory/CSharp/Refactoring/TypeSystemAstBuilder.cs b/ICSharpCode.NRefactory/CSharp/Refactoring/TypeSystemAstBuilder.cs index 1299df042e..8594de33ac 100644 --- a/ICSharpCode.NRefactory/CSharp/Refactoring/TypeSystemAstBuilder.cs +++ b/ICSharpCode.NRefactory/CSharp/Refactoring/TypeSystemAstBuilder.cs @@ -8,6 +8,7 @@ using System.Linq; using ICSharpCode.NRefactory.CSharp.Resolver; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem.Implementation; +using ICSharpCode.NRefactory.Utils; namespace ICSharpCode.NRefactory.CSharp.Refactoring { @@ -17,6 +18,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring public class TypeSystemAstBuilder { readonly CSharpResolver resolver; + readonly ITypeResolveContext context; /// /// Creates a new TypeSystemAstBuilder. @@ -24,11 +26,73 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring /// /// A resolver initialized for the position where the type will be inserted. /// - public TypeSystemAstBuilder(CSharpResolver resolver = null) + public TypeSystemAstBuilder(CSharpResolver resolver) { + if (resolver == null) + throw new ArgumentNullException("resolver"); this.resolver = resolver; + this.context = resolver.Context; + InitProperties(); } + public TypeSystemAstBuilder(ITypeResolveContext context) + { + if (context == null) + throw new ArgumentNullException("context"); + this.context = context; + InitProperties(); + } + + #region Properties + void InitProperties() + { + this.ShowAccessibility = true; + this.ShowModifiers = true; + this.ShowBaseTypes = true; + this.ShowTypeParameters = true; + this.ShowTypeParameterConstraints = true; + this.ShowParameterNames = true; + this.ShowConstantValues = true; + } + + /// + /// Controls the accessibility modifiers are shown. + /// + public bool ShowAccessibility { get; set; } + + /// + /// Controls the non-accessibility modifiers are shown. + /// + public bool ShowModifiers { get; set; } + + /// + /// Controls whether base type references are shown. + /// + public bool ShowBaseTypes { get; set; } + + /// + /// Controls whether type parameter declarations are shown. + /// + public bool ShowTypeParameters { get; set; } + + /// + /// Controls whether contraints on type parameter declarations are shown. + /// Has no effect if ShowTypeParameters is false. + /// + public bool ShowTypeParameterConstraints { get; set; } + + /// + /// Controls whether the names of parameters are shown. + /// + public bool ShowParameterNames { get; set; } + + /// + /// Controls whether to show default values of optional parameters, and the values of constant fields. + /// + public bool ShowConstantValues { get; set; } + #endregion + + #region Convert Type public AstType ConvertType(IType type) { if (type == null) @@ -49,7 +113,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring if (pt.Name == "Nullable" && pt.Namespace == "System" && pt.TypeParameterCount == 1) { return ConvertType(pt.TypeArguments[0]).MakeNullableType(); } - return ConvertTypeDefinition(pt.GetDefinition(), pt.TypeArguments); + return ConvertTypeHelper(pt.GetDefinition(), pt.TypeArguments); } ITypeDefinition typeDef = type as ITypeDefinition; if (typeDef != null) { @@ -59,15 +123,15 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring for (int i = 0; i < typeArguments.Length; i++) { typeArguments[i] = SharedTypes.UnboundTypeArgument; } - return ConvertTypeDefinition(typeDef, typeArguments); + return ConvertTypeHelper(typeDef, typeArguments); } else { - return ConvertTypeDefinition(typeDef, EmptyList.Instance); + return ConvertTypeHelper(typeDef, EmptyList.Instance); } } return new SimpleType(type.Name); } - AstType ConvertTypeDefinition(ITypeDefinition typeDef, IList typeArguments) + AstType ConvertTypeHelper(ITypeDefinition typeDef, IList typeArguments) { Debug.Assert(typeArguments.Count >= typeDef.TypeParameterCount); switch (ReflectionHelper.GetTypeCode(typeDef)) { @@ -144,7 +208,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring MemberType result = new MemberType(); if (typeDef.DeclaringTypeDefinition != null) { // Handle nested types - result.Target = ConvertTypeDefinition(typeDef.DeclaringTypeDefinition, typeArguments); + result.Target = ConvertTypeHelper(typeDef.DeclaringTypeDefinition, typeArguments); } else { // Handle top-level types if (string.IsNullOrEmpty(typeDef.Namespace)) { @@ -238,5 +302,388 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring NamespaceResolveResult nrr = resolver.ResolveSimpleName(firstNamespacePart, EmptyList.Instance) as NamespaceResolveResult; return nrr != null && !nrr.IsError && nrr.NamespaceName == firstNamespacePart; } + #endregion + + #region Convert Constant Value + public Expression ConvertConstantValue(IConstantValue constantValue) + { + if (constantValue == null) + throw new ArgumentNullException("constantValue"); + IType type = constantValue.GetValueType(context); + object val = constantValue.GetValue(context); + if (val == null) { + if (type.IsReferenceType(context) == true) + return new NullReferenceExpression(); + else + return new DefaultValueExpression(ConvertType(type)); + } else if (type.Kind == TypeKind.Enum) { + throw new NotImplementedException(); + } else { + return new PrimitiveExpression(val); + } + } + #endregion + + #region Convert Parameter + public ParameterDeclaration ConvertParameter(IParameter parameter) + { + if (parameter == null) + throw new ArgumentNullException("parameter"); + ParameterDeclaration decl = new ParameterDeclaration(); + if (parameter.IsRef) { + decl.ParameterModifier = ParameterModifier.Ref; + } else if (parameter.IsOut) { + decl.ParameterModifier = ParameterModifier.Out; + } else if (parameter.IsParams) { + decl.ParameterModifier = ParameterModifier.Params; + } + decl.Type = ConvertType(parameter.Type.Resolve(context)); + if (this.ShowParameterNames) { + decl.Name = parameter.Name; + } + if (parameter.IsOptional && this.ShowConstantValues) { + decl.DefaultExpression = ConvertConstantValue(parameter.DefaultValue); + } + return decl; + } + #endregion + + #region Convert Entity + public AstNode ConvertEntity(IEntity entity) + { + if (entity == null) + throw new ArgumentNullException("entity"); + switch (entity.EntityType) { + case EntityType.TypeDefinition: + return ConvertTypeDefinition((ITypeDefinition)entity); + case EntityType.Field: + return ConvertField((IField)entity); + case EntityType.Property: + return ConvertProperty((IProperty)entity); + case EntityType.Indexer: + return ConvertIndexer((IProperty)entity); + case EntityType.Event: + return ConvertEvent((IEvent)entity); + case EntityType.Method: + return ConvertMethod((IMethod)entity); + case EntityType.Operator: + return ConvertOperator((IMethod)entity); + case EntityType.Constructor: + return ConvertConstructor((IMethod)entity); + case EntityType.Destructor: + return ConvertDestructor((IMethod)entity); + default: + throw new ArgumentException("Invalid value for EntityType: " + entity.EntityType); + } + } + + AttributedNode ConvertTypeDefinition(ITypeDefinition typeDefinition) + { + Modifiers modifiers = ModifierFromAccessibility(typeDefinition.Accessibility); + if (this.ShowModifiers) { + if (typeDefinition.IsStatic) { + modifiers |= Modifiers.Static; + } else if (typeDefinition.IsAbstract) { + modifiers |= Modifiers.Abstract; + } else if (typeDefinition.IsSealed) { + modifiers |= Modifiers.Sealed; + } + if (typeDefinition.IsShadowing) { + modifiers |= Modifiers.New; + } + } + + ClassType classType; + switch (typeDefinition.Kind) { + case TypeKind.Struct: + classType = ClassType.Struct; + break; + case TypeKind.Enum: + classType = ClassType.Enum; + break; + case TypeKind.Interface: + classType = ClassType.Interface; + break; + case TypeKind.Delegate: + IMethod invoke = typeDefinition.GetDelegateInvokeMethod(); + if (invoke != null) + return ConvertDelegate(invoke, modifiers); + else + goto default; + default: + classType = ClassType.Class; + break; + } + + TypeDeclaration decl = new TypeDeclaration(); + decl.Modifiers = modifiers; + decl.ClassType = classType; + decl.Name = typeDefinition.Name; + + if (this.ShowTypeParameters) { + foreach (ITypeParameter tp in typeDefinition.TypeParameters) { + decl.TypeParameters.Add(ConvertTypeParameter(tp)); + } + } + + if (this.ShowBaseTypes) { + foreach (ITypeReference baseType in typeDefinition.BaseTypes) { + decl.BaseTypes.Add(ConvertType(baseType.Resolve(context))); + } + } + + if (this.ShowTypeParameters && this.ShowTypeParameterConstraints) { + foreach (ITypeParameter tp in typeDefinition.TypeParameters) { + var constraint = ConvertTypeParameterConstraint(tp); + if (constraint != null) + decl.Constraints.Add(constraint); + } + } + return decl; + } + + DelegateDeclaration ConvertDelegate(IMethod invokeMethod, Modifiers modifiers) + { + ITypeDefinition d = invokeMethod.DeclaringTypeDefinition; + + DelegateDeclaration decl = new DelegateDeclaration(); + decl.Modifiers = modifiers; + decl.ReturnType = ConvertType(invokeMethod.ReturnType.Resolve(context)); + decl.Name = d.Name; + + if (this.ShowTypeParameters) { + foreach (ITypeParameter tp in d.TypeParameters) { + decl.TypeParameters.Add(ConvertTypeParameter(tp)); + } + } + + foreach (IParameter p in invokeMethod.Parameters) { + decl.Parameters.Add(ConvertParameter(p)); + } + + if (this.ShowTypeParameters && this.ShowTypeParameterConstraints) { + foreach (ITypeParameter tp in d.TypeParameters) { + var constraint = ConvertTypeParameterConstraint(tp); + if (constraint != null) + decl.Constraints.Add(constraint); + } + } + return decl; + } + + AstNode ConvertField(IField field) + { + FieldDeclaration decl = new FieldDeclaration(); + Modifiers m = GetMemberModifiers(field); + if (field.IsConst) { + m &= ~Modifiers.Static; + m |= Modifiers.Const; + } else if (field.IsReadOnly) { + m |= Modifiers.Readonly; + } else if (field.IsVolatile) { + m |= Modifiers.Volatile; + } + decl.Modifiers = m; + decl.ReturnType = ConvertType(field.ReturnType.Resolve(context)); + Expression initializer = null; + if (field.IsConst && this.ShowConstantValues) + initializer = ConvertConstantValue(field.ConstantValue); + decl.Variables.Add(new VariableInitializer(field.Name, initializer)); + return decl; + } + + Accessor ConvertAccessor(IAccessor accessor) + { + if (accessor == null) + return Accessor.Null; + Accessor decl = new Accessor(); + decl.Modifiers = ModifierFromAccessibility(accessor.Accessibility); + return decl; + } + + PropertyDeclaration ConvertProperty(IProperty property) + { + PropertyDeclaration decl = new PropertyDeclaration(); + decl.Modifiers = GetMemberModifiers(property); + decl.ReturnType = ConvertType(property.ReturnType.Resolve(context)); + decl.Name = property.Name; + decl.Getter = ConvertAccessor(property.Getter); + decl.Setter = ConvertAccessor(property.Setter); + return decl; + } + + IndexerDeclaration ConvertIndexer(IProperty indexer) + { + IndexerDeclaration decl = new IndexerDeclaration(); + decl.Modifiers = GetMemberModifiers(indexer); + decl.ReturnType = ConvertType(indexer.ReturnType.Resolve(context)); + foreach (IParameter p in indexer.Parameters) { + decl.Parameters.Add(ConvertParameter(p)); + } + decl.Getter = ConvertAccessor(indexer.Getter); + decl.Setter = ConvertAccessor(indexer.Setter); + return decl; + } + + EventDeclaration ConvertEvent(IEvent ev) + { + EventDeclaration decl = new EventDeclaration(); + decl.Modifiers = GetMemberModifiers(ev); + decl.ReturnType = ConvertType(ev.ReturnType.Resolve(context)); + decl.Variables.Add(new VariableInitializer(ev.Name)); + return decl; + } + + MethodDeclaration ConvertMethod(IMethod method) + { + MethodDeclaration decl = new MethodDeclaration(); + decl.Modifiers = GetMemberModifiers(method); + decl.ReturnType = ConvertType(method.ReturnType.Resolve(context)); + decl.Name = method.Name; + + if (this.ShowTypeParameters) { + foreach (ITypeParameter tp in method.TypeParameters) { + decl.TypeParameters.Add(ConvertTypeParameter(tp)); + } + } + + foreach (IParameter p in method.Parameters) { + decl.Parameters.Add(ConvertParameter(p)); + } + + if (this.ShowTypeParameters && this.ShowTypeParameterConstraints) { + foreach (ITypeParameter tp in method.TypeParameters) { + var constraint = ConvertTypeParameterConstraint(tp); + if (constraint != null) + decl.Constraints.Add(constraint); + } + } + return decl; + } + + AstNode ConvertOperator(IMethod op) + { + OperatorType? opType = OperatorDeclaration.GetOperatorType(op.Name); + if (opType == null) + return ConvertMethod(op); + + OperatorDeclaration decl = new OperatorDeclaration(); + decl.Modifiers = GetMemberModifiers(op); + decl.OperatorType = opType.Value; + decl.ReturnType = ConvertType(op.ReturnType.Resolve(context)); + foreach (IParameter p in op.Parameters) { + decl.Parameters.Add(ConvertParameter(p)); + } + return decl; + } + + ConstructorDeclaration ConvertConstructor(IMethod ctor) + { + ConstructorDeclaration decl = new ConstructorDeclaration(); + decl.Modifiers = GetMemberModifiers(ctor); + decl.Name = ctor.DeclaringTypeDefinition.Name; + foreach (IParameter p in ctor.Parameters) { + decl.Parameters.Add(ConvertParameter(p)); + } + return decl; + } + + DestructorDeclaration ConvertDestructor(IMethod dtor) + { + DestructorDeclaration decl = new DestructorDeclaration(); + decl.Name = dtor.DeclaringTypeDefinition.Name; + return decl; + } + #endregion + + #region Convert Modifiers + Modifiers ModifierFromAccessibility(Accessibility accessibility) + { + if (!this.ShowAccessibility) + return Modifiers.None; + switch (accessibility) { + case Accessibility.Private: + return Modifiers.Private; + case Accessibility.Public: + return Modifiers.Public; + case Accessibility.Protected: + return Modifiers.Protected; + case Accessibility.Internal: + return Modifiers.Internal; + case Accessibility.ProtectedOrInternal: + case Accessibility.ProtectedAndInternal: + return Modifiers.Protected | Modifiers.Internal; + default: + return Modifiers.None; + } + } + + Modifiers GetMemberModifiers(IMember member) + { + Modifiers m = ModifierFromAccessibility(member.Accessibility); + if (this.ShowModifiers) { + if (member.IsStatic) { + m |= Modifiers.Static; + } else { + if (member.IsAbstract) + m |= Modifiers.Abstract; + if (member.IsOverride) + m |= Modifiers.Override; + if (member.IsVirtual && !member.IsAbstract && !member.IsOverride) + m |= Modifiers.Virtual; + if (member.IsSealed) + m |= Modifiers.Sealed; + } + if (member.IsShadowing) + m |= Modifiers.New; + } + return m; + } + #endregion + + #region Convert Type Parameter + TypeParameterDeclaration ConvertTypeParameter(ITypeParameter tp) + { + TypeParameterDeclaration decl = new TypeParameterDeclaration(); + decl.Variance = tp.Variance; + decl.Name = tp.Name; + return decl; + } + + Constraint ConvertTypeParameterConstraint(ITypeParameter tp) + { + if (tp.Constraints.Count == 0 && !tp.HasDefaultConstructorConstraint && !tp.HasReferenceTypeConstraint && !tp.HasValueTypeConstraint) { + return null; + } + Constraint c = new Constraint(); + c.TypeParameter = tp.Name; + if (tp.HasReferenceTypeConstraint) { + c.BaseTypes.Add(new PrimitiveType("class")); + } else if (tp.HasValueTypeConstraint) { + c.BaseTypes.Add(new PrimitiveType("struct")); + } + foreach (ITypeReference tr in tp.Constraints) { + c.BaseTypes.Add(ConvertType(tr.Resolve(context))); + } + if (tp.HasDefaultConstructorConstraint) { + c.BaseTypes.Add(new PrimitiveType("new")); + } + return c; + } + #endregion + + #region Convert Variable + public VariableDeclarationStatement ConvertVariable(IVariable v) + { + VariableDeclarationStatement decl = new VariableDeclarationStatement(); + decl.Modifiers = v.IsConst ? Modifiers.Const : Modifiers.None; + decl.Type = ConvertType(v.Type.Resolve(context)); + Expression initializer = null; + if (v.IsConst) + initializer = ConvertConstantValue(v.ConstantValue); + decl.Variables.Add(new VariableInitializer(v.Name, initializer)); + return decl; + } + #endregion } } diff --git a/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj b/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj index 0e63ab8ae5..5e1b57a98d 100644 --- a/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj +++ b/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj @@ -60,7 +60,6 @@ - @@ -252,6 +251,7 @@ + @@ -427,6 +427,10 @@ {D68133BD-1E63-496E-9EDE-4FBDBF77B486} Mono.Cecil + + {F054A788-B591-4561-A8BA-AE745BBEB817} + ICSharpCode.Editor + \ No newline at end of file diff --git a/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs b/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs index bee93e7689..ab3ae6ca3b 100644 --- a/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs +++ b/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs @@ -196,6 +196,10 @@ namespace ICSharpCode.NRefactory.TypeSystem get { return moduleAttributes; } } + public string AssemblyName { + get { return assemblyName; } + } + public override string ToString() { return "[CecilProjectContent " + assemblyName + "]"; diff --git a/ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs b/ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs index 1e43b982b9..262338b66c 100644 --- a/ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs +++ b/ICSharpCode.NRefactory/TypeSystem/ExtensionMethods.cs @@ -255,7 +255,7 @@ namespace ICSharpCode.NRefactory.TypeSystem /// public static ITypeDefinition GetTypeDefinition (this IParsedFile file, int line, int column) { - return file.GetTypeDefinition (new AstLocation (line, column)); + return file.GetInnerMostTypeDefinition (new AstLocation (line, column)); } /// diff --git a/ICSharpCode.NRefactory/TypeSystem/IParsedFile.cs b/ICSharpCode.NRefactory/TypeSystem/IParsedFile.cs index 86e6586e39..e988489496 100644 --- a/ICSharpCode.NRefactory/TypeSystem/IParsedFile.cs +++ b/ICSharpCode.NRefactory/TypeSystem/IParsedFile.cs @@ -67,7 +67,7 @@ namespace ICSharpCode.NRefactory.TypeSystem /// Gets the type (potentially a nested type) defined at the specified location. /// Returns null if no type is defined at that location. /// - ITypeDefinition GetTypeDefinition(AstLocation location); + ITypeDefinition GetInnerMostTypeDefinition(AstLocation location); /// /// Gets the member defined at the specified location. diff --git a/ICSharpCode.NRefactory/TypeSystem/IProjectContent.cs b/ICSharpCode.NRefactory/TypeSystem/IProjectContent.cs index 515d85876f..e2d6ea5a56 100644 --- a/ICSharpCode.NRefactory/TypeSystem/IProjectContent.cs +++ b/ICSharpCode.NRefactory/TypeSystem/IProjectContent.cs @@ -30,6 +30,11 @@ namespace ICSharpCode.NRefactory.TypeSystem #endif public interface IProjectContent : ITypeResolveContext, IAnnotatable { + /// + /// Gets the assembly name (short name). + /// + string AssemblyName { get; } + /// /// Gets the list of all assembly attributes in the project. /// diff --git a/ICSharpCode.NRefactory/CSharp/Analysis/MinimalResolveContext.cs b/ICSharpCode.NRefactory/TypeSystem/Implementation/MinimalResolveContext.cs similarity index 95% rename from ICSharpCode.NRefactory/CSharp/Analysis/MinimalResolveContext.cs rename to ICSharpCode.NRefactory/TypeSystem/Implementation/MinimalResolveContext.cs index e2a395d226..e87fcf87e5 100644 --- a/ICSharpCode.NRefactory/CSharp/Analysis/MinimalResolveContext.cs +++ b/ICSharpCode.NRefactory/TypeSystem/Implementation/MinimalResolveContext.cs @@ -21,15 +21,12 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using ICSharpCode.NRefactory.TypeSystem; -using ICSharpCode.NRefactory.TypeSystem.Implementation; - -namespace ICSharpCode.NRefactory.CSharp.Analysis +namespace ICSharpCode.NRefactory.TypeSystem.Implementation { /// /// Resolve context represents the minimal mscorlib required for evaluating constants. /// - sealed class MinimalResolveContext : AbstractAnnotatable, IProjectContent, ISynchronizedTypeResolveContext + public sealed class MinimalResolveContext : AbstractAnnotatable, IProjectContent, ISynchronizedTypeResolveContext { static readonly Lazy instance = new Lazy(() => new MinimalResolveContext()); @@ -175,5 +172,9 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis { throw new NotSupportedException(); } + + public string AssemblyName { + get { return "MinimalResolveContext"; } + } } } diff --git a/ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleProjectContent.cs b/ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleProjectContent.cs index 30db64757e..5083e1e952 100644 --- a/ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleProjectContent.cs +++ b/ICSharpCode.NRefactory/TypeSystem/Implementation/SimpleProjectContent.cs @@ -50,6 +50,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation } #endregion + public virtual string AssemblyName { + get { return string.Empty; } + } + #region AssemblyAttributes readonly List assemblyAttributes = new List(); // mutable assembly attribute storage readonly List moduleAttributes = new List();