Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes an issue where complex generics where treated as OnlinerBase type in rcc #178

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected override void OnParametersSet()
/// <param name="presentationType">Type of presentation.</param>
/// </summary>

internal IRenderableComponent ViewLocatorBuilder(Type twinType, string presentationType)
internal IRenderableComponent ViewLocatorBuilder(Type twinType, ITwinElement twin, string presentationType)
{
var namespc = twinType.Namespace;
//set default namespace if is namespace of primitive types or empty
Expand All @@ -140,11 +140,11 @@ internal IRenderableComponent ViewLocatorBuilder(Type twinType, string presentat
var presentationName = item;
if (presentationName.ToLower() == "base") presentationName = "";
// try to find component view
var component = GetComponent(twinType, presentationName, namespc);
var component = GetComponent(twinType, twin, presentationName, namespc);
if (component == null)
{
//if not found, look at predecessor
component = ViewLocatorBuilder(twinType.BaseType, presentationName);
component = ViewLocatorBuilder(twinType.BaseType, twin, presentationName);
}
if (component != null) return component;
}
Expand Down Expand Up @@ -320,7 +320,9 @@ private bool IsEnumerator(ITwinElement obj)

private (string, Type) GetGenericInfo(Type primitiveKidType)
{
var baseName = primitiveKidType?.BaseType.Name;
if (primitiveKidType == null) return (null, null);

var baseName = primitiveKidType?.BaseType?.Name;

if (baseName == "OnlinerBase")
{
Expand All @@ -329,26 +331,32 @@ private bool IsEnumerator(ITwinElement obj)
}
else
{
return GetGenericInfo(primitiveKidType.BaseType);
return GetGenericInfo(primitiveKidType?.BaseType);
}
}
private IRenderableComponent GetComponent(Type twinType, string presentationName, string namespc)
private IRenderableComponent GetComponent(Type twinType, ITwinElement twin, string presentationName, string namespc)
{
// if is generic type, render generic component
if (twinType.IsGenericType)
switch (twin)
{
var (baseName, genericTypeArg) = GetGenericInfo(twinType);
var name = $"{namespc}.{baseName}";
var buildedComponentName = $"{name}{presentationName}View`1";
return ComponentService.GetGenericComponent(buildedComponentName, genericTypeArg);
case OnlinerBase onliner:
if (twinType.IsGenericType)
{
var (baseName, genericTypeArg) = GetGenericInfo(twinType);
var onlinerName = $"{namespc}.{baseName}";
var onlinerBuildedComponentName = $"{onlinerName}{presentationName}View`1";
return ComponentService.GetGenericComponent(onlinerBuildedComponentName, genericTypeArg);
}
else
{
var onlinerName = $"{namespc}.{twinType.Name}";
var onlinerBuildedComponentName = $"{onlinerName}{presentationName}View";
return ComponentService.GetComponent(onlinerBuildedComponentName);
}
default:
var name = $"{namespc}.{twinType.Name}";
var buildedComponentName = $"{name}{presentationName}View";
return ComponentService.GetComponent(buildedComponentName);
}
else
{
var name = $"{namespc}.{twinType.Name}";
var buildedComponentName = $"{name}{presentationName}View";
return ComponentService.GetComponent(buildedComponentName);
}

}
private bool HasReadAccess(ITwinPrimitive kid) => kid.ReadWriteAccess == ReadWriteAccess.Read;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//try to find complex component (also try predecessors) and generate it
var twin = (ITwinObject)element;
var twinType = twin.GetType();
var component = ViewLocatorBuilder(twinType, Presentation);
var component = ViewLocatorBuilder(twinType, twin, Presentation);
if (component != null)
{
@CreateComplexComponent(twin, component);
Expand Down Expand Up @@ -139,7 +139,7 @@
{
Type mainLayout = null;

var component = ViewLocatorBuilder(twin.GetType(), Presentation);
var component = ViewLocatorBuilder(twin.GetType(), twin, Presentation);
if (component != null)
{
var name = String.IsNullOrEmpty(twin.AttributeName) ? twin.GetSymbolTail() : twin.AttributeName;
Expand Down Expand Up @@ -180,7 +180,7 @@
{
string presentationType = GetDisplayPresentationIfEmpty();
var primitiveKidType = primitiveKid.GetType();
var primitiveComponent = ViewLocatorBuilder(primitiveKidType, presentationType);
var primitiveComponent = ViewLocatorBuilder(primitiveKidType, primitiveKid, presentationType);
@CreatePrimitiveComponent(primitiveKid, primitiveComponent)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void Get_BoolControlComponentWithBuilder_NotNullAreEqual()
var testedObjType = _fixture.Connector.testingProgram.testPrimitive.testBool.GetType();

//Act
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _control);
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _fixture.Connector.testingProgram.testPrimitive.testBool, _control);

//Assert
Assert.NotNull(component);
Expand All @@ -318,7 +318,7 @@ public void Get_BoolDisplayComponentWithBuilder_NotNullAreEqual()


//Act
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _display);
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _fixture.Connector.testingProgram.testPrimitive.testBool, _display);

//Assert
Assert.NotNull(component);
Expand All @@ -333,7 +333,7 @@ public void Get_DateTimeDisplayComponentWithBuilder_NotNullAreEqual()


//Act
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _display);
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _fixture.Connector.testingProgram.testPrimitive.TestDateTime, _display);

//Assert
Assert.NotNull(component);
Expand All @@ -347,7 +347,7 @@ public void Get_ComponentWithinPipeline_NotNullAreEqual()
var testedObjType = _fixture.Connector.testingProgram.testPrimitive.TestDateTime.GetType();

//Act
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, "Base-Display");
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _fixture.Connector.testingProgram.testPrimitive.TestDateTime,"Base-Display");

//Assert
Assert.NotNull(component);
Expand All @@ -362,7 +362,7 @@ public void Get_ComponentWithinPipelineRandomString_Unsuccessfull()
//Arrange
var testedObjType = _fixture.Connector.testingProgram.testPrimitive.TestDateTime.GetType();
//Act
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, "Bases-Displays");
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _fixture.Connector.testingProgram.testPrimitive.TestDateTime, "Bases-Displays");
//Assert
Assert.Null(component);

Expand All @@ -374,7 +374,7 @@ public void Get_ComponentWithinPipelineEmptyString_Unsuccessfull()
//Arrange
var testedObjType = _fixture.Connector.testingProgram.testPrimitive.TestDateTime.GetType();
//Act
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, "");
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _fixture.Connector.testingProgram.testPrimitive.TestDateTime, "");
//Assert
Assert.Null(component);

Expand All @@ -389,7 +389,7 @@ public void Get_GenericBaseControlComponentWithBuilder_NotNullAreEqual()
var testedObjType = _fixture.Connector.testingProgram.testPrimitive.testInteger.GetType();

//Act
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _control);
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _fixture.Connector.testingProgram.testPrimitive.testInteger, _control);

//Assert
Assert.NotNull(component);
Expand All @@ -403,7 +403,7 @@ public void Get_GenericBaseDisplayComponentWithBuilder_NotNullAreEqual()
var testedObjType = _fixture.Connector.testingProgram.testPrimitive.testInteger.GetType();

//Act
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _display);
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _fixture.Connector.testingProgram.testPrimitive.testInteger, _display);

//Assert
Assert.NotNull(component);
Expand All @@ -417,7 +417,7 @@ public void Get_GenericBaseControlWithinPipeline_NotNullAreEqual()
var testedObjType = _fixture.Connector.testingProgram.testPrimitive.testInteger.GetType();

//Act
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, "Base-Manual-Service-Control");
var component = _fixture.RenderableContent.ViewLocatorBuilder(testedObjType, _fixture.Connector.testingProgram.testPrimitive.testInteger, "Base-Manual-Service-Control");

//Assert
Assert.NotNull(component);
Expand Down