当前位置: 首页>>代码示例>>C#>>正文


C# DObject.InvokeMethod方法代码示例

本文整理汇总了C#中DObject.InvokeMethod方法的典型用法代码示例。如果您正苦于以下问题:C# DObject.InvokeMethod方法的具体用法?C# DObject.InvokeMethod怎么用?C# DObject.InvokeMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DObject的用法示例。


在下文中一共展示了DObject.InvokeMethod方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WritePhpObjectInternal

            /// <summary>
            /// Serializes <see cref="DObject"/> using PHP serialization.
            /// </summary>
            /// <param name="value">The object.</param>
            private void WritePhpObjectInternal(DObject/*!*/value)
            {
                byte[] binaryClassName;

                // determine class name
                bool avoid_pic_name = false;
                string class_name = null;
                __PHP_Incomplete_Class pic = value as __PHP_Incomplete_Class;
                if (pic != null)
                {
                    if (pic.__PHP_Incomplete_Class_Name.IsSet)
                    {
                        avoid_pic_name = true;
                        class_name = pic.__PHP_Incomplete_Class_Name.Value as string;
                    }
                }
                if (value is stdClass) class_name = stdClass.ClassName;
                if (class_name == null) class_name = value.TypeName;

                // is the instance PHP5.1 Serializable?
                if (value.RealObject is Library.SPL.Serializable)
                {
                    context.Stack.AddFrame();
                    object res = PhpVariable.Dereference(value.InvokeMethod("serialize", null, context));
                    if (res == null)
                    {
                        // serialize returned NULL -> serialize the instance as NULL
                        WriteNull();
                        return;
                    }

                    byte[] resdata = null;

                    if (res is PhpString)
                    {
                        res = res.ToString();
                    }

                    if (res is string)
                    {
                        resdata = writer.Encoding.GetBytes((string)res);
                    }
                    else if (res is PhpBytes)
                    {
                        resdata = ((PhpBytes)res).ReadonlyData;
                    }

                    if (resdata == null)
                    {
                        // serialize did not return NULL nor a string -> throw an exception
                        SPL.Exception.ThrowSplException(
                            _ctx => new SPL.Exception(_ctx, true),
                            context,
                            string.Format(CoreResources.serialize_must_return_null_or_string, value.TypeName), 0, null);
                    }

                    writer.Write(Tokens.ObjectSer);
                    writer.Write(Tokens.Colon);

                    binaryClassName = writer.Encoding.GetBytes(class_name);

                    // write out class name
                    writer.Write(binaryClassName.Length);
                    writer.Write(Tokens.Colon);
                    writer.Write(Tokens.Quote);

                    // flush the StreamWriter before accessing its underlying stream
                    writer.Flush();

                    writer.BaseStream.Write(binaryClassName, 0, binaryClassName.Length);
                    writer.Write(Tokens.Quote);
                    writer.Write(Tokens.Colon);

                    // write out the result of serialize
                    writer.Write(resdata.Length);
                    writer.Write(Tokens.Colon);
                    writer.Write(Tokens.BraceOpen);

                    // flush the StreamWriter before accessing its underlying stream
                    writer.Flush();

                    writer.BaseStream.Write(resdata, 0, resdata.Length);
                    writer.Write(Tokens.BraceClose);
                    return;
                }

                // try to call the __sleep method
                bool sleep_called;
                PhpArray ser_props = value.Sleep(ClassContext, context, out sleep_called);

                if (sleep_called && ser_props == null)
                {
                    // __sleep did not return an array -> serialize the instance as NULL
                    WriteNull();
                    return;
                }
//.........这里部分代码省略.........
开发者ID:hansdude,项目名称:Phalanger,代码行数:101,代码来源:PhpFormatter.CLR.cs

示例2: BuildDObject

			/// <summary>
			/// Builds a <see cref="DObject"/> from atoms (the object itself given as parameter).
			/// </summary>
			/// <param name="obj">The instance.</param>
			private void BuildDObject(DObject obj)
			{
				bool serializable = ((bool)atoms[atomCounter++] == true);

				if (serializable && obj.RealObject is Library.SPL.Serializable)
				{
					// pass the serialized data to unserialize
					context.Stack.AddFrame(BuildObjectGraph());
					obj.InvokeMethod("unserialize", null, context);
					return;
				}

				while (atoms[atomCounter] != delimiter)
				{
					string property_name = (string)BuildObjectGraph();
					object property_value = BuildObjectGraph();

					Debug.Assert(property_name != null);
					Serialization.SetProperty(obj, property_name, property_value, context);
				}
				atomCounter++; // for the delimiter

				// invoke __wakeup on the deserialized instance
				obj.Wakeup(ClassContext, context);
			}
开发者ID:hansdude,项目名称:Phalanger,代码行数:29,代码来源:PhpFormatter.CLR.cs

示例3: GetUserArrayItemRef

		/// <summary>
		/// Gets an item of a user array by invoking <see cref="Library.SPL.ArrayAccess.offsetGet"/>.
		/// </summary>
		/// <param name="arrayAccess">User array object.</param>
		/// <param name="index">An index.</param>
		/// <param name="context">The current script context.</param>
		/// <returns>A reference on item returned by the user getter.</returns>
		internal static PhpReference GetUserArrayItemRef(DObject/*!*/ arrayAccess, object index, ScriptContext/*!*/ context)
		{
			Debug.Assert(arrayAccess.RealObject is Library.SPL.ArrayAccess);
			Debug.Assert(!(index is PhpReference));

			context.Stack.AddFrame(index);
			object result = arrayAccess.InvokeMethod(Library.SPL.PhpArrayObject.offsetGet, null, context);
			PhpReference ref_result = result as PhpReference;
			if (ref_result == null)
			{
				// obsolete (?): PhpException.Throw(PhpError.Error,CoreResources.GetString("offsetGet_must_return_byref"));
				ref_result = new PhpReference(result);
			}
			return ref_result;
		}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:22,代码来源:ArrayAccess.cs

示例4: GetObjectData

        new public static void GetObjectData(DObject/*!*/ instance, SerializationInfo/*!*/ info, StreamingContext strctx)
		{
			info.SetType(typeof(SPLDeserializer));

			SerializationContext context = SerializationContext.CreateFromStreamingContext(strctx);

			object res = PhpVariable.Dereference(instance.InvokeMethod("serialize", null, context.ScriptContext));
			if (res == null)
			{
				// serialize returned NULL -> this instance will deserialize as NULL
				info.AddValue(__PHP_Incomplete_Class.ClassNameFieldName, String.Empty);
			}
			else
			{
				string res_str = PhpVariable.AsString(res);
				if (res_str == null)
				{
					// serialize did not return NULL nor a string -> throw an exception
                    Library.SPL.Exception.ThrowSplException(
                        _ctx => new Library.SPL.Exception(_ctx, true),
                        context.ScriptContext,
                        string.Format(CoreResources.serialize_must_return_null_or_string, instance.TypeName), 0, null);
				}

				info.AddValue(SerializedDataFieldName, res_str);
				info.AddValue(__PHP_Incomplete_Class.ClassNameFieldName, instance.TypeName);
			}
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:28,代码来源:Serialization.CLR.cs

示例5: GetUserArrayItem

		internal static object GetUserArrayItem(DObject/*!*/ arrayAccess, object index, Operators.GetItemKinds kind)
		{
			PhpStack stack = ScriptContext.CurrentContext.Stack;

			switch (kind)
			{
				case Operators.GetItemKinds.Isset:
					// pass isset() ""/null to say true/false depending on the value returned from "offsetExists": 
					stack.AddFrame(index);
					return Core.Convert.ObjectToBoolean(arrayAccess.InvokeMethod(offsetExists, null, stack.Context)) ? "" : null;

				case Operators.GetItemKinds.Empty:
					// if "offsetExists" returns false, the empty()/isset() returns false (pass null to say true/false): 
					// otherwise, "offsetGet" is called to retrieve the value, which is passed to isset():
					stack.AddFrame(index);
					if (!Core.Convert.ObjectToBoolean(arrayAccess.InvokeMethod(offsetExists, null, stack.Context)))
						return null;
					else
						goto default;
				
				default:
					// regular getter:
					stack.AddFrame(index);
					return PhpVariable.Dereference(arrayAccess.InvokeMethod(offsetGet, null, stack.Context));
			}
			
		}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:27,代码来源:ArrayAccess.cs


注:本文中的DObject.InvokeMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。