Skip to content

Commit

Permalink
fix: Mixing Assembly Versions
Browse files Browse the repository at this point in the history
  • Loading branch information
workgroupengineering committed Jun 13, 2024
1 parent 5d043a5 commit 80472a7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private TypeWrapper(TypeDef type, DnlibMetadataProviderSession session)
throw new ArgumentNullException();
_type = type;
_session = session;
AssemblyQualifiedName = _type.AssemblyQualifiedName;
AssemblyQualifiedName = $"{type.FullName}, {type.DefinitionAssembly.Name}";
}

public string FullName => _type.FullName;
Expand Down Expand Up @@ -204,7 +204,9 @@ public PropertyWrapper(PropertyDef prop)
}

TypeFullName = type.FullName;
QualifiedTypeFullName = type.AssemblyQualifiedName;
QualifiedTypeFullName = type.IsGenericParameter
? type.FullName
: $"{type.FullName}, {type.DefinitionAssembly.Name}";

_prop = prop;
if (HasPublicGetter || HasPublicSetter)
Expand Down Expand Up @@ -290,7 +292,9 @@ public FieldWrapper(FieldDef f, DnlibMetadataProviderSession session)
IsPublic = f.IsPublic || f.IsAssembly;
Name = f.Name;
ReturnTypeFullName = f.FieldType.FullName;
QualifiedTypeFullName = f.FieldType.AssemblyQualifiedName;
QualifiedTypeFullName = f.FieldType.DefinitionAssembly is null
? f.FieldType.FullName
: $"{f.FieldType.FullName}, {f.FieldType.DefinitionAssembly.Name}";
bool isRoutedEvent = false;
ITypeDefOrRef t = f.FieldType.ToTypeDefOrRef();
while (t != null)
Expand Down Expand Up @@ -324,7 +328,9 @@ public EventWrapper(EventDef @event)
{
Name = @event.Name;
TypeFullName = @event.EventType.FullName;
QualifiedTypeFullName = @event.EventType.AssemblyQualifiedName;
QualifiedTypeFullName = @event.EventType.DefinitionAssembly is null
? @event.EventType.FullName
: $"{@event.EventType.FullName}, {@event.EventType.DefinitionAssembly.Name}";
IsPublic = @event.IsPublic();
IsInternal = @event.IsInternal();
}
Expand All @@ -350,12 +356,14 @@ public MethodWrapper(MethodDef method)
IList<IParameterInformation>);
if (_method.ReturnType is not null)
{
QualifiedReturnTypeFullName = _method.ReturnType.AssemblyQualifiedName;
QualifiedReturnTypeFullName = _method.ReturnType.DefinitionAssembly is null
? _method.ReturnType.FullName
: $"{_method.ReturnType.FullName}, {_method.ReturnType.DefinitionAssembly.Name}";
ReturnTypeFullName = _method.ReturnType.FullName;
}
else
{
QualifiedReturnTypeFullName = typeof(void).AssemblyQualifiedName!;
QualifiedReturnTypeFullName = $"{typeof(void).FullName}, {typeof(void).Assembly.FullName}";
ReturnTypeFullName = typeof(void).FullName!;
}
}
Expand All @@ -377,7 +385,9 @@ internal class ParameterWrapper : IParameterInformation
public ParameterWrapper(Parameter param)
{
_param = param;
QualifiedTypeFullName = _param.Type.AssemblyQualifiedName;
QualifiedTypeFullName = _param.Type.DefinitionAssembly is null
? _param.Type.FullName
: $"{_param.Type.FullName}, {_param.Type.DefinitionAssembly.Name}";
}
public string TypeFullName => _param.Type.FullName;
public string QualifiedTypeFullName { get; }
Expand Down
33 changes: 17 additions & 16 deletions tests/CompletionEngineTests/Metadata/MetadataConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public void Discover_Do_Not_Overlapped()
Assert.NotNull(ns);
MetadataType type = ns[clrType.Name];
Assert.NotNull(type);
Assert.Equal(clrType.AssemblyQualifiedName, type.AssemblyQualifiedName);


Assert.Equal(GetName(clrType), type.AssemblyQualifiedName);

Type clrTypeA1 = typeof(A1::CompletionEngineTests.Models.AttachedBehavior);
nsName = "clr-namespace:" + clrTypeA1.Namespace + ";assembly=" + clrTypeA1.Assembly.GetName().Name;
Expand All @@ -64,7 +62,7 @@ public void Discover_Do_Not_Overlapped()

Assert.NotNull(typeA1);

Assert.Equal(clrTypeA1.AssemblyQualifiedName, typeA1.AssemblyQualifiedName);
Assert.Equal(GetName(clrTypeA1), typeA1.AssemblyQualifiedName);


Type clrTypeA2 = typeof(A2::CompletionEngineTests.Models.AttachedBehavior);
Expand All @@ -78,7 +76,7 @@ public void Discover_Do_Not_Overlapped()

Assert.NotNull(typeA2);

Assert.Equal(clrTypeA2.AssemblyQualifiedName, typeA2.AssemblyQualifiedName);
Assert.Equal(GetName(clrTypeA2), typeA2.AssemblyQualifiedName);
}

[Theory]
Expand All @@ -104,7 +102,7 @@ public void AttachedPropertySetterAndGetterMixmatch()
ns.TryGetValue(clrType.Name, out var type);
Assert.NotNull(type);

var property = type.Properties.SingleOrDefault(p=> p.Name == "Column");
var property = type.Properties.SingleOrDefault(p => p.Name == "Column");
Assert.NotNull(property);
Assert.True(property.IsAttached);
Assert.Equal("System.Int32", property.Type?.Name);
Expand All @@ -119,7 +117,7 @@ public static IEnumerable<object[]> GetCasese()
typeof(Models.InternalAttachedBehavior),
new Action<Type,MetadataType>(static (clrType,mdType) =>
{
Assert.Equal(clrType.AssemblyQualifiedName, mdType.AssemblyQualifiedName);
Assert.Equal(GetName(clrType) , mdType.AssemblyQualifiedName);
})),
};
yield return new object[]
Expand All @@ -128,7 +126,7 @@ public static IEnumerable<object[]> GetCasese()
typeof(Models.InternalClass),
new Action<Type,MetadataType>(static (clrType,mdType) =>
{
Assert.Equal(clrType.AssemblyQualifiedName, mdType.AssemblyQualifiedName);
Assert.Equal(GetName(clrType), mdType.AssemblyQualifiedName);
Assert.Equal(ExpectedPublicOrInternalProperties,mdType.Properties.Select(p=>p.Name));
})),
};
Expand All @@ -138,7 +136,7 @@ public static IEnumerable<object[]> GetCasese()
typeof(Models.PublicWithInternalPropertiesClass),
new Action<Type,MetadataType>(static (clrType,mdType) =>
{
Assert.Equal(clrType.AssemblyQualifiedName, mdType.AssemblyQualifiedName);
Assert.Equal(GetName(clrType), mdType.AssemblyQualifiedName);
Assert.Equal(ExpectedPublicOrInternalProperties,mdType.Properties.Select(p=>p.Name));
})),
};
Expand All @@ -149,7 +147,7 @@ public static IEnumerable<object[]> GetCasese()
typeof(A1::CompletionEngineTests.Models.InternalAttachedBehavior),
new Action<Type,MetadataType>(static (clrType,mdType) =>
{
Assert.Equal(clrType.AssemblyQualifiedName, mdType?.AssemblyQualifiedName);
Assert.Equal(GetName(clrType), mdType?.AssemblyQualifiedName);
})),
};
yield return new object[]
Expand All @@ -158,7 +156,7 @@ public static IEnumerable<object[]> GetCasese()
typeof(A1::CompletionEngineTests.Models.InternalClass),
new Action<Type,MetadataType>(static (clrType,mdType) =>
{
Assert.Equal(clrType.AssemblyQualifiedName, mdType.AssemblyQualifiedName);
Assert.Equal(GetName(clrType), mdType.AssemblyQualifiedName);
Assert.Equal(ExpectedPublicOrInternalProperties,mdType.Properties.Select(p=>p.Name));
})),
};
Expand All @@ -168,15 +166,15 @@ public static IEnumerable<object[]> GetCasese()
typeof(A1::CompletionEngineTests.Models.PublicWithInternalPropertiesClass),
new Action<Type,MetadataType>(static (clrType,mdType) =>
{
Assert.Equal(clrType.AssemblyQualifiedName, mdType.AssemblyQualifiedName);
Assert.Equal(GetName(clrType), mdType.AssemblyQualifiedName);
Assert.Equal(ExpectedPublicOrInternalProperties,mdType.Properties.Select(p=>p.Name));
})),
};
// TestAssembly2 without InternalsVisibleTo
yield return new object[]
{
new TestScenario("Not InternalsVisibleTo Internal Attached Behavior",
Type.GetType("CompletionEngineTests.Models.InternalAttachedBehavior, TestAssembly2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"),
Type.GetType("CompletionEngineTests.Models.InternalAttachedBehavior, TestAssembly2"),
new Action<Type,MetadataType>(static (clrType,mdType) =>
{
Assert.Null(mdType);
Expand All @@ -185,7 +183,7 @@ public static IEnumerable<object[]> GetCasese()
yield return new object[]
{
new TestScenario("Not InternalsVisibleTo Internal Class",
Type.GetType("CompletionEngineTests.Models.InternalAttachedBehavior, TestAssembly2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"),
Type.GetType("CompletionEngineTests.Models.InternalAttachedBehavior, TestAssembly2"),
new Action<Type,MetadataType>(static (clrType,mdType) =>
{
Assert.Null(mdType);
Expand All @@ -194,10 +192,10 @@ public static IEnumerable<object[]> GetCasese()
yield return new object[]
{
new TestScenario("InternalsVisibleTo Public Class with internal properties",
Type.GetType("CompletionEngineTests.Models.PublicWithInternalPropertiesClass, TestAssembly2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"),
Type.GetType("CompletionEngineTests.Models.PublicWithInternalPropertiesClass, TestAssembly2"),
new Action<Type,MetadataType>(static (clrType,mdType) =>
{
Assert.Equal(clrType.AssemblyQualifiedName, mdType.AssemblyQualifiedName);
Assert.Equal(GetName(clrType), mdType.AssemblyQualifiedName);
Assert.Equal(ExpectedPublicProperties,mdType.Properties.Select(p=>p.Name));
})),
};
Expand Down Expand Up @@ -225,5 +223,8 @@ public override string ToString()

private static Metadata Metadata = new MetadataReader(new DnlibMetadataProvider())
.GetForTargetAssembly(new FolderAssemblyProvider(typeof(XamlCompletionTestBase).Assembly.GetModules()[0].FullyQualifiedName));

private static string GetName(Type clrType) =>
$"{clrType.FullName}, {clrType.Assembly.GetName().Name}";
}
}

0 comments on commit 80472a7

Please sign in to comment.