Skip to content

Instantly share code, notes, and snippets.

@Arakade
Last active September 24, 2016 16:22
Show Gist options
  • Save Arakade/11da94e1b6eab96a194a9c2b69368244 to your computer and use it in GitHub Desktop.
Save Arakade/11da94e1b6eab96a194a9c2b69368244 to your computer and use it in GitHub Desktop.
Class compiles in MonoDevelop Unity 3.5 full profile and VisualStudio but not Unity 5.4.0 - Unity bug 834988
using System;
namespace MiscCSharp {
public static class AbstractGenericProtected {
public static void Main(string[] args) {
var debugGraph = new DebugGraph { start = 5, end = 4, numRecords = 10 };
var floatSeries = new FloatSeries(debugGraph, "series1");
floatSeries.doStuff();
System.Console.WriteLine("All done");
}
}
public abstract class Series<T> {
internal DebugGraph owner;
/// <summary>
/// Whether <see cref="DebugGraph"/> should set the old values to false after they wrap.
/// Must be implemented in concrete sub-class' <see cref="renderRecords"/>.
/// </summary>
internal AutoClearType autoClearOld;
/// <summary>
/// The value written when <see cref="autoClearOld"/> <see cref="AutoClearType.Default"/> enabled.
/// A public member so arbitrary values can be assigned.
/// </summary>
public T defaultValue = default(T);
internal readonly T[] records;
public int currentIndex { get { return owner.start; } }
public int nextIndexToBeWritten { get { return owner.end; } }
/// <summary>
/// Initializes a new instance of the <see cref="DebugGraph.Series"/> class.
/// </summary>
protected Series(DebugGraph owner, string name, AutoClearType autoClearOld = AutoClearType.Default) {
this.owner = owner;
this.autoClearOld = autoClearOld;
this.records = new T[owner.numRecords];
}
public void doStuff() {
doAutoClear(); // test calling it
}
public void doAutoClear() {
switch (autoClearOld) {
case AutoClearType.None:
break;
case AutoClearType.Default:
records[nextIndexToBeWritten] = defaultValue; // error CS0103: The name `nextIndexToBeWritten' does not exist in the current context
break;
case AutoClearType.Previous:
records[nextIndexToBeWritten] = records[currentIndex]; // error CS0103: The name `currentIndex' does not exist in the current context (and `nextIndexToBeWritten')
break;
default:
throw new System.NotImplementedException(string.Format("{0} '{1}'", typeof(AutoClearType).Name, autoClearOld));
}
}
}
public class FloatSeries : Series<float> {
internal FloatSeries(DebugGraph owner, string name, AutoClearType autoClearOld = AutoClearType.Default) : base(owner, name, autoClearOld) {
}
}
// Version without Generics as contrast.
public abstract class SeriesNonGeneric {
internal DebugGraph owner;
/// <summary>
/// Whether <see cref="DebugGraph"/> should set the old values to false after they wrap.
/// Must be implemented in concrete sub-class' <see cref="renderRecords"/>.
/// </summary>
internal AutoClearType autoClearOld;
/// <summary>
/// The value written when <see cref="autoClearOld"/> <see cref="AutoClearType.Default"/> enabled.
/// A public member so arbitrary values can be assigned.
/// </summary>
public float defaultValue = 0f;
internal readonly float[] records;
public int currentIndex { get { return owner.start; } }
public int nextIndexToBeWritten { get { return owner.end; } }
/// <summary>
/// Initializes a new instance of the <see cref="DebugGraph.Series"/> class.
/// </summary>
protected SeriesNonGeneric(DebugGraph owner, string name, AutoClearType autoClearOld = AutoClearType.Default) {
this.owner = owner;
this.autoClearOld = autoClearOld;
this.records = new float[owner.numRecords];
}
public void doStuff() {
doAutoClear(); // test calling it
}
public void doAutoClear() {
switch (autoClearOld) {
case AutoClearType.None:
break;
case AutoClearType.Default:
records[nextIndexToBeWritten] = defaultValue; // error CS0103: The name `nextIndexToBeWritten' does not exist in the current context
break;
case AutoClearType.Previous:
records[nextIndexToBeWritten] = records[currentIndex]; // error CS0103: The name `currentIndex' does not exist in the current context (and `nextIndexToBeWritten')
break;
default:
throw new System.NotImplementedException(string.Format("{0} '{1}'", typeof(AutoClearType).Name, autoClearOld));
}
}
}
public class FloatSeriesNonGenerics : SeriesNonGeneric {
internal FloatSeriesNonGenerics(DebugGraph owner, string name, AutoClearType autoClearOld = AutoClearType.Default) : base(owner, name, autoClearOld) {
}
}
public class DebugGraph {
public int start;
public int end;
public int numRecords;
}
/// <summary>
/// Whether to clear the next value to be written (and values that have fallen off left side).
/// </summary>
public enum AutoClearType {
/// <summary>
/// Do no clearing.
/// </summary>
None,
/// <summary>
/// Assign the 'default' value.
/// </summary>
Default,
/// <summary>
/// Assign the previous value.
/// </summary>
Previous,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment