protected StateToken(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { var e = info.GetEnumerator(); while (e.MoveNext()) { _table[e.Current.Name] = e.Current.Value; } }
internal static IntPtr ReadIntoProfileContext(System.Runtime.Serialization.SerializationInfo info, string sectionBase) { IntPtr pProfileContext = UnsafeNativeMethods.CRhCmnProfileContext_New(); var e = info.GetEnumerator(); while (e.MoveNext()) { string entry = e.Name.Replace("::", "\\"); string section = sectionBase; int split_index = entry.LastIndexOf("\\", System.StringComparison.Ordinal); if (split_index > -1) { section = sectionBase + "\\" + entry.Substring(0, split_index); entry = entry.Substring(split_index + 1); } Type t = e.ObjectType; if( typeof(string) == t ) UnsafeNativeMethods.CRhinoProfileContext_SaveProfileString(pProfileContext, section, entry, e.Value as string); else if( typeof(Guid) == t ) UnsafeNativeMethods.CRhinoProfileContext_SaveProfileUuid(pProfileContext, section, entry, (Guid)e.Value); else if( typeof(System.Drawing.Color) == t ) { System.Drawing.Color c = (System.Drawing.Color)e.Value; int argb = c.ToArgb(); UnsafeNativeMethods.CRhinoProfileContext_SaveProfileColor(pProfileContext, section, entry, argb); } else if( typeof(int) == t ) UnsafeNativeMethods.CRhinoProfileContext_SaveProfileInt(pProfileContext, section, entry, (int)e.Value); else if( typeof(double) == t ) UnsafeNativeMethods.CRhinoProfileContext_SaveProfileDouble(pProfileContext, section, entry, (double)e.Value); else if( typeof(System.Drawing.Rectangle) == t ) { System.Drawing.Rectangle r = (System.Drawing.Rectangle)e.Value; UnsafeNativeMethods.CRhinoProfileContext_SaveProfileRect(pProfileContext, section, entry, r.Left, r.Top, r.Right, r.Bottom); } else if( typeof(System.Drawing.Point) == t ) { System.Drawing.Point pt = (System.Drawing.Point)e.Value; UnsafeNativeMethods.CRhinoProfileContext_SaveProfilePoint(pProfileContext, section, entry, pt.X, pt.Y); } else if( typeof(Rhino.Geometry.Point3d) == t ) { Rhino.Geometry.Point3d pt = (Rhino.Geometry.Point3d)e.Value; UnsafeNativeMethods.CRhinoProfileContext_SaveProfilePoint3d(pProfileContext, section, entry, pt); } else if( typeof(Rhino.Geometry.Transform) == t ) { Rhino.Geometry.Transform xf = (Rhino.Geometry.Transform)e.Value; UnsafeNativeMethods.CRhinoProfileContext_SaveProfileXform(pProfileContext, section, entry, ref xf); } else if( typeof(Rhino.Geometry.Vector3d) == t ) { Rhino.Geometry.Vector3d v = (Rhino.Geometry.Vector3d)e.Value; UnsafeNativeMethods.CRhinoProfileContext_SaveProfileVector3d(pProfileContext, section, entry, v); } else if( typeof(Rhino.Geometry.MeshingParameters) == t ) { Rhino.Geometry.MeshingParameters mp = e.Value as Rhino.Geometry.MeshingParameters; if (mp != null) { IntPtr pMp = mp.ConstPointer(); UnsafeNativeMethods.CRhinoProfileContext_SaveProfileMeshingParameters(pProfileContext, section, entry, pMp); } } else if( typeof(byte[]) == t ) { byte[] b = e.Value as byte[]; if (b != null) { UnsafeNativeMethods.CRhinoProfileContext_SaveProfileBuffer(pProfileContext, section, entry, b.Length, b); } } else if (typeof(bool) == t) UnsafeNativeMethods.CRhinoProfileContext_SaveProfileBool(pProfileContext, section, entry, (bool)e.Value); else { //try //{ string s = info.GetString(e.Name); UnsafeNativeMethods.CRhinoProfileContext_SaveProfileString(pProfileContext, section, entry, s); //} //catch (Exception ex) //{ // throw; //} } } return pProfileContext; }