✅ 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
64 Replies
What's the actual error?
There is just nothing after base.
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Well that would be the error, then
thing.Property;
just does... nothingits like ur putting
1;
I mean i can write the full code, but it still doesnt work. I just wanted to share that base contains nothing
That would be the code:
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
Do you have other part of that partial class
What's the error with the updated code?
try
if(base.EditContext.Validate())
Its a blazor code. I dont know exactly how that works but here a screenshot:
An object reference is required for the non-static field, method, or property 'member'
well EditContext is green, means it sees it as the class, not the property
Green text indicates its a class
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
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?
yes im thinking the issue could be with partial ,let me test
As you can see, it is not the case, cause here it works when i change the name of the partial class
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
makes sense
u probably have another class of same name that does not extend SignBase
Yeah probably, but since it is an "extention" of SignIn.razor, how do i change that?
by renaming the class
or the page
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?
is SignIn class suppose to be a partial class of the class that is defined in SignIn.razor.cs ?
You've not got
@inherits SomethingOtherThanSignBase
in your SignIn.razor have you?you could just do
public partial class SignIn
It suppose to replace the @Code{} part inside of SignIn.razor
without the : SIgnBase part
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
dont worry it will inherit from SignBase
I dont inherit signbase tho, i inherit singin? Not usre to follow ahahah
Huh? How? 😅
Lemme try
Well, SignIn inherits from SignBase... I was just checking you didn't have different inheritance specified in your .razor vs your .razor.cs
because it will detect that its a partial class from the other class that inherits SignBase
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
SignIn.razor is the other part of SignIn.Razor.cs
Alright, it looks like this for now:
as you can see in the previews picture, it doesnt work, since no where else i specify that signin inherits fron signbase
by default, the SignIn page inherits from ComponentBase, u want it to inherit from SignBase instead, correct?
Exact!
well u have to use @inherits
And rename that class?
rename ur class so it doesnt conflict with the page's name
Damn, i hate when the code behind isnt under the front code
u dont even need to use partial now
If i do that it won't stay under it collapsed
@inherits is fine its just a single line
I mean, if i rename signin.razor.cs to signbase.cs
or u can rename the class
yeah from signin.razor.cs to signbase.cs?
suit yourself
there is already a class called SignBase
so it might cause issues
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
well, the file name can be different from the class name that is defined inside
only applies for .cs tho
for .razor the compiler generates a new class based on the file's name
so it doesnt matter if i do that?
yes
Alright then it works. I thought it was bad practice to have the file name differemt from the class
And the i inherits signinbase in the .razor file
👍🏻
Thanks a lot for the help!!