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


C# PHP类代码示例

本文整理汇总了C#中PHP的典型用法代码示例。如果您正苦于以下问题:C# PHP类的具体用法?C# PHP怎么用?C# PHP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Apply

        public static int Apply(ScriptContext/*!*/context, PHP.Core.Reflection.DTypeDesc caller, Iterator/*!*/iterator, PhpCallback function, PhpArray args)
        {
            // check parameters:
            Debug.Assert(context != null);
            Debug.Assert(iterator != null, "Phalanger should not pass a null here.");

            if (function == null)
            {
                PhpException.ArgumentNull("function");
                return -1;
            }

            // copy args into object array:
            object[] args_array;

            if (args != null)
            {
                args_array = new object[args.Count];
                args.Values.CopyTo(args_array, 0);
            }
            else
            {
                args_array = ArrayUtils.EmptyObjects;
            }

            // iterate through the iterator:
            int n = 0;
            
            iterator.rewind(context);
            
            while (PHP.Core.Convert.ObjectToBoolean(iterator.valid(context)))
            {
                if (!PHP.Core.Convert.ObjectToBoolean(function.Invoke(caller, args_array)))
                    break;
		        n++;

		        iterator.next(context);
	        }

            // return amount of iterated elements:
            return n;
        }
开发者ID:hansdude,项目名称:Phalanger,代码行数:42,代码来源:Iterators.cs

示例2: EmitMethodCall

        /// <summary>
        /// Emit call of the instance/static method. This defines the call site and call it using given parameters.
        /// </summary>
        /// <param name="cg">Current code <see cref="CodeGenerator"/>.</param>
        /// <param name="returnType">Return type of the method call determined by current access of the method call.</param>
        /// <param name="targetExpr">The method call instance expression (the target) if it is an instance method call.</param>
        /// <param name="targetType">The target type if it is a static method call.</param>
        /// <param name="methodFullName">If known at compile time, the method name. Otherwise <c>null</c>.</param>
        /// <param name="methodNameExpr">If the <paramref name="methodFullName"/> is null, this will be the expression giving the method name in run time.</param>
        /// <param name="callSignature">The call signature of the method call.</param>
        /// <returns>The resulting value type code. This value will be pushed onto the evaluation stack.</returns>
        public PhpTypeCode EmitMethodCall(
            PHP.Core.CodeGenerator/*!*/cg, Type returnType,
            Expression/*!*/targetExpr, DType/*!*/targetType,
            string methodFullName, Expression methodNameExpr, CallSignature callSignature)
        {
            Debug.Assert(methodFullName != null ^ methodNameExpr != null);          

            //
            bool staticCall = (targetExpr == null); // we are going to emit static method call
            //bool methodNameIsKnown = (methodFullName != null);
            //bool classContextIsKnown = (this.classContextPlace != null);

            //
            // define the call site:
            //
            var delegateType = /*System.Linq.Expressions.Expression.*/delegateBuilder.GetDelegateType(
                MethodCallDelegateTypeArgs(
                    callSignature,
                    staticCall ? Types.DObject[0] : Types.Object[0],
                    MethodCallDelegateAdditionalArguments(staticCall, methodFullName != null, this.classContextPlace != null),
                    returnType),
                callSitesCount);    // (J) do not create dynamic delegates in dynamic modules, so they can be referenced from non-transient assemblies

            //
            var field = DefineCallSite(cg.IL, string.Format("call_{0}", methodFullName ?? "$"), delegateType, (il) =>
            {
                // <LOAD> Binder.{MethodCall|StaticMethodCall}( methodFullName, genericParamsCount, paramsCount, classContext, <returnType> )
                if (methodFullName != null) il.Emit(OpCodes.Ldstr, methodFullName); else il.Emit(OpCodes.Ldnull);
                il.LdcI4(callSignature.GenericParams.Count);
                il.LdcI4(callSignature.Parameters.Count);
                if (this.classContextPlace != null) this.classContextPlace.EmitLoad(il); else il.Emit(OpCodes.Ldsfld, Fields.UnknownTypeDesc.Singleton);

                il.Emit(OpCodes.Ldtoken, returnType);
                il.Emit(OpCodes.Call, Methods.GetTypeFromHandle);
                
                il.Emit(OpCodes.Call, staticCall ? Methods.Binder.StaticMethodCall : Methods.Binder.MethodCall);
            });

            //
            // call the CallSite:
            //

            // <field>.Target( <field>, <targetExpr|self>, <scriptContext>, <callSignature.EmitLoadOnEvalStack>, <targetType>?, (classContext)?, <methodNameExpr>? ):

            cg.IL.Emit(OpCodes.Ldsfld, field);
            cg.IL.Emit(OpCodes.Ldfld, field.FieldType.GetField("Target"));
            cg.IL.Emit(OpCodes.Ldsfld, field);
            if (staticCall) cg.EmitLoadSelf(); else EmitMethodTargetExpr(cg, targetExpr);
            cg.EmitLoadScriptContext();
            EmitMethodCallParameters(cg, callSignature);
            if (staticCall) targetType.EmitLoadTypeDesc(cg, ResolveTypeFlags.UseAutoload | ResolveTypeFlags.ThrowErrors);
            if (/*!classContextIsKnown*/this.classContextPlace == null) cg.EmitLoadClassContext();
            if (/*!methodNameIsKnown*/methodFullName == null) cg.EmitName(methodFullName/*null*/, methodNameExpr, true);
            
            cg.MarkTransientSequencePoint();
            cg.IL.Emit(OpCodes.Callvirt, delegateType.GetMethod("Invoke"));
            
            cg.MarkTransientSequencePoint();
            
            //
            return PhpTypeCodeEnum.FromType(returnType);
        }
开发者ID:Ashod,项目名称:Phalanger,代码行数:73,代码来源:CallSitesBuilder.cs

示例3: GetInlinedLambdaCodeFill

        /// <summary>
        /// Gets a string which is used as a fill in the code to be parsed in order to maintain
        /// correct token positioning.
        /// </summary>
        /// <param name="args">A position of string literal holding source code for lambda function arguments.</param>
        /// <param name="body">A position of string literal holding source code for the body.</param>
        /// <returns>A string containing spaces and end-of-line characters '\n'.</returns>
        private static string GetInlinedLambdaCodeFill(PHP.Core.Parsers.Position args, PHP.Core.Parsers.Position body)
        {
            int delta_lines = body.FirstLine - args.LastLine;

            if (delta_lines == 0)
            {
                // ....args.......'_____,_______________'.......body.....
                // ...............)_________fill________{................
                return new String(' ', body.FirstColumn - args.LastColumn - 1);
            }
            else
            {
                // source:
                // .....args.....'_____\r\n
                // _________,_____\r\n
                // ____________'......body..... 

                // code to parse:
                // .....args....'\n
                // \n
                // ____fill____{.....body......

                // the same number of lines as it is in the source file + leading columns:
                return new System.Text.StringBuilder(delta_lines + body.FirstColumn).
                  Append('\n', delta_lines).Append(' ', body.FirstColumn).ToString();
            }
        }
开发者ID:kripper,项目名称:Phalanger,代码行数:34,代码来源:Functions.cs

示例4: Filter

		public static PhpArray Filter(PHP.Core.Reflection.DTypeDesc caller, PhpArray array, PhpCallback callback)
		{
			if (callback == null) { PhpException.ArgumentNull("callback"); return null; }
			if (array == null) { PhpException.ArgumentNull("array"); return null; }

			PhpArray result = new PhpArray();
			object[] args = new object[1];

			foreach (KeyValuePair<IntStringKey, object> entry in array)
			{
				// no deep copying needed because it is done so in callback:
				args[0] = entry.Value;

				// adds entry to the resulting array if callback returns true:
                if (Core.Convert.ObjectToBoolean(callback.Invoke(caller, args)))
				{
					result.Add(entry.Key, entry.Value);
				}
			}

			// values should be inplace deeply copied:
			result.InplaceCopyOnReturn = true;
			return result;
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:24,代码来源:Arrays.cs

示例5: VisitEntryOnWalk

		/// <summary>
		/// Visits an entyr of array which <see cref="Walk"/> or <see cref="WalkRecursive"/> is walking through.
		/// </summary>
		private static void VisitEntryOnWalk(PHP.Core.Reflection.DTypeDesc caller, KeyValuePair<IntStringKey, object> entry, IDictionary<IntStringKey, object> array,
			PhpCallback callback, object[] args)
		{
			PhpReference ref_item = entry.Value as PhpReference;

			// fills arguments for the callback:
			((PhpReference)args[0]).Value = (ref_item != null) ? ref_item.Value : entry.Value;
			args[1] = entry.Key.Object;

			// invoke callback:
            Core.Convert.ObjectToBoolean(callback.Invoke(caller, args));

			// loads a new value from a reference:
			if (ref_item != null)
			{
				ref_item.Value = ((PhpReference)args[0]).Value;
			}
			else
			{
				array[entry.Key] = ((PhpReference)args[0]).Value;
			}
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:25,代码来源:Arrays.cs

示例6: WalkRecursive

		public static bool WalkRecursive(PHP.Core.Reflection.DTypeDesc caller, [PhpRw] PhpHashtable array, PhpCallback callback)
		{
			return WalkRecursive(caller, array, callback, null);
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:4,代码来源:Arrays.cs

示例7: Walk

        public static bool Walk(PHP.Core.Reflection.DTypeDesc caller, [PhpRw] PhpHashtable array, PhpCallback function)
		{
			return Walk(caller, array, function, null);
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:4,代码来源:Arrays.cs

示例8: Reduce

        public static object Reduce(PHP.Core.Reflection.DTypeDesc caller, [PhpRw] PhpArray array, PhpCallback function)
		{
			return Reduce(caller, array, function, null);
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:4,代码来源:Arrays.cs

示例9: IsCallable

		public static bool IsCallable(PHP.Core.Reflection.DTypeDesc caller, object variable)
		{
			return IsCallable(caller, variable, false);
		}
开发者ID:hansdude,项目名称:Phalanger,代码行数:4,代码来源:Variables.cs

示例10: CreateLiteral

 public PHP.Core.AST.Literal CreateLiteral(PHP.Core.Parsers.Position position)
 {
     if (IsBinary)
         return new PHP.Core.AST.BinaryStringLiteral(position, new PhpBytes(BinaryBuilder.ToArray()));
     else
         return new PHP.Core.AST.StringLiteral(position, UnicodeBuilder.ToString());
 }
开发者ID:hansdude,项目名称:Phalanger,代码行数:7,代码来源:Lexer.cs

示例11: Unserialize

        public static PhpReference Unserialize(PHP.Core.Reflection.DTypeDesc caller, PhpBytes bytes)
		{
            LibraryConfiguration config = LibraryConfiguration.GetLocal(ScriptContext.CurrentContext);

            return config.Serialization.DefaultSerializer.Deserialize(bytes, caller);
		}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:6,代码来源:Variables.cs

示例12: GetStubParameterTypes

		private static object[] GetStubParameterTypes(
			int paramCount,
			int typeParamCount,
			PhpRoutineSignature/*!*/ signature,
			PHP.Core.AST.FormalTypeParam[]/*!*/ formalTypeParams)
		{
			object[] parameter_types = new object[paramCount];
			for (int i = 0; i < paramCount; i++)
			{
				DType type_hint = signature.TypeHints[i];
				if (type_hint != null && !type_hint.IsUnknown)
				{
					GenericParameter gen_type_hint = type_hint as GenericParameter;
					if (gen_type_hint != null)
					{
						// this is a generic parameter - declared by either the method or type
						if (gen_type_hint.DeclaringMember is PhpRoutine)
						{
							if (gen_type_hint.Index < typeParamCount)
							{
								// unknown at this point - fixed-up later
								parameter_types[i] = gen_type_hint.Index;
							}
							else
							{
								// default generic parameter
                                var typeparam = formalTypeParams[gen_type_hint.Index].DefaultType;
                                
                                DType default_type = typeparam as DType;
                                if (default_type == null && typeparam is GenericQualifiedName)
                                    default_type = PrimitiveType.GetByName((GenericQualifiedName)typeparam);

								parameter_types[i] = (default_type == null ? Types.Object[0] : default_type.RealType);
							}
						}
						else parameter_types[i] = gen_type_hint.RealGenericTypeParameterBuilder;
					}
					else parameter_types[i] = type_hint.RealType;
				}
				else parameter_types[i] = Types.Object[0];

				// make it byref if declared with &
				if (signature.AliasMask[i])
				{
					Type type = parameter_types[i] as Type;
					if (type != null) parameter_types[i] = type.MakeByRefType();
					else parameter_types[i] = -((int)parameter_types[i] + 1);
				}

				Debug.Assert(parameter_types[i] != null);
			}

			return parameter_types;
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:54,代码来源:ClrStubBuilder.cs

示例13: DefineStubParameters

		/// <summary>
		/// Sets attributes of generated override/implement/export stub parameters.
		/// </summary>
		/// <param name="stub">The stub constructor builder.
		/// </param>
		/// <param name="formalParams">Formal parameters of the implementing PHP method.</param>
		/// <param name="templateParams">Parameters of the overload being overriden/implemented/exported.</param>
		public static void DefineStubParameters(ConstructorBuilder/*!*/ stub,
			PHP.Core.AST.FormalParam[] formalParams, ParameterInfo[]/*!*/ templateParams)
		{
			for (int i = 0; i < templateParams.Length; i++)
			{
				string name;

				// take the overriding parameter name if available
				if (formalParams != null && i < formalParams.Length) name = formalParams[i].Name.ToString();
				else name = templateParams[i].Name;

				stub.DefineParameter(i + 1, templateParams[i].Attributes, name);
			}
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:21,代码来源:ClrStubBuilder.cs

示例14: EmitGetProperty

        /// <summary>
        /// Create and call <see cref="CallSite"/> for getting property.
        /// </summary>
        /// <param name="cg"><see cref="CodeGenerator"/>.</param>
        /// <param name="wantRef">Wheter <see cref="PhpReference"/> is expected as the result.</param>
        /// <param name="targetExpr">The expression representing the target (object).</param>
        /// <param name="targetObjectPlace">The place representing the target (<see cref="DObject"/>) iff <paramref name="targetExpr"/> is not provided.</param>
        /// <param name="targetPlace">The place representing the target (object) iff <paramref name="targetExpr"/> and <paramref name="targetObjectPlace"/> are not provided.</param>
        /// <param name="targetType">Type of target iff we are getting property statically.</param>
        /// <param name="fieldName">The name of the field. Can be null if the name is not known at compile time (indirect).</param>
        /// <param name="fieldNameExpr">The expression used to get field name in run time (iff <paramref name="fieldName"/> is <c>null</c>.</param>
        /// <param name="issetSemantics">Wheter we are only checking if the property exists. If true, no warnings are thrown during run time.</param>
        /// <returns>Type code of the value that is pushed onto the top of the evaluation stack.</returns>
        public PhpTypeCode EmitGetProperty(
            PHP.Core.CodeGenerator/*!*/cg, bool wantRef,
            Expression targetExpr, IPlace targetObjectPlace, IPlace targetPlace, DType targetType,
            string fieldName, Expression fieldNameExpr,
            bool issetSemantics)
        {
            Debug.Assert(fieldName != null ^ fieldNameExpr != null);
            Debug.Assert(targetExpr != null || targetObjectPlace != null || targetPlace != null || targetType != null);
            
            //
            bool staticCall = (targetExpr == null && targetObjectPlace == null && targetPlace == null); // we are going to access static property
            bool fieldNameIsKnown = (fieldName != null);
            bool classContextIsKnown = (this.classContextPlace != null);

            //
            // binder flags:
            //
            Type returnType = wantRef ? Types.PhpReference[0] : Types.Object[0];
            
            //
            // define the call site:
            //

            //
            List<Type> additionalArgs = new List<Type>();
            if (!classContextIsKnown) additionalArgs.Add(Types.DTypeDesc[0]);
            if (!fieldNameIsKnown) additionalArgs.Add(Types.String[0]);

            var delegateTypeArgs = GetPropertyDelegateTypeArgs(
                staticCall ? Types.DTypeDesc[0] : ((targetObjectPlace != null) ? Types.DObject[0] : Types.Object[0]),   // DTypeDesc of static field's declaring type || DObject if field called on DObject known at compile time || otherwise object
                additionalArgs.ToArray(),
                returnType);

            var delegateType = /*System.Linq.Expressions.Expression.*/delegateBuilder.GetDelegateType(delegateTypeArgs, callSitesCount);    // (J) do not create dynamic delegates in dynamic modules, so they can be referenced from non-transient assemblies

            //
            var field = DefineCallSite(cg.IL, string.Format("get{0}_{1}", wantRef ? "ref" : string.Empty, fieldName ?? "$"), delegateType, (il) =>
            {
                // <LOAD> Binder.{GetProperty|GetStaticProperty}( fieldName, classContext, issetSemantics, <returnType> )
                if (fieldName != null) il.Emit(OpCodes.Ldstr, fieldName); else il.Emit(OpCodes.Ldnull);
                if (this.classContextPlace != null) this.classContextPlace.EmitLoad(il); else il.Emit(OpCodes.Ldsfld, Fields.UnknownTypeDesc.Singleton);
                il.LoadBool(issetSemantics);

                il.Emit(OpCodes.Ldtoken, returnType);
                il.Emit(OpCodes.Call, Methods.GetTypeFromHandle);

                il.Emit(OpCodes.Call, staticCall ? Methods.Binder.StaticGetProperty : Methods.Binder.GetProperty);
            });

            //
            // call the CallSite:
            //

            // <field>.Target( <field>, <targetExpr|targetType>, (classContext)?, <methodNameExpr>? ):

            cg.IL.Emit(OpCodes.Ldsfld, field);
            cg.IL.Emit(OpCodes.Ldfld, field.FieldType.GetField("Target"));
            cg.IL.Emit(OpCodes.Ldsfld, field);
            if (staticCall) targetType.EmitLoadTypeDesc(cg, ResolveTypeFlags.UseAutoload | ResolveTypeFlags.ThrowErrors);
            else if (targetExpr != null)
            {
                cg.ChainBuilder.Lengthen(); // for hop over ->
                cg.EmitBoxing(targetExpr.Emit(cg)); // prepare for operator invocation
            }
            else if (targetObjectPlace != null) targetObjectPlace.EmitLoad(cg.IL);
            else if (targetPlace != null) targetPlace.EmitLoad(cg.IL);
            else Debug.Fail();
            if (!classContextIsKnown) cg.EmitLoadClassContext();
            if (!fieldNameIsKnown) cg.EmitName(fieldName/*null*/, fieldNameExpr, true, PhpTypeCode.String);

            cg.MarkTransientSequencePoint();
            cg.IL.Emit(OpCodes.Callvirt, delegateType.GetMethod("Invoke"));

            cg.MarkTransientSequencePoint();
            
            //
            return PhpTypeCodeEnum.FromType(returnType);
        }
开发者ID:Ashod,项目名称:Phalanger,代码行数:91,代码来源:CallSitesBuilder.cs

示例15: EmitMethodTargetExpr

        /// <summary>
        /// Emit the target of instance method invocation.
        /// </summary>
        /// <param name="cg"></param>
        /// <param name="targetExpr"></param>
        private static void EmitMethodTargetExpr(PHP.Core.CodeGenerator/*!*/cg, Expression/*!*/targetExpr)
        {
            // start a new operators chain (as the rest of chain is read)
            cg.ChainBuilder.Create();
            cg.ChainBuilder.Begin();
            cg.ChainBuilder.Lengthen(); // for hop over ->

            // prepare for operator invocation
            cg.EmitBoxing(targetExpr.Emit(cg));
            cg.ChainBuilder.End();
        }
开发者ID:Ashod,项目名称:Phalanger,代码行数:16,代码来源:CallSitesBuilder.cs


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