Questions tagged [sealed]

The sealed modifier keyword prevents a C# class from being inherited. Similar to the final keyword in Java.

The sealed modifier keyword prevents a C# class from being inherited. Similar to the final keyword in Java.

183 questions
0
votes
1 answer

Kotlin : error: unresolved reference for a method inside a sealed class

This small code gives error: unresolved reference: make : sealed class Color () { object Red : Color() object Blue : Color() override fun toString(): String = when (this) { is Red -> "Red" is Blue -> "Blue" …
Emile Achadde
  • 1,715
  • 3
  • 10
  • 22
0
votes
1 answer

"fromString" method on case classes extending a sealed trait

Is there an idiomatic way of generating something like a fromString method on a sealed trait for use with case classes? For example, something like: sealed trait ExampleEnum {def id: Any} final case class One(first: String) extends ExampleEnum{…
cohoz
  • 750
  • 4
  • 16
0
votes
2 answers

Scala: how to extend an immutable List

Many methods of a program receive as parameter a List[Map[String, String]]. I'd like to formalize it and make it more readable by defining a class such as: class MyClass extends List[Map[String, String]] However it throws an error: Illegal…
Rolintocour
  • 2,934
  • 4
  • 32
  • 63
0
votes
3 answers

How to know if you can instantiate a class or interface if it is sealed, inherited or abstract in C#?

I am having difficulties knowing which of the following classes / interfaces can I instantiate in the Main method (which class / interface is completely OK). The code goes like this for some of the classes and interfaces: interface A {public void…
0
votes
2 answers

Raise event when property is changed

I need to raise an event when the value of the property is changed. In my case this is when webView.Source is changed. I can't make a derived class because the class is marked as sealed. Is there any way to raise an event ? Thank you.
Greenkiller
  • 200
  • 2
  • 12
0
votes
1 answer

Why sealed and singleton?

Possible Duplicate: Purpose of final and sealed Hi all, When should we opt for designing a sealed class? When should we opt for designing a singleton class?
ramu
  • 1,019
  • 3
  • 15
  • 41
0
votes
1 answer

Pureconfig Typesafe Config with sealed abstract case class

I am trying to incorporate Pureconfig in my use case for typesafe configurations. Been successful in mapping HOCON .conf to case class types. However, if I have to constrain my types with no side-effects on the object definition side (i.e., supress…
ganaakruti
  • 23
  • 4
0
votes
2 answers

C# - Extending existing framework sealed class

Consider the sealed framework class "WorkItem" (MSDN-description) I would like to extend this sealed class so I can write extension methods of the class e.g. I could write: workitem.ReadWrite(); Is this possible to implement, if so how could it be…
Jaja1415
  • 113
  • 1
  • 5
0
votes
1 answer

Marking External Library Sealed Class as Obsolete

This is a bit of a nasty one; I have an "external" library (technically internal to the company but the original source code is no longer available, just the DLL) with a sealed class that is/should be marked as obsolete. Is it possible to do? I…
Trent
  • 1,595
  • 15
  • 37
0
votes
3 answers

What is the difference between a sealed class and a private class?

I know that you can not inherit from a class once sealed is used but I am confused what is the difference between these two: private and sealed? Can't we make the base class members private if we don't want to inherit them instead of the whole…
user8080469
0
votes
1 answer

UWP C#: Where does VS remember inheritance in a project

I was playing around trying to design a button and I came up with using a Border with a Button on it. Then I changed my MyClass to derive from Border. Border is a sealed class so the compiler flagged an error. So I removed the ": Border" from the…
Paulustrious
  • 609
  • 1
  • 11
  • 17
0
votes
1 answer

Hidden Inherritance c#

In c#, is it possible to prevent the programmer to inherit a parent class, but allow child classes to be inherited from (perhaps just during the writing of the code, not during runtime)? For example: //Class which should only allow 'RangedAbility'…
user3593478
0
votes
3 answers

Inheritance and sealed

Should I always specify a class as sealed if it's the last in the inheritance list? As an example, say I've got 3 classes, Foundation, Building, and House. public class Foundation { // Base class } public class Building : Foundation { //…
Alexej
  • 97
  • 1
  • 1
  • 6
0
votes
0 answers

List of a sealed class inside a sealed class| windows phone 8.1

I'm parsing JSON in a background task. I'm parsing the result to a class with the NewtonSoft parser. Because the classes i'm parsing the result are sealed, it gives conflicts when i use a list of sealed class A in sealed class B This gives me the…
Jeroen Brock
  • 191
  • 8
0
votes
1 answer

Make a public class only extensible within an assembly?

Is something like this possible in C#? What about CLR in general? public sealed-outside class MySample { }
Den
  • 1,827
  • 3
  • 25
  • 46