예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dsObject"></param>
        /// <returns></returns>
        public override string GetStringValue(StackValue dsObject)
        {
            object clrObject = null;

            if (!DSObjectMap.TryGetValue(dsObject, out clrObject))
            {
                return(string.Empty);
            }

            if (clrObject != null)
            {
                if (!DumpXmlProperties)
                {
                    return(clrObject.ToString());
                }
                else
                {
                    XmlWriterSettings settings = new XmlWriterSettings {
                        Indent = false, OmitXmlDeclaration = true
                    };
                    using (StringWriter sw = new StringWriter())
                    {
                        using (XmlWriter xw = XmlTextWriter.Create(sw, settings))
                        {
                            GeneratePrimaryPropertiesAsXml(clrObject, xw);
                        }
                        return(sw.ToString());
                    }
                }
            }
            else
            {
                return(string.Empty);
            }
        }
예제 #2
0
        /// <summary>
        /// Dispose event handler.
        /// </summary>
        /// <param name="sender">Core object being disposed.</param>
        void core_Dispose(ProtoCore.Core sender)
        {
            CLRObjectMarshler marshaller = null;

            if (!mObjectMarshlers.TryGetValue(sender, out marshaller))
            {
                throw new KeyNotFoundException();
            }

            mObjectMarshlers.Remove(sender);

            //Detach from core.
            sender.Dispose -= core_Dispose;

            //Dispose all disposable CLR objects.
            foreach (var item in DSObjectMap)
            {
                IDisposable disposable = item.Value as IDisposable;
                sender.FFIPropertyChangedMonitor.RemoveFFIObject(item.Value);

                if (null != disposable)
                {
                    disposable.Dispose();
                }
            }

            //Clear the maps.
            DSObjectMap.Clear();
            CLRObjectMap.Clear();
        }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dsObject"></param>
 /// <param name="context"></param>
 /// <param name="dsi"></param>
 public override void OnDispose(StackValue dsObject, ProtoCore.Runtime.Context context, Interpreter dsi)
 {
     lock (DSObjectMap)
     {
         Object clrobject;
         if (DSObjectMap.TryGetValue(dsObject, out clrobject))
         {
             DSObjectMap.Remove(dsObject);
             CLRObjectMap.Remove(clrobject);
             dsi.runtime.Core.FFIPropertyChangedMonitor.RemoveFFIObject(clrobject);
         }
     }
 }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="dsobj"></param>
        private void BindObjects(object obj, StackValue dsobj)
        {
#if DEBUG
            if (DSObjectMap.ContainsKey(dsobj))
            {
                throw new InvalidOperationException("Object reference already mapped");
            }

            if (CLRObjectMap.ContainsKey(obj))
            {
                throw new InvalidOperationException("Object reference already mapped");
            }
#endif
            lock (DSObjectMap)
            {
                DSObjectMap[dsobj] = obj;
                CLRObjectMap[obj]  = dsobj;
            }
        }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dsObject"></param>
        /// <param name="context"></param>
        /// <param name="dsi"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public override object UnMarshal(StackValue dsObject, ProtoCore.Runtime.Context context, Interpreter dsi, System.Type type)
        {
            object clrObject = null;

            switch (dsObject.optype)
            {
            case AddressType.ArrayPointer:
            {
                if (type.IsArray || type == typeof(object))
                {
                    return(ConvertDSArrayToCSArray(dsObject, context, dsi, type));
                }
                if (typeof(System.Collections.ICollection).IsAssignableFrom(type))
                {
                    Type   arrayType = type.GetGenericArguments()[0].MakeArrayType();
                    object arr       = ConvertDSArrayToCSArray(dsObject, context, dsi, arrayType);
                    return(Activator.CreateInstance(type, new[] { arr }));        //Create the collection using
                }
                else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(type))
                {
                    Type   arrayType = type.GetGenericArguments()[0].MakeArrayType();
                    object arr       = ConvertDSArrayToCSArray(dsObject, context, dsi, arrayType);
                    return(arr);

/*
 *                          Type genericType = type.GetGenericArguments()[0];
 *                          return ConvertDSArrayToCSList(dsObject, context, dsi, genericType);
 *
 *                          Type listType = typeof(List<>).MakeGenericType(genericType);
 *                          var list = Activator.CreateInstance(listType);
 *                          listType.GetMethod("AddRange").Invoke(list, new object[]{arr});
 *                          return list;
 */
                }
                break;
            }

            case AddressType.Int:
            case AddressType.Double:
            case AddressType.Boolean:
            case AddressType.Char:
            case AddressType.String:
            {
                clrObject = TryGetPrimitiveObject(dsObject, context, dsi, type);
                break;
            }

            case AddressType.Null:
            {
                return(null);
            }

            case AddressType.Pointer:
            {
                DSObjectMap.TryGetValue(dsObject, out clrObject);
                break;
            }

            default:
            {
                throw new NotSupportedException(string.Format("Operand type {0} not supported for marshalling", dsObject.optype));
            }
            }

            if (null != clrObject)
            {
                return(clrObject);
            }

            return(CreateCLRObject(dsObject, context, dsi, type));
        }