C
C#15mo ago
N0mlss

✅ Cant access base parameter in children partial class

I have a partial class that herits from a parent class. In the children class, i cant access any of the parent properties, but it works if the class is not partial. Is it normal or is it a bug? Pictures in comments
No description
64 Replies
N0mlss
N0mlssOP15mo ago
No description
SinFluxx
SinFluxx15mo ago
What's the actual error?
N0mlss
N0mlssOP15mo ago
There is just nothing after base. Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Angius
Angius15mo ago
Well that would be the error, then thing.Property; just does... nothing
TheRanger
TheRanger15mo ago
its like ur putting 1;
{
1;
}
{
1;
}
N0mlss
N0mlssOP15mo ago
I mean i can write the full code, but it still doesnt work. I just wanted to share that base contains nothing
N0mlss
N0mlssOP15mo ago
That would be the code:
No description
N0mlss
N0mlssOP15mo ago
EditContext isnt even recognize as a properties of the SignBase class Also, if I remove the partial keyword from the signIn class, it works. It looks like I can't access properties of a parent class with a partial class
cathei
cathei15mo ago
Do you have other part of that partial class
SinFluxx
SinFluxx15mo ago
What's the error with the updated code?
Florian Voß
Florian Voß15mo ago
try if(base.EditContext.Validate())
N0mlss
N0mlssOP15mo ago
Its a blazor code. I dont know exactly how that works but here a screenshot:
No description
N0mlss
N0mlssOP15mo ago
An object reference is required for the non-static field, method, or property 'member'
TheRanger
TheRanger15mo ago
well EditContext is green, means it sees it as the class, not the property Green text indicates its a class
N0mlss
N0mlssOP15mo ago
I restarted my computer and this morning i have this error, but i didnt touch the code: Partial declarations of 'type' must not specify different base classes
No description
N0mlss
N0mlssOP15mo ago
Of course, but if i have a property with that name, it should come first I can change the name of the property if that helps?
TheRanger
TheRanger15mo ago
yes im thinking the issue could be with partial ,let me test
N0mlss
N0mlssOP15mo ago
As you can see, it is not the case, cause here it works when i change the name of the partial class
No description
N0mlss
N0mlssOP15mo ago
I think it has something to do with the fact that it is a code behind of a blazor page or something like that. Im new with blazor so i don't know yet how everything works
TheRanger
TheRanger15mo ago
makes sense u probably have another class of same name that does not extend SignBase
N0mlss
N0mlssOP15mo ago
Yeah probably, but since it is an "extention" of SignIn.razor, how do i change that?
N0mlss
N0mlssOP15mo ago
No description
TheRanger
TheRanger15mo ago
by renaming the class or the page
N0mlss
N0mlssOP15mo ago
Will it still recognize it as the code behind if i rename that class? Or will i need to add @inherit in the front page?
TheRanger
TheRanger15mo ago
is SignIn class suppose to be a partial class of the class that is defined in SignIn.razor.cs ?
SinFluxx
SinFluxx15mo ago
You've not got @inherits SomethingOtherThanSignBase in your SignIn.razor have you?
TheRanger
TheRanger15mo ago
you could just do public partial class SignIn
N0mlss
N0mlssOP15mo ago
It suppose to replace the @Code{} part inside of SignIn.razor
TheRanger
TheRanger15mo ago
without the : SIgnBase part
N0mlss
N0mlssOP15mo ago
Yeah but there is a bunch of code inside of SignBase that is used at more than one place. It wouldn't make sense to dupplicate the code if it does the same thing
TheRanger
TheRanger15mo ago
dont worry it will inherit from SignBase
N0mlss
N0mlssOP15mo ago
I dont inherit signbase tho, i inherit singin? Not usre to follow ahahah Huh? How? 😅 Lemme try
SinFluxx
SinFluxx15mo ago
Well, SignIn inherits from SignBase... I was just checking you didn't have different inheritance specified in your .razor vs your .razor.cs
TheRanger
TheRanger15mo ago
because it will detect that its a partial class from the other class that inherits SignBase
N0mlss
N0mlssOP15mo ago
Ahhh but i didnt specify anywhere else beside in signin.razor.cs that it inherits signbase. I dont know where to find sign.cs without the partial part, it that make sense
N0mlss
N0mlssOP15mo ago
No description
SinFluxx
SinFluxx15mo ago
SignIn.razor is the other part of SignIn.Razor.cs
N0mlss
N0mlssOP15mo ago
Alright, it looks like this for now:
No description
N0mlss
N0mlssOP15mo ago
No description
N0mlss
N0mlssOP15mo ago
as you can see in the previews picture, it doesnt work, since no where else i specify that signin inherits fron signbase
TheRanger
TheRanger15mo ago
by default, the SignIn page inherits from ComponentBase, u want it to inherit from SignBase instead, correct?
N0mlss
N0mlssOP15mo ago
Exact!
TheRanger
TheRanger15mo ago
well u have to use @inherits
N0mlss
N0mlssOP15mo ago
And rename that class?
TheRanger
TheRanger15mo ago
rename ur class so it doesnt conflict with the page's name
N0mlss
N0mlssOP15mo ago
Damn, i hate when the code behind isnt under the front code
TheRanger
TheRanger15mo ago
u dont even need to use partial now
N0mlss
N0mlssOP15mo ago
If i do that it won't stay under it collapsed
TheRanger
TheRanger15mo ago
@inherits is fine its just a single line
N0mlss
N0mlssOP15mo ago
I mean, if i rename signin.razor.cs to signbase.cs
TheRanger
TheRanger15mo ago
or u can rename the class
N0mlss
N0mlssOP15mo ago
yeah from signin.razor.cs to signbase.cs?
N0mlss
N0mlssOP15mo ago
No description
TheRanger
TheRanger15mo ago
suit yourself there is already a class called SignBase so it might cause issues
N0mlss
N0mlssOP15mo ago
Thats what i mean, signup.razor.cs collapses under signup.razor. But signinbase.cs doesnt collapses under signin.razor. For them to collapse they need to have the same class name but if i do that, i need to rename the class to have the same name thus not collapsing and yeah 😂 Only workaround would be to have the file name signin.razor.cs but inside i name the class signinbase so it works but I dont think it is good practice
TheRanger
TheRanger15mo ago
well, the file name can be different from the class name that is defined inside only applies for .cs tho
N0mlss
N0mlssOP15mo ago
No description
TheRanger
TheRanger15mo ago
for .razor the compiler generates a new class based on the file's name
N0mlss
N0mlssOP15mo ago
so it doesnt matter if i do that?
TheRanger
TheRanger15mo ago
yes
N0mlss
N0mlssOP15mo ago
Alright then it works. I thought it was bad practice to have the file name differemt from the class
N0mlss
N0mlssOP15mo ago
And the i inherits signinbase in the .razor file
No description
TheRanger
TheRanger15mo ago
👍🏻
N0mlss
N0mlssOP15mo ago
Thanks a lot for the help!!
Want results from more Discord servers?
Add your server