//public void Set() //{ // Drawer.depth = this; //} public void Set(Action action) { DepthLayer previous = Drawer.depth; Drawer.depth = this; action(); Drawer.depth = previous; }
private static void InitDepthClass(Type type) { List <DepthLayer> depthList = new List <DepthLayer>(); var properties = from property in type.GetFields() where Attribute.IsDefined(property, typeof(OrderAttribute)) orderby((OrderAttribute)property .GetCustomAttributes(typeof(OrderAttribute), false) .Single()).Order select property; int line = -1; int lineCount = 0; foreach (var property in properties) { int cLine = ((OrderAttribute)property .GetCustomAttributes(typeof(OrderAttribute), false) .Single()).Order; if (cLine > line) { line = cLine; lineCount++; } else if (cLine < line) { throw new Exception(); } } float partition = 1f / lineCount; float depth = 0f; line = -1; foreach (var property in properties) { int cLine = ((OrderAttribute)property .GetCustomAttributes(typeof(OrderAttribute), false) .Single()).Order; if (cLine > line) { // new depth layer if (line != -1) // if first one, don't skip 0f depth { depth += partition; } line = cLine; DepthLayer d = new DepthLayer(depth); property.SetValue(null, d); depthList.Add(d); } else { property.SetValue(null, depthList.Last()); } } depths.Add(type, depthList); }