Skip to main content

All Questions

Tagged with
1 vote
0 answers
29 views

Complex multi level EF Core 8 inheritance issue

Please consider the following: DB Context: // DbContext.cs public partial class OperationsDbContext : DbContext { public virtual DbSet<AnimalBase> AnimalBases { get; set; } public virtual ...
Mejenborg's user avatar
1 vote
1 answer
31 views

polymorphic type displaying as blank in the inspector

It's not easy to specifically explain what the problem is, and the code through which the problem could be originating is extensive, and I am uncertain how to narrow it down beyond what I already have,...
RWolfe's user avatar
  • 178
-1 votes
1 answer
41 views

How to set up classes for parsing custom data types in C#

I'm working on a saving/loading system, and I'm trying to serialize and deserialize various objects. I'm working in Unity, and I've created one custom class for the game objects and their behaviours, ...
Adam L.'s user avatar
  • 89
0 votes
1 answer
51 views

How do I match types when trying to write polymorphic classes in C# or am I using the wrong pattern?

TLDR; I'm looking for a pattern that allows me to have a base class and derived classes that handle objects of various different classes but which are all derived from one interface/base class - ...
Alex Masidlover's user avatar
1 vote
1 answer
40 views

Passing derived class to a method

newbie here, trying to figure out best way to achieve the following: Have a base class: public class MessageBaseDto { public string AssetId { get; set; } } And 2 derived classes: public class ...
flawia's user avatar
  • 11
0 votes
0 answers
51 views

Downcast with swig director classes

I have the following C++ code class CPPSession { }; class CPPModule { virtual CPPSession* create_session() { return new CPPSession; } virtual void do_something(CPPSession* ...
arthurbesse's user avatar
0 votes
1 answer
24 views

System.InvalidCastException while inheriting a class

I've created a class for a binary search tree called BSTree. I want to create a class for AVL tree called AVLTree and inherit BSTree class. But when I override a virtual method from BSTree class in ...
olesatthewheel's user avatar
0 votes
1 answer
36 views

Hide generic type arguments behind concrete type results in CS0535

I've a rather academic question: why is it technically not possible to use the following code? // abstractions public record MappingRequest<TContract, TEntity>( TContract Contract, TEntity ...
mu88's user avatar
  • 5,063
-2 votes
1 answer
61 views

How would you create a list/array containing variables instantiated from classes in C#?

So, I've been trying to create a list in C# that will contain variables that are instantiations of classes. I'm still quite new to C# and this was just supposed to be a practice exercise, but lists ...
kyupid_codes's user avatar
-1 votes
2 answers
74 views

Difference between creating objects with master/sub class "Cat cat1 = new Cat(); vs Animal cat2 = new Cat();"

(First time posting in Stackoverflow, so If I did it wrong, I am sorry =( ) What is the difference between creating an object from its class or the class its inheriting from? I made this code: ...
MrV's user avatar
  • 1
0 votes
3 answers
151 views

is it possible to fully override a property in c#?

i have a parent class coming from a library i don't control, and i'm trying to create a child class that overrides a public property in that class. i found that the answer is to use the new keyword, ...
ditzy's user avatar
  • 31
0 votes
2 answers
111 views

C# class inheritance and polymorphism with polymorphic fields

I'm running into an occasional design issue with classes, mostly in some video game stuff. The problem arises when a class that extends another class (such as a Player) has a field that is also a ...
samala7800's user avatar
0 votes
2 answers
571 views

Can I customize and shorten the polymorphic type discriminator property name and value when serializing?

Is it possible to shorten the type discriminator property name and value during serialization/deserialization? I don't have access to the types itself so in my case it should be done by configuring ...
Yola's user avatar
  • 18.9k
0 votes
1 answer
2k views

Polymorphic Json Serialization/Deserialization with custom Converter broken with .NET 8

I have some classes using polymorphism and I need to send them via an OData Controller to the client. On the client I have added Converters to JsonSerializerOptions in order to determine the correct ...
phil ius's user avatar
0 votes
0 answers
52 views

How can I write one method that accepts either Graphics or XGraphics as argument?

I have code that uses Graphics class to draw string on a PNG image, and very similar code to generate PDF (using PdfSharp) void DrawText(Graphics gfx, string text) // used to draw PNG images { // ...
Ahmad's user avatar
  • 12.5k

15 30 50 per page
1
2 3 4 5
87