예제 #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>
 ///
 /// </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);
         }
     }
 }
예제 #3
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));
        }