Browse Source

Marshal Cleanups

Josh Engebretson 10 years ago
parent
commit
2e947d19be

+ 72 - 80
Build/AtomicNETTest/AtomicEditor/AssemblyInspector.cs

@@ -20,8 +20,8 @@ namespace AtomicEditor
 	class AssemblyInspector
 	{
 
-    Dictionary<string, InspectorEnum> InspectorEnums = new Dictionary<string, InspectorEnum>();
-    Dictionary<string, InspectorComponent> InspectorComponents = new Dictionary<string, InspectorComponent>();
+		Dictionary<string, InspectorEnum> InspectorEnums = new Dictionary<string, InspectorEnum> ();
+		Dictionary<string, InspectorComponent> InspectorComponents = new Dictionary<string, InspectorComponent> ();
 
 		PEReader peFile;
 		MetadataReader metaReader;
@@ -31,29 +31,27 @@ namespace AtomicEditor
 
 		}
 
-    public string DumpToJSON ()
-    {
-        var dict = new Dictionary<string, object>();
+		public string DumpToJSON ()
+		{
+			var dict = new Dictionary<string, object> ();
 
-        var enumList = new List<object>();
-        var componentList = new List<object>();
+			var enumList = new List<object> ();
+			var componentList = new List<object> ();
 
-        foreach (var entry in InspectorEnums)
-        {
-          enumList.Add(entry.Value.GetJSONDict());
-        }
+			foreach (var entry in InspectorEnums) {
+				enumList.Add (entry.Value.GetJSONDict ());
+			}
 
-        foreach (var entry in InspectorComponents)
-        {
-          componentList.Add(entry.Value.GetJSONDict());
-        }
+			foreach (var entry in InspectorComponents) {
+				componentList.Add (entry.Value.GetJSONDict ());
+			}
 
-        dict["enums"] = enumList;
-        dict["components"] = componentList;
+			dict ["enums"] = enumList;
+			dict ["components"] = componentList;
 
-        return MiniJSON.Json.Serialize(dict);
+			return MiniJSON.Json.Serialize (dict);
 
-    }
+		}
 
 		public void Inspect (String pathToAssembly)
 		{
@@ -64,34 +62,32 @@ namespace AtomicEditor
 				metaReader = peFile.GetMetadataReader ();
 
 				ParseEnums ();
-        ParseComponents();
+				ParseComponents ();
 			}
 
 		}
 
-    void ParseComponents ()
+		void ParseComponents ()
 		{
 
-			foreach (var handle in metaReader.TypeDefinitions)
-      {
+			foreach (var handle in metaReader.TypeDefinitions) {
 				var typeDef = metaReader.GetTypeDefinition (handle);
 
 				var baseTypeHandle = typeDef.BaseType;
 
-				if (baseTypeHandle.Kind == HandleKind.TypeReference)
-        {
+				if (baseTypeHandle.Kind == HandleKind.TypeReference) {
 
 					var typeRef = metaReader.GetTypeReference ((TypeReferenceHandle)baseTypeHandle);
 
-          if (metaReader.GetString(typeRef.Name) != "CSComponent")
-            continue;
+					if (metaReader.GetString (typeRef.Name) != "CSComponent")
+						continue;
 
-          var inspector = new CSComponentInspector(typeDef, peFile, metaReader);
+					var inspector = new CSComponentInspector (typeDef, peFile, metaReader);
 
-          var icomponent = inspector.Inspect();
+					var icomponent = inspector.Inspect ();
 
-          if (icomponent != null)
-            InspectorComponents[icomponent.Name] = icomponent;
+					if (icomponent != null)
+						InspectorComponents [icomponent.Name] = icomponent;
 				}
 			}
 		}
@@ -99,18 +95,15 @@ namespace AtomicEditor
 
 		void ParseEnums ()
 		{
-			foreach (var handle in metaReader.TypeDefinitions)
-      {
+			foreach (var handle in metaReader.TypeDefinitions) {
 				var typeDef = metaReader.GetTypeDefinition (handle);
 
 				var baseTypeHandle = typeDef.BaseType;
 
-				if (baseTypeHandle.Kind == HandleKind.TypeReference)
-        {
+				if (baseTypeHandle.Kind == HandleKind.TypeReference) {
 					var typeRef = metaReader.GetTypeReference ((TypeReferenceHandle)baseTypeHandle);
 
-					if (metaReader.GetString (typeRef.Name) == "Enum")
-          {
+					if (metaReader.GetString (typeRef.Name) == "Enum") {
 						ParseEnum (typeDef);
 					}
 				}
@@ -122,11 +115,11 @@ namespace AtomicEditor
 
 			// TODO: verify that int32 is the enums storage type for constant read below
 
-      InspectorEnum ienum = new InspectorEnum();
+			InspectorEnum ienum = new InspectorEnum ();
 
-      ienum.Name = metaReader.GetString(enumTypeDef.Name);
+			ienum.Name = metaReader.GetString (enumTypeDef.Name);
 
-      InspectorEnums[ienum.Name] = ienum;
+			InspectorEnums [ienum.Name] = ienum;
 
 			var fields = enumTypeDef.GetFields ();
 
@@ -143,7 +136,7 @@ namespace AtomicEditor
 
 					BlobReader constantReader = metaReader.GetBlobReader (constant.Value);
 
-          ienum.Values[metaReader.GetString (fieldDef.Name)] = constantReader.ReadInt32 ();
+					ienum.Values [metaReader.GetString (fieldDef.Name)] = constantReader.ReadInt32 ();
 
 				}
 			}
@@ -153,62 +146,61 @@ namespace AtomicEditor
 		}
 	}
 
-  internal class InspectorEnum
-  {
-    public String Name;
-    public Dictionary<string, int> Values = new Dictionary<string, int>();
-
-    public Dictionary<string, object> GetJSONDict()
-    {
-      var dict = new Dictionary<string,object>();
-      dict["name"] = Name;
-      dict["values"] = Values;
-      return dict;
-    }
-  }
-
-  internal class InspectorComponent
-  {
-    public String Name;
+	internal class InspectorEnum
+	{
+		public String Name;
+		public Dictionary<string, int> Values = new Dictionary<string, int> ();
+
+		public Dictionary<string, object> GetJSONDict ()
+		{
+			var dict = new Dictionary<string,object> ();
+			dict ["name"] = Name;
+			dict ["values"] = Values;
+			return dict;
+		}
+	}
+
+	internal class InspectorComponent
+	{
+		public String Name;
 		public Dictionary<string, InspectorField> Fields = new Dictionary<string, InspectorField> ();
 
-		public Dictionary<string, object> GetJSONDict()
+		public Dictionary<string, object> GetJSONDict ()
 		{
-      var dict = new Dictionary<string,object>();
+			var dict = new Dictionary<string,object> ();
 
-      dict["name"] = Name;
-      var fieldList = new List<object>();
+			dict ["name"] = Name;
+			var fieldList = new List<object> ();
 
-      foreach (var entry in Fields)
-      {
-        fieldList.Add(entry.Value.GetJSONDict());
-      }
+			foreach (var entry in Fields) {
+				fieldList.Add (entry.Value.GetJSONDict ());
+			}
 
-      dict["fields"] = fieldList;
+			dict ["fields"] = fieldList;
 
-      return dict;
+			return dict;
 		}
-  }
+	}
 
 	internal class InspectorField
 	{
 
-    public Dictionary<string, object> GetJSONDict()
-    {
+		public Dictionary<string, object> GetJSONDict ()
+		{
 
-      var dict = new Dictionary<string,object>();
+			var dict = new Dictionary<string,object> ();
 
-      dict["isEnum"] = IsEnum;
-      dict["typeName"] = TypeName;
-      dict["name"] = Name;
-      dict["defaultValue"] = DefaultValue;
+			dict ["isEnum"] = IsEnum;
+			dict ["typeName"] = TypeName;
+			dict ["name"] = Name;
+			dict ["defaultValue"] = DefaultValue;
 
-      dict["customAttrPosArgs"] = CustomAttrPositionalArgs;
-      dict["customAttrNamedArgs"] = CustomAttrNamedArgs;
+			dict ["caPos"] = CustomAttrPositionalArgs;
+			dict ["caNamed"] = CustomAttrNamedArgs;
 
-      return dict;
+			return dict;
 
-    }
+		}
 
 		public bool IsEnum = false;
 

+ 3 - 3
Build/AtomicNETTest/AtomicEditor/AtomicEditor.cs

@@ -24,9 +24,9 @@ namespace AtomicEditor
 
 			try {
 
-				var inspector = new AssemblyInspector();
-				inspector.Inspect(pathToAssembly);
-				Console.WriteLine(inspector.DumpToJSON());
+				var inspector = new AssemblyInspector ();
+				inspector.Inspect (pathToAssembly);
+				Console.WriteLine (inspector.DumpToJSON ());
 
 			} catch (Exception ex) {
 				Console.WriteLine (ex.Message);

+ 305 - 305
Build/AtomicNETTest/AtomicEditor/CSComponentInspector.cs

@@ -33,7 +33,7 @@ using System.Reflection.PortableExecutable;
 
 namespace AtomicEditor
 {
-	
+
 	public class CSComponentInspector
 	{
 
@@ -45,8 +45,8 @@ namespace AtomicEditor
 			this.peFile = peFile;
 			this.metaReader = metaReader;
 
-			this._inspectorComponent = new InspectorComponent();
-			this._inspectorComponent.Name = metaReader.GetString(typeDef.Name);
+			this._inspectorComponent = new InspectorComponent ();
+			this._inspectorComponent.Name = metaReader.GetString (typeDef.Name);
 		}
 
 		// Inspect a CSComponent derived class
@@ -119,7 +119,7 @@ namespace AtomicEditor
 
 						inspectorField.TypeName = typeName;
 						inspectorField.Name = metaReader.GetString (fieldDef.Name);
-						_inspectorComponent.Fields[inspectorField.Name] = inspectorField;
+						_inspectorComponent.Fields [inspectorField.Name] = inspectorField;
 
 						break;
 					}
@@ -223,7 +223,7 @@ namespace AtomicEditor
 
 				// support string custom attr for now to simplify things
 				if (paramTypeCode != SignatureTypeCode.String)
-				return false;
+					return false;
 
 				string value;
 
@@ -257,17 +257,17 @@ namespace AtomicEditor
 
 				// support string custom attr for now to simplify things
 				if (typeCode != SerializationTypeCode.String)
-				return false;
+					return false;
 
 				string name;
 
 				if (!CrackStringInAttributeValue (out name, ref argsReader))
-				return false;
+					return false;
 
 				string value;
 
 				if (!CrackStringInAttributeValue (out value, ref argsReader))
-				return false;
+					return false;
 
 				inspectorField.CustomAttrNamedArgs [name] = value;
 
@@ -302,11 +302,11 @@ namespace AtomicEditor
 		}
 
 		public void InspectILBlock (
-		ImmutableArray<byte> ilBytes,
-		int length,
-		IReadOnlyList<HandlerSpan> spans = null,
-		int blockOffset = 0,
-		IReadOnlyDictionary<int, string> markers = null)
+			ImmutableArray<byte> ilBytes,
+			int length,
+			IReadOnlyList<HandlerSpan> spans = null,
+			int blockOffset = 0,
+			IReadOnlyDictionary<int, string> markers = null)
 		{
 			if (ilBytes == null) {
 				return;
@@ -317,14 +317,14 @@ namespace AtomicEditor
 		}
 
 		private int InspectILBlock (
-		ImmutableArray<byte> ilBytes,
-		int length,
-		IReadOnlyList<HandlerSpan> spans,
-		int blockOffset,
-		int curIndex,
-		int spanIndex,
-		IReadOnlyDictionary<int, string> markers,
-		out int nextSpanIndex)
+			ImmutableArray<byte> ilBytes,
+			int length,
+			IReadOnlyList<HandlerSpan> spans,
+			int blockOffset,
+			int curIndex,
+			int spanIndex,
+			IReadOnlyDictionary<int, string> markers,
+			out int nextSpanIndex)
 		{
 			int lastSpanIndex = spanIndex - 1;
 
@@ -370,7 +370,7 @@ namespace AtomicEditor
 
 					switch (opCode.OperandType) {
 
-						case OperandType.InlineField:
+					case OperandType.InlineField:
 
 						// read token
 						uint fieldToken = ReadUInt32 (ilBytes, ref curIndex);
@@ -398,31 +398,31 @@ namespace AtomicEditor
 						loadedValues.Clear ();
 
 						break;
-						case OperandType.InlineMethod:
+					case OperandType.InlineMethod:
 
 						// new Vector3, etc
 						if (opCode.ToString () == "newobj") {
 
-							} else
+						} else
 							loadedValues.Clear ();
 
-							break;
-							case OperandType.InlineTok:
-							case OperandType.InlineType:
-							ReadUInt32 (ilBytes, ref curIndex);
-							loadedValues.Clear ();
-							break;
+						break;
+					case OperandType.InlineTok:
+					case OperandType.InlineType:
+						ReadUInt32 (ilBytes, ref curIndex);
+						loadedValues.Clear ();
+						break;
 
-							case OperandType.InlineSig: // signature (calli), not emitted by C#/VB
-							ReadUInt32 (ilBytes, ref curIndex);
-							loadedValues.Clear ();
-							break;
+					case OperandType.InlineSig: // signature (calli), not emitted by C#/VB
+						ReadUInt32 (ilBytes, ref curIndex);
+						loadedValues.Clear ();
+						break;
 
-							case OperandType.InlineString:
+					case OperandType.InlineString:
 							//sb.Append(" 391 ");
 							//sb.Append(VisualizeUserString());
 
-							uint stringToken = ReadUInt32 (ilBytes, ref curIndex);
+						uint stringToken = ReadUInt32 (ilBytes, ref curIndex);
 
 							// get the kind
 							//uint tokenKind = stringToken & TokenTypeIds.TokenTypeMask;
@@ -430,137 +430,137 @@ namespace AtomicEditor
 							//uint rowId = stringToken & TokenTypeIds.RIDMask;
 
 
-							UserStringHandle handle = MetadataTokens.UserStringHandle ((int)stringToken);
-							loadedValues.Add (metaReader.GetUserString (handle));
+						UserStringHandle handle = MetadataTokens.UserStringHandle ((int)stringToken);
+						loadedValues.Add (metaReader.GetUserString (handle));
 
-							break;
+						break;
 
-							case OperandType.InlineNone:
+					case OperandType.InlineNone:
 
-							if (opCode == OpCodes.Ldc_I4_0)
+						if (opCode == OpCodes.Ldc_I4_0)
 							loadedValues.Add ("0");
-							else if (opCode == OpCodes.Ldc_I4_1)
+						else if (opCode == OpCodes.Ldc_I4_1)
 							loadedValues.Add ("1");
-							else if (opCode == OpCodes.Ldc_I4_2)
+						else if (opCode == OpCodes.Ldc_I4_2)
 							loadedValues.Add ("2");
-							else if (opCode == OpCodes.Ldc_I4_3)
+						else if (opCode == OpCodes.Ldc_I4_3)
 							loadedValues.Add ("3");
-							else if (opCode == OpCodes.Ldc_I4_4)
+						else if (opCode == OpCodes.Ldc_I4_4)
 							loadedValues.Add ("4");
-							else if (opCode == OpCodes.Ldc_I4_5)
+						else if (opCode == OpCodes.Ldc_I4_5)
 							loadedValues.Add ("5");
-							else if (opCode == OpCodes.Ldc_I4_6)
+						else if (opCode == OpCodes.Ldc_I4_6)
 							loadedValues.Add ("6");
-							else if (opCode == OpCodes.Ldc_I4_7)
+						else if (opCode == OpCodes.Ldc_I4_7)
 							loadedValues.Add ("7");
-							else if (opCode == OpCodes.Ldc_I4_8)
+						else if (opCode == OpCodes.Ldc_I4_8)
 							loadedValues.Add ("8");
-							else if (opCode == OpCodes.Ldc_I4_M1)
+						else if (opCode == OpCodes.Ldc_I4_M1)
 							loadedValues.Add ("-1");
 
-							break;
-
-							case OperandType.ShortInlineI:
-							loadedValues.Add (ReadSByte (ilBytes, ref curIndex).ToString ());
-							break;
+						break;
 
-							case OperandType.ShortInlineVar:
-							loadedValues.Add (ReadByte (ilBytes, ref curIndex).ToString ());
-							break;
+					case OperandType.ShortInlineI:
+						loadedValues.Add (ReadSByte (ilBytes, ref curIndex).ToString ());
+						break;
 
-							case OperandType.InlineVar:
-							loadedValues.Add (ReadUInt16 (ilBytes, ref curIndex).ToString ());
-							break;
+					case OperandType.ShortInlineVar:
+						loadedValues.Add (ReadByte (ilBytes, ref curIndex).ToString ());
+						break;
 
-							case OperandType.InlineI:
-							loadedValues.Add (ReadUInt32 (ilBytes, ref curIndex).ToString ());
-							break;
+					case OperandType.InlineVar:
+						loadedValues.Add (ReadUInt16 (ilBytes, ref curIndex).ToString ());
+						break;
 
-							case OperandType.InlineI8:
-							loadedValues.Add (ReadUInt64 (ilBytes, ref curIndex).ToString ());
-							break;
+					case OperandType.InlineI:
+						loadedValues.Add (ReadUInt32 (ilBytes, ref curIndex).ToString ());
+						break;
 
-							case OperandType.ShortInlineR:
-							{
-								loadedValues.Add (ReadSingle (ilBytes, ref curIndex).ToString ());
-							}
-							break;
+					case OperandType.InlineI8:
+						loadedValues.Add (ReadUInt64 (ilBytes, ref curIndex).ToString ());
+						break;
 
-							case OperandType.InlineR:
-							{
-								loadedValues.Add (ReadDouble (ilBytes, ref curIndex).ToString ());
-							}
-							break;
+					case OperandType.ShortInlineR:
+						{
+							loadedValues.Add (ReadSingle (ilBytes, ref curIndex).ToString ());
+						}
+						break;
 
-							case OperandType.ShortInlineBrTarget:
-							loadedValues.Clear ();
-							var sbyteValue = ReadSByte (ilBytes, ref curIndex) + curIndex + blockOffset;
-							break;
+					case OperandType.InlineR:
+						{
+							loadedValues.Add (ReadDouble (ilBytes, ref curIndex).ToString ());
+						}
+						break;
 
-							case OperandType.InlineBrTarget:
-							loadedValues.Clear ();
-							var int32value = ReadInt32 (ilBytes, ref curIndex) + curIndex + blockOffset;
-							break;
+					case OperandType.ShortInlineBrTarget:
+						loadedValues.Clear ();
+						var sbyteValue = ReadSByte (ilBytes, ref curIndex) + curIndex + blockOffset;
+						break;
 
-							case OperandType.InlineSwitch:
-							loadedValues.Clear ();
-							int labelCount = ReadInt32 (ilBytes, ref curIndex);
-							int instrEnd = curIndex + labelCount * 4;
-							for (int i = 0; i < labelCount; i++) {
-								var int32LabelValue = ReadInt32 (ilBytes, ref curIndex) + instrEnd + blockOffset;
-								//sb.AppendLine((i == labelCount - 1) ? ")" : ",");
-							}
-							break;
+					case OperandType.InlineBrTarget:
+						loadedValues.Clear ();
+						var int32value = ReadInt32 (ilBytes, ref curIndex) + curIndex + blockOffset;
+						break;
 
-							default:
-							throw new InvalidOperationException ();
-							//throw ExceptionUtilities.UnexpectedValue(opCode.OperandType);
+					case OperandType.InlineSwitch:
+						loadedValues.Clear ();
+						int labelCount = ReadInt32 (ilBytes, ref curIndex);
+						int instrEnd = curIndex + labelCount * 4;
+						for (int i = 0; i < labelCount; i++) {
+							var int32LabelValue = ReadInt32 (ilBytes, ref curIndex) + instrEnd + blockOffset;
+							//sb.AppendLine((i == labelCount - 1) ? ")" : ",");
 						}
+						break;
 
-						//sb.AppendLine();
+					default:
+						throw new InvalidOperationException ();
+					//throw ExceptionUtilities.UnexpectedValue(opCode.OperandType);
 					}
 
-					if (EndsSpan (spans, lastSpanIndex, curIndex + blockOffset)) {
-						break;
-					}
+					//sb.AppendLine();
 				}
 
-				nextSpanIndex = spanIndex;
-				return curIndex;
+				if (EndsSpan (spans, lastSpanIndex, curIndex + blockOffset)) {
+					break;
+				}
 			}
 
-			TypeDefinition typeDef;
-			PEReader peFile;
-			MetadataReader metaReader;
+			nextSpanIndex = spanIndex;
+			return curIndex;
+		}
 
-			private static readonly OpCode[] s_oneByteOpCodes;
-			private static readonly OpCode[] s_twoByteOpCodes;
+		TypeDefinition typeDef;
+		PEReader peFile;
+		MetadataReader metaReader;
 
-			static CSComponentInspector ()
-			{
-				s_oneByteOpCodes = new OpCode[0x100];
-				s_twoByteOpCodes = new OpCode[0x100];
+		private static readonly OpCode[] s_oneByteOpCodes;
+		private static readonly OpCode[] s_twoByteOpCodes;
 
-				var typeOfOpCode = typeof(OpCode);
+		static CSComponentInspector ()
+		{
+			s_oneByteOpCodes = new OpCode[0x100];
+			s_twoByteOpCodes = new OpCode[0x100];
 
-				foreach (FieldInfo fi in typeof(OpCodes).GetTypeInfo().DeclaredFields) {
-					if (fi.FieldType != typeOfOpCode) {
-						continue;
-					}
+			var typeOfOpCode = typeof(OpCode);
 
-					OpCode opCode = (OpCode)fi.GetValue (null);
-					var value = unchecked((ushort)opCode.Value);
-					if (value < 0x100) {
-						s_oneByteOpCodes [value] = opCode;
-					} else if ((value & 0xff00) == 0xfe00) {
-						s_twoByteOpCodes [value & 0xff] = opCode;
-					}
+			foreach (FieldInfo fi in typeof(OpCodes).GetTypeInfo().DeclaredFields) {
+				if (fi.FieldType != typeOfOpCode) {
+					continue;
+				}
+
+				OpCode opCode = (OpCode)fi.GetValue (null);
+				var value = unchecked((ushort)opCode.Value);
+				if (value < 0x100) {
+					s_oneByteOpCodes [value] = opCode;
+				} else if ((value & 0xff00) == 0xfe00) {
+					s_twoByteOpCodes [value & 0xff] = opCode;
 				}
 			}
+		}
 
-			private static ulong ReadUInt64 (ImmutableArray<byte> buffer, ref int pos)
-			{
-				ulong result =
+		private static ulong ReadUInt64 (ImmutableArray<byte> buffer, ref int pos)
+		{
+			ulong result =
 				buffer [pos] |
 				(ulong)buffer [pos + 1] << 8 |
 				(ulong)buffer [pos + 2] << 16 |
@@ -570,184 +570,184 @@ namespace AtomicEditor
 				(ulong)buffer [pos + 6] << 48 |
 				(ulong)buffer [pos + 7] << 56;
 
-				pos += sizeof(ulong);
-				return result;
-			}
+			pos += sizeof(ulong);
+			return result;
+		}
 
-			private static uint ReadUInt32 (ImmutableArray<byte> buffer, ref int pos)
-			{
-				uint result = buffer [pos] | (uint)buffer [pos + 1] << 8 | (uint)buffer [pos + 2] << 16 | (uint)buffer [pos + 3] << 24;
-				pos += sizeof(uint);
-				return result;
-			}
+		private static uint ReadUInt32 (ImmutableArray<byte> buffer, ref int pos)
+		{
+			uint result = buffer [pos] | (uint)buffer [pos + 1] << 8 | (uint)buffer [pos + 2] << 16 | (uint)buffer [pos + 3] << 24;
+			pos += sizeof(uint);
+			return result;
+		}
 
-			private static int ReadInt32 (ImmutableArray<byte> buffer, ref int pos)
-			{
-				return unchecked((int)ReadUInt32 (buffer, ref pos));
-			}
+		private static int ReadInt32 (ImmutableArray<byte> buffer, ref int pos)
+		{
+			return unchecked((int)ReadUInt32 (buffer, ref pos));
+		}
 
-			private static ushort ReadUInt16 (ImmutableArray<byte> buffer, ref int pos)
-			{
-				ushort result = (ushort)(buffer [pos] | buffer [pos + 1] << 8);
-				pos += sizeof(ushort);
-				return result;
-			}
+		private static ushort ReadUInt16 (ImmutableArray<byte> buffer, ref int pos)
+		{
+			ushort result = (ushort)(buffer [pos] | buffer [pos + 1] << 8);
+			pos += sizeof(ushort);
+			return result;
+		}
 
-			private static byte ReadByte (ImmutableArray<byte> buffer, ref int pos)
-			{
-				byte result = buffer [pos];
-				pos += sizeof(byte);
-				return result;
-			}
+		private static byte ReadByte (ImmutableArray<byte> buffer, ref int pos)
+		{
+			byte result = buffer [pos];
+			pos += sizeof(byte);
+			return result;
+		}
 
-			private static sbyte ReadSByte (ImmutableArray<byte> buffer, ref int pos)
-			{
-				sbyte result = unchecked((sbyte)buffer [pos]);
-				pos += 1;
-				return result;
-			}
+		private static sbyte ReadSByte (ImmutableArray<byte> buffer, ref int pos)
+		{
+			sbyte result = unchecked((sbyte)buffer [pos]);
+			pos += 1;
+			return result;
+		}
 
-			private unsafe static float ReadSingle (ImmutableArray<byte> buffer, ref int pos)
-			{
-				uint value = ReadUInt32 (buffer, ref pos);
-				return *(float*)&value;
-			}
+		private unsafe static float ReadSingle (ImmutableArray<byte> buffer, ref int pos)
+		{
+			uint value = ReadUInt32 (buffer, ref pos);
+			return *(float*)&value;
+		}
 
-			private unsafe static double ReadDouble (ImmutableArray<byte> buffer, ref int pos)
-			{
-				ulong value = ReadUInt64 (buffer, ref pos);
-				return *(double*)&value;
-			}
+		private unsafe static double ReadDouble (ImmutableArray<byte> buffer, ref int pos)
+		{
+			ulong value = ReadUInt64 (buffer, ref pos);
+			return *(double*)&value;
+		}
+
+		public enum HandlerKind
+		{
+			Try,
+			Catch,
+			Filter,
+			Finally,
+			Fault
+		}
 
-			public enum HandlerKind
+		public struct HandlerSpan : IComparable<HandlerSpan>
+		{
+			public readonly HandlerKind Kind;
+			public readonly object ExceptionType;
+			public readonly int StartOffset;
+			public readonly int FilterHandlerStart;
+			public readonly int EndOffset;
+
+			public HandlerSpan (HandlerKind kind, object exceptionType, int startOffset, int endOffset, int filterHandlerStart = 0)
 			{
-				Try,
-				Catch,
-				Filter,
-				Finally,
-				Fault
+				this.Kind = kind;
+				this.ExceptionType = exceptionType;
+				this.StartOffset = startOffset;
+				this.EndOffset = endOffset;
+				this.FilterHandlerStart = filterHandlerStart;
 			}
 
-			public struct HandlerSpan : IComparable<HandlerSpan>
+			public int CompareTo (HandlerSpan other)
 			{
-				public readonly HandlerKind Kind;
-				public readonly object ExceptionType;
-				public readonly int StartOffset;
-				public readonly int FilterHandlerStart;
-				public readonly int EndOffset;
-
-				public HandlerSpan (HandlerKind kind, object exceptionType, int startOffset, int endOffset, int filterHandlerStart = 0)
-				{
-					this.Kind = kind;
-					this.ExceptionType = exceptionType;
-					this.StartOffset = startOffset;
-					this.EndOffset = endOffset;
-					this.FilterHandlerStart = filterHandlerStart;
-				}
-
-				public int CompareTo (HandlerSpan other)
-				{
-					int result = this.StartOffset - other.StartOffset;
-					if (result == 0) {
-						// Both blocks have same start. Order larger (outer) before smaller (inner).
-						result = other.EndOffset - this.EndOffset;
-					}
-
-					return result;
-				}
-
-				public string ToString (CSComponentInspector visualizer)
-				{
-					switch (this.Kind) {
-						default:
-						return ".try";
-						case HandlerKind.Catch:
-						return "catch **exceptiontype**";// + visualizer.VisualizeLocalType(this.ExceptionType);
-						case HandlerKind.Filter:
-						return "filter";
-						case HandlerKind.Finally:
-						return "finally";
-						case HandlerKind.Fault:
-						return "fault";
-					}
+				int result = this.StartOffset - other.StartOffset;
+				if (result == 0) {
+					// Both blocks have same start. Order larger (outer) before smaller (inner).
+					result = other.EndOffset - this.EndOffset;
 				}
 
-				public override string ToString ()
-				{
-					throw new NotSupportedException ("Use ToString(CSComponentInspector)");
-				}
+				return result;
 			}
 
-			private static bool StartsSpan (IReadOnlyList<HandlerSpan> spans, int spanIndex, int curIndex)
+			public string ToString (CSComponentInspector visualizer)
 			{
-				return spans != null && spanIndex < spans.Count && spans [spanIndex].StartOffset == (uint)curIndex;
+				switch (this.Kind) {
+				default:
+					return ".try";
+				case HandlerKind.Catch:
+					return "catch **exceptiontype**";// + visualizer.VisualizeLocalType(this.ExceptionType);
+				case HandlerKind.Filter:
+					return "filter";
+				case HandlerKind.Finally:
+					return "finally";
+				case HandlerKind.Fault:
+					return "fault";
+				}
 			}
 
-			private static bool EndsSpan (IReadOnlyList<HandlerSpan> spans, int spanIndex, int curIndex)
+			public override string ToString ()
 			{
-				return spans != null && spanIndex >= 0 && spans [spanIndex].EndOffset == (uint)curIndex;
+				throw new NotSupportedException ("Use ToString(CSComponentInspector)");
 			}
+		}
 
-			private static bool StartsFilterHandler (IReadOnlyList<HandlerSpan> spans, int spanIndex, int curIndex)
-			{
-				return spans != null &&
-				spanIndex < spans.Count &&
-				spans [spanIndex].Kind == HandlerKind.Filter &&
-				spans [spanIndex].FilterHandlerStart == (uint)curIndex;
-			}
+		private static bool StartsSpan (IReadOnlyList<HandlerSpan> spans, int spanIndex, int curIndex)
+		{
+			return spans != null && spanIndex < spans.Count && spans [spanIndex].StartOffset == (uint)curIndex;
+		}
 
-			public static IReadOnlyList<HandlerSpan> GetHandlerSpans (ImmutableArray<ExceptionRegion> entries)
-			{
-				if (entries.Length == 0) {
-					return new HandlerSpan[0];
-				}
+		private static bool EndsSpan (IReadOnlyList<HandlerSpan> spans, int spanIndex, int curIndex)
+		{
+			return spans != null && spanIndex >= 0 && spans [spanIndex].EndOffset == (uint)curIndex;
+		}
 
-				var result = new List<HandlerSpan> ();
-				foreach (ExceptionRegion entry in entries) {
-					int tryStartOffset = entry.TryOffset;
-					int tryEndOffset = entry.TryOffset + entry.TryLength;
-					var span = new HandlerSpan (HandlerKind.Try, null, tryStartOffset, tryEndOffset);
+		private static bool StartsFilterHandler (IReadOnlyList<HandlerSpan> spans, int spanIndex, int curIndex)
+		{
+			return spans != null &&
+			spanIndex < spans.Count &&
+			spans [spanIndex].Kind == HandlerKind.Filter &&
+			spans [spanIndex].FilterHandlerStart == (uint)curIndex;
+		}
 
-					if (result.Count == 0 || span.CompareTo (result [result.Count - 1]) != 0) {
-						result.Add (span);
-					}
-				}
+		public static IReadOnlyList<HandlerSpan> GetHandlerSpans (ImmutableArray<ExceptionRegion> entries)
+		{
+			if (entries.Length == 0) {
+				return new HandlerSpan[0];
+			}
 
-				foreach (ExceptionRegion entry in entries) {
-					int handlerStartOffset = entry.HandlerOffset;
-					int handlerEndOffset = entry.HandlerOffset + entry.HandlerLength;
+			var result = new List<HandlerSpan> ();
+			foreach (ExceptionRegion entry in entries) {
+				int tryStartOffset = entry.TryOffset;
+				int tryEndOffset = entry.TryOffset + entry.TryLength;
+				var span = new HandlerSpan (HandlerKind.Try, null, tryStartOffset, tryEndOffset);
 
-					HandlerSpan span;
-					switch (entry.Kind) {
-						case ExceptionRegionKind.Catch:
-						span = new HandlerSpan (HandlerKind.Catch, MetadataTokens.GetToken (entry.CatchType), handlerStartOffset, handlerEndOffset);
-						break;
+				if (result.Count == 0 || span.CompareTo (result [result.Count - 1]) != 0) {
+					result.Add (span);
+				}
+			}
 
-						case ExceptionRegionKind.Fault:
-						span = new HandlerSpan (HandlerKind.Fault, null, handlerStartOffset, handlerEndOffset);
-						break;
+			foreach (ExceptionRegion entry in entries) {
+				int handlerStartOffset = entry.HandlerOffset;
+				int handlerEndOffset = entry.HandlerOffset + entry.HandlerLength;
 
-						case ExceptionRegionKind.Filter:
-						span = new HandlerSpan (HandlerKind.Filter, null, handlerStartOffset, handlerEndOffset, entry.FilterOffset);
-						break;
+				HandlerSpan span;
+				switch (entry.Kind) {
+				case ExceptionRegionKind.Catch:
+					span = new HandlerSpan (HandlerKind.Catch, MetadataTokens.GetToken (entry.CatchType), handlerStartOffset, handlerEndOffset);
+					break;
 
-						case ExceptionRegionKind.Finally:
-						span = new HandlerSpan (HandlerKind.Finally, null, handlerStartOffset, handlerEndOffset);
-						break;
+				case ExceptionRegionKind.Fault:
+					span = new HandlerSpan (HandlerKind.Fault, null, handlerStartOffset, handlerEndOffset);
+					break;
 
-						default:
-						throw new InvalidOperationException ();
-					}
+				case ExceptionRegionKind.Filter:
+					span = new HandlerSpan (HandlerKind.Filter, null, handlerStartOffset, handlerEndOffset, entry.FilterOffset);
+					break;
 
-					result.Add (span);
+				case ExceptionRegionKind.Finally:
+					span = new HandlerSpan (HandlerKind.Finally, null, handlerStartOffset, handlerEndOffset);
+					break;
+
+				default:
+					throw new InvalidOperationException ();
 				}
 
-				return result;
+				result.Add (span);
 			}
 
-			public void Dump ()
-			{
-				/*
+			return result;
+		}
+
+		public void Dump ()
+		{
+			/*
 				foreach (var entry in InspectorFields) {
 					var field = entry.Value;
 
@@ -765,43 +765,43 @@ namespace AtomicEditor
 					Console.WriteLine ("      {0}:{1}", nentry.Key, nentry.Value);
 				}
 				*/
-			}
-
-		}
-
-		internal static class TokenTypeIds
-		{
-			internal const uint Module = 0x00000000;
-			internal const uint TypeRef = 0x01000000;
-			internal const uint TypeDef = 0x02000000;
-			internal const uint FieldDef = 0x04000000;
-			internal const uint MethodDef = 0x06000000;
-			internal const uint ParamDef = 0x08000000;
-			internal const uint InterfaceImpl = 0x09000000;
-			internal const uint MemberRef = 0x0a000000;
-			internal const uint CustomAttribute = 0x0c000000;
-			internal const uint Permission = 0x0e000000;
-			internal const uint Signature = 0x11000000;
-			internal const uint Event = 0x14000000;
-			internal const uint Property = 0x17000000;
-			internal const uint ModuleRef = 0x1a000000;
-			internal const uint TypeSpec = 0x1b000000;
-			internal const uint Assembly = 0x20000000;
-			internal const uint AssemblyRef = 0x23000000;
-			internal const uint File = 0x26000000;
-			internal const uint ExportedType = 0x27000000;
-			internal const uint ManifestResource = 0x28000000;
-			internal const uint GenericParam = 0x2a000000;
-			internal const uint MethodSpec = 0x2b000000;
-			internal const uint GenericParamConstraint = 0x2c000000;
-			internal const uint String = 0x70000000;
-			internal const uint Name = 0x71000000;
-			internal const uint BaseType = 0x72000000;
-			// Leave this on the high end value. This does not correspond to metadata table???
-
-			internal const uint RIDMask = 0x00FFFFFF;
-			internal const uint TokenTypeMask = 0xFF000000;
 		}
 
+	}
 
+	internal static class TokenTypeIds
+	{
+		internal const uint Module = 0x00000000;
+		internal const uint TypeRef = 0x01000000;
+		internal const uint TypeDef = 0x02000000;
+		internal const uint FieldDef = 0x04000000;
+		internal const uint MethodDef = 0x06000000;
+		internal const uint ParamDef = 0x08000000;
+		internal const uint InterfaceImpl = 0x09000000;
+		internal const uint MemberRef = 0x0a000000;
+		internal const uint CustomAttribute = 0x0c000000;
+		internal const uint Permission = 0x0e000000;
+		internal const uint Signature = 0x11000000;
+		internal const uint Event = 0x14000000;
+		internal const uint Property = 0x17000000;
+		internal const uint ModuleRef = 0x1a000000;
+		internal const uint TypeSpec = 0x1b000000;
+		internal const uint Assembly = 0x20000000;
+		internal const uint AssemblyRef = 0x23000000;
+		internal const uint File = 0x26000000;
+		internal const uint ExportedType = 0x27000000;
+		internal const uint ManifestResource = 0x28000000;
+		internal const uint GenericParam = 0x2a000000;
+		internal const uint MethodSpec = 0x2b000000;
+		internal const uint GenericParamConstraint = 0x2c000000;
+		internal const uint String = 0x70000000;
+		internal const uint Name = 0x71000000;
+		internal const uint BaseType = 0x72000000;
+		// Leave this on the high end value. This does not correspond to metadata table???
+
+		internal const uint RIDMask = 0x00FFFFFF;
+		internal const uint TokenTypeMask = 0xFF000000;
 	}
+
+
+}

+ 6 - 7
Build/AtomicNETTest/MyClass.cs

@@ -4,11 +4,11 @@ using System;
 
 namespace AtomicNETTest
 {
-    public enum MyEnum
+    public enum BehaviorState
     {
-      One,
-      Two = 10,
-      Three
+      Friendly,
+      Aggressive = 10,
+      Neutral
     }
 
     public class MyComponent : CSComponent
@@ -25,19 +25,18 @@ namespace AtomicNETTest
         [Inspector]
         public Quaternion MyQuaternionValue = new Quaternion(1, 1, 1, 1);
 
-        [Inspector("HeyHeyMyMy", Value2 = "one")]
+        [Inspector(Value1 = "This is a", Value2 = "test")]
         public float MyFloatValue = 42.0f;
 
         [Inspector]
         public string MyStringValue = "Hey!";
 
         [Inspector]
-        public MyEnum MyEnumValue = MyEnum.Three;
+        public BehaviorState State = BehaviorState.Neutral;
 
         [Inspector("Sprites/star.png")]
         public Sprite2D sprite2D;
 
-
     }
 
 }