Subtype polymorphism
As I see subtype polymorphism is not possible. It's a pity. My first intention was to make some abstract class Element and overload two methods in derived classes to make a graph with different nodes and draw it, but now I stuck with it... Maybe I dont know something... do you have a workaround for that?
I can think of some ways to accomplish what I think you're trying to accomplish.
However your description is quite abstract, so not sure an answer will serve its purpose. If you'd like to share more details about the scenario, and esp. the code you'd like to write or the script you'd like to generate, that would help make it more concrete, feel free to reopen with those details.
Thank you for the quick reply!
What I think to implement with scriptsharp is something like WPF object library. Well, not whole, at least layout engine. The code:
public abstract class UIElement { public Size Measure() {..} protected abstract Size MeasureCore(Size availableSize); public void Arrange() {...} protected abstract Size ArrangeCore(Size availableSize); }
public class StackPanel : UIElement
{
public IEnumerable
public class TextBlock : UIElement { public string Text {get;set... protected override Size MeasureCore(Size availableSize) {...} protected override Size ArrangeCore(Size availableSize) {...} }
(I dont have permission to re-open)
This is just normal class derivation, and overridable methods. Which part of this didn't work for you? It compiles just fine ... here is the command to compile: ssc /ref:mscorlib.dll /out:Test.js Test.cs
and here is the exact code I used:
using System;
using System.Runtime.CompilerServices;
[assembly: ScriptAssembly("sample")]
public class Size {
public Size(int x, int y) { }
}
public abstract class UIElement
{
public Size Measure() {
return MeasureCore(new Size(0, 0));
}
protected abstract Size MeasureCore(Size availableSize);
public void Arrange() {
return ArrangeCore(new Size(0, 0));
}
protected abstract Size ArrangeCore(Size availableSize);
}
public class StackPanel : UIElement
{
public IEnumerable Children {
get { return null; }
}
protected override Size MeasureCore(Size availableSize) {
return new Size(0,0);
}
protected override Size ArrangeCore(Size availableSize) {
return new Size(0,0);
}
}
public class TextBlock : UIElement
{
private string _text;
public string Text {
get { return _text; }
set { _text = value; }
}
protected override Size MeasureCore(Size availableSize) {
return new Size(0,0);
}
protected override Size ArrangeCore(Size availableSize) {
return new Size(0,0);
}
}
I am just back here to thank you. This compiles like a charm! You do the great job, many thanks!
P.S. I have some issues and propositions, I will submit it in separate requests. Thank you