Created
September 6, 2016 20:45
-
-
Save mattpodwysocki/0b52d3394e1a895dd612b6ca00db03d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace CSSLayoutApp | |
{ | |
public class CSSNode : IDisposable | |
{ | |
private bool _isDisposed; | |
private readonly IntPtr _cssNode; | |
public CSSNode() | |
{ | |
_cssNode = Native.CSSNodeNew(); | |
Native.CSSNodeInit(_cssNode); | |
} | |
public CSSNode(IntPtr cssNode) | |
{ | |
_cssNode = cssNode; | |
} | |
private void CheckDisposed() | |
{ | |
if (_isDisposed) | |
{ | |
throw new ObjectDisposedException("CSSNode"); | |
} | |
} | |
public void Dispose() | |
{ | |
if (!_isDisposed) | |
{ | |
_isDisposed = true; | |
Native.CSSNodeFree(_cssNode); | |
} | |
} | |
public CSSNode this[int index] | |
{ | |
get | |
{ | |
CheckDisposed(); | |
var ptr = Native.CSSNodeGetChild(_cssNode, (uint)index); | |
return new CSSNode(ptr); | |
} | |
} | |
public int Count | |
{ | |
get | |
{ | |
CheckDisposed(); | |
return (int)Native.CSSNodeChildCount(_cssNode); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment