Skip to content

Commit

Permalink
fix name clash tests
Browse files Browse the repository at this point in the history
  • Loading branch information
georghinkel committed Oct 22, 2024
1 parent 0e73179 commit e483e8d
Show file tree
Hide file tree
Showing 15 changed files with 28,936 additions and 28,908 deletions.
21 changes: 11 additions & 10 deletions Transformations/CodeGen/NamespaceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private void FillNameConflictsWithDefaultAssemblies(Dictionary<string, string> n
{
if (DefaultImports.Contains(type.Namespace))
{
RegisterConflict(type.Name, nameDict, type.Namespace);
RegisterConflict(type.Name, nameDict, type.Namespace, false);
}
}
}
Expand All @@ -222,7 +222,7 @@ private void CalculateConflictsInRule(ITransformationContext context, Dictionary
});
foreach (CodeTypeDeclaration codeType in codeNs.Types)
{
RegisterConflict(codeType.Name, nameDict, codeNs.Name);
RegisterConflict(codeType.Name, nameDict, codeNs.Name, true);
}
}
}
Expand Down Expand Up @@ -250,11 +250,11 @@ private void RegisterConflicts(CodeTypeReference reference, Dictionary<string, s
var refNs = reference.Namespace();
if (refNs != null)
{
RegisterConflict(reference.BaseType, nameDict, refNs);
RegisterConflict(reference.BaseType, nameDict, refNs, true);
}
}

private void RegisterConflict(string typeName, Dictionary<string, string> nameDict, string refNs)
private void RegisterConflict(string typeName, Dictionary<string, string> nameDict, string refNs, bool checkSystemConflict)
{
string chosenClass;
if (nameDict.TryGetValue(typeName, out chosenClass))
Expand All @@ -266,26 +266,27 @@ private void RegisterConflict(string typeName, Dictionary<string, string> nameDi
}
else
{
nameDict.Add(typeName, IsSystemNameConflict(typeName) ? null : refNs);
nameDict.Add(typeName, checkSystemConflict && IsSystemNameConflict(typeName, refNs) ? null : refNs);
}
}

/// <summary>
/// Determines whether the given type name is a conflict with a system type
/// </summary>
/// <param name="typeName"></param>
/// <param name="refNs">the suggested namespace</param>
/// <returns></returns>
protected virtual bool IsSystemNameConflict(string typeName)
protected virtual bool IsSystemNameConflict(string typeName, string refNs)
{
var hits = 0;
foreach (var defaultNamespace in DefaultImports)
{
if (Type.GetType(defaultNamespace + "." + typeName, false) != null)
var type = Type.GetType(defaultNamespace + "." + typeName, false);
if (type != null && type.Namespace != refNs)
{
hits++;
return true;
}
}
return hits < 2;
return false;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static CodeMemberMethod GenerateConvertTo(CodeTypeDeclaration generatedT
convertTo.Parameters.Add(new CodeParameterDeclarationExpression(typeof(ITypeDescriptorContext).ToTypeReference(), "context"));
convertTo.Parameters.Add(new CodeParameterDeclarationExpression(typeof(CultureInfo).ToTypeReference(), "culture"));
convertTo.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "value"));
convertTo.Parameters.Add(new CodeParameterDeclarationExpression(typeof(System.Type).ToTypeReference(), "destinationType"));
convertTo.Parameters.Add(new CodeParameterDeclarationExpression(typeof(System.Type), "destinationType"));
convertTo.WriteDocumentation("Convert the provided value into a " + generatedType.Name,
"the converted value",
new Dictionary<string, string>
Expand Down Expand Up @@ -184,7 +184,7 @@ private static CodeMemberMethod GenerateCanConvertFrom(CodeTypeDeclaration gener
ReturnType = new CodeTypeReference(typeof(bool))
};
canConvertFromMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(ITypeDescriptorContext).ToTypeReference(), "context"));
canConvertFromMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(System.Type).ToTypeReference(), "sourceType"));
canConvertFromMethod.Parameters.Add(new CodeParameterDeclarationExpression(typeof(System.Type), "sourceType"));
canConvertFromMethod.WriteDocumentation("Determines whether the converter can convert from the provided source type into " + generatedType.Name,
"true, if the converter can convert from the source type, otherwise false",
new Dictionary<string, string>
Expand Down
Loading

0 comments on commit e483e8d

Please sign in to comment.