Browse Source

Implemented CecilLoader.ReadField

newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
7ff4e5a778
  1. 1
      ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj
  2. 46
      ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  3. 9
      ICSharpCode.NRefactory/TypeSystem/IField.cs
  4. 4
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultEvent.cs
  5. 62
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultField.cs
  6. 4
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultProperty.cs

1
ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj

@ -166,6 +166,7 @@ @@ -166,6 +166,7 @@
<Compile Include="TypeSystem\Implementation\DefaultAttribute.cs" />
<Compile Include="TypeSystem\Implementation\DefaultEvent.cs" />
<Compile Include="TypeSystem\Implementation\DefaultExplicitInterfaceImplementation.cs" />
<Compile Include="TypeSystem\Implementation\DefaultField.cs" />
<Compile Include="TypeSystem\Implementation\DefaultMethod.cs" />
<Compile Include="TypeSystem\Implementation\DefaultParameter.cs" />
<Compile Include="TypeSystem\Implementation\DefaultProperty.cs" />

46
ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -522,7 +522,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -522,7 +522,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
if (typeDefinition.HasFields) {
foreach (FieldDefinition field in typeDefinition.Fields) {
if (loader.IsVisible(field.Attributes)) {
if (loader.IsVisible(field.Attributes) && !field.IsSpecialName) {
this.Fields.Add(loader.ReadField(field, this));
}
}
@ -580,8 +580,6 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -580,8 +580,6 @@ namespace ICSharpCode.NRefactory.TypeSystem
}
}
AddExplicitInterfaceImplementations(method, m);
// mark as extension method is the attribute is set
if (method.IsStatic && method.HasCustomAttributes) {
foreach (var attr in method.CustomAttributes) {
@ -634,6 +632,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -634,6 +632,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
m.IsSealed = true;
else if (method.IsVirtual)
m.IsVirtual = true;
m.IsStatic = method.IsStatic;
}
}
#endregion
@ -686,16 +685,47 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -686,16 +685,47 @@ namespace ICSharpCode.NRefactory.TypeSystem
public IField ReadField(FieldDefinition field, ITypeDefinition parentType)
{
throw new NotImplementedException();
if (field == null)
throw new ArgumentNullException("field");
if (parentType == null)
throw new ArgumentNullException("parentType");
DefaultField f = new DefaultField(parentType, field.Name);
f.Accessibility = GetAccessibility(field.Attributes);
f.IsReadOnly = field.IsInitOnly;
f.IsStatic = field.IsStatic;
if (field.HasConstant) {
f.ConstantValue = ReadConstantValue(new CustomAttributeArgument(field.FieldType, field.Constant));
}
if (field.HasCustomAttributes) {
AddAttributes(field, f.Attributes);
}
RequiredModifierType modreq = field.FieldType as RequiredModifierType;
if (modreq != null && modreq.ModifierType.FullName == typeof(IsVolatile).FullName) {
f.IsVolatile = true;
}
return f;
}
#endregion
void AddExplicitInterfaceImplementations(MethodDefinition method, AbstractMember targetMember)
static Accessibility GetAccessibility(FieldAttributes attr)
{
if (method.HasOverrides) {
throw new NotImplementedException();
switch (attr & FieldAttributes.FieldAccessMask) {
case FieldAttributes.Public:
return Accessibility.Public;
case FieldAttributes.FamANDAssem:
return Accessibility.ProtectedAndInternal;
case FieldAttributes.Assembly:
return Accessibility.Internal;
case FieldAttributes.Family:
return Accessibility.Protected;
case FieldAttributes.FamORAssem:
return Accessibility.ProtectedOrInternal;
default:
return Accessibility.Private;
}
}
#endregion
#region Type Parameter Constraints
void AddConstraints(DefaultTypeParameter tp, GenericParameter g)

9
ICSharpCode.NRefactory/TypeSystem/IField.cs

@ -27,6 +27,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -27,6 +27,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </summary>
bool IsReadOnly { get; }
/// <summary>
/// Gets whether this field is volatile.
/// </summary>
bool IsVolatile { get; }
/// <summary>
/// If this field is a constant, retrieves the value.
/// </summary>
@ -55,6 +60,10 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -55,6 +60,10 @@ namespace ICSharpCode.NRefactory.TypeSystem
get { return false; }
}
bool IField.IsVolatile {
get { return false; }
}
IConstantValue IField.ConstantValue {
get { return null; }
}

4
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultEvent.cs

@ -1,4 +1,6 @@ @@ -1,4 +1,6 @@

// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation

62
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultField.cs

@ -0,0 +1,62 @@ @@ -0,0 +1,62 @@
// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
{
/// <summary>
/// Default implementation of <see cref="IField"/>.
/// </summary>
public class DefaultField : AbstractMember, IField
{
IConstantValue constantValue;
const ushort FlagIsReadOnly = 0x1000;
const ushort FlagIsVolatile = 0x2000;
protected override void FreezeInternal()
{
if (constantValue != null)
constantValue.Freeze();
base.FreezeInternal();
}
public DefaultField(ITypeDefinition declaringTypeDefinition, string name)
: base(declaringTypeDefinition, name, EntityType.Field)
{
}
public bool IsConst {
get { return constantValue != null; }
}
public bool IsReadOnly {
get { return flags[FlagIsReadOnly]; }
set {
CheckBeforeMutation();
flags[FlagIsReadOnly] = value;
}
}
public bool IsVolatile {
get { return flags[FlagIsVolatile]; }
set {
CheckBeforeMutation();
flags[FlagIsVolatile] = value;
}
}
public IConstantValue ConstantValue {
get { return constantValue; }
set {
CheckBeforeMutation();
constantValue = value;
}
}
ITypeReference IVariable.Type {
get { return this.ReturnType; }
}
}
}

4
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultProperty.cs

@ -1,4 +1,6 @@ @@ -1,4 +1,6 @@

// Copyright (c) 2010 AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;

Loading…
Cancel
Save