當前位置: 首頁>>代碼示例>>C#>>正文


C# ScriptContext.ResolveType方法代碼示例

本文整理匯總了C#中PHP.Core.ScriptContext.ResolveType方法的典型用法代碼示例。如果您正苦於以下問題:C# ScriptContext.ResolveType方法的具體用法?C# ScriptContext.ResolveType怎麽用?C# ScriptContext.ResolveType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PHP.Core.ScriptContext的用法示例。


在下文中一共展示了ScriptContext.ResolveType方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ResolveType

 /// <summary>
 /// Resolves the <paramref name="typeName"/> and provides corresponding <see cref="DTypeDesc"/> or <c>null</c> reference.
 /// </summary>
 private static DTypeDesc ResolveType(ScriptContext/*!*/context, string typeName)
 {
     return context.ResolveType(typeName, null, null, null, ResolveTypeFlags.ThrowErrors | ResolveTypeFlags.UseAutoload);
 }
開發者ID:hansdude,項目名稱:Phalanger,代碼行數:7,代碼來源:ReflectionClass.cs

示例2: __construct

        public virtual object __construct(ScriptContext/*!*/context, object/*Traversable*/ iterator, [Optional]object classname)
        {
            this.iterator = iterator as DObject;    // iterator.RealObject is Traversable ?
            if (this.iterator != null)
            {
                if (classname != null && classname != Arg.Default &&
                    !(this.iterator.RealObject is SPL.Iterator)    // downcast only if it is not an Iterator instance
                    )
                {
                    var downcast = context.ResolveType(PhpVariable.AsString(classname), null, this.iterator.TypeDesc, null, ResolveTypeFlags.ThrowErrors);

                    if (downcast == null || // not found
                        !downcast.IsAssignableFrom(this.iterator.TypeDesc) ||    // not base
                        !DTypeDesc.Create(typeof(Traversable)).IsAssignableFrom(downcast))   // not Traversable
                    {
                        // TODO: error
                        // zend_throw_exception(spl_ce_LogicException, "Class to downcast to not found or not base class or does not implement Traversable", 0 TSRMLS_CC);

                        this.iterator = null;
                    }
                    else
                    {
                        //if (DTypeDesc.Create(typeof(IteratorAggregate)).IsAssignableFrom(downcast))
                        //{
                        //    // {downcast} is IteratorAggregate
                        //    context.Stack.AddFrame();
                        //    var result = this.iterator.InvokeMethod("getIterator", null, context);

                        //    if (result == null || !(result is DObject) || !(((DObject)result).RealObject is Traversable))
                        //    {
                        //        //zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "%s::getIterator() must return an object that implements Traversable", ce->name);
                        //        this.iterator = null;
                        //    }
                        //    else
                        //    {
                        //        this.iterator = (DObject)result;
                        //    }
                        //}
                        throw new NotImplementedException();
                    }
                }
            }
            else
            {
                // TODO: error
            }

            //rewind(context);  // not in PHP, performance reasons (foreach causes rewind() itself)

            return null;
        }
開發者ID:dw4dev,項目名稱:Phalanger,代碼行數:51,代碼來源:Iterators.cs

示例3: SetProperty

		/// <summary>
		/// Sets a property of a <see cref="DObject"/> instance according to deserialized name and value.
		/// </summary>
		/// <param name="instance">The instance being deserialized.</param>
		/// <param name="name">The property name formatted for serialization (see <see cref="FormatPropertyName"/>).</param>
		/// <param name="value">The property value.</param>
		/// <param name="context">Current <see cref="ScriptContext"/>.</param>
		public static void SetProperty(DObject/*!*/ instance, string/*!*/ name, object value, ScriptContext/*!*/ context)
		{
			// the property name might encode its visibility and "classification" -> use these
			// information for suitable property desc lookups
			PhpMemberAttributes visibility;
			string type_name;

			string property_name = ParsePropertyName(name, out type_name, out visibility);

			DTypeDesc declarer;
			if (type_name == null) declarer = instance.TypeDesc;
			else
			{
				declarer = context.ResolveType(type_name);
				if (declarer == null) declarer = instance.TypeDesc;
			}

			// try to find a suitable field handle
			DPropertyDesc property;
			if (instance.TypeDesc.GetProperty(new VariableName(property_name), declarer, out property) ==
				PHP.Core.Reflection.GetMemberResult.OK)
			{
				if ((property.IsPrivate &&
					declarer != property.DeclaringType))
				{
					// if certain conditions are met, don't use the handle even if it was found
					// (this is to precisely mimic the PHP behavior)
					property = null;
				}
			}
			else property = null;

			if (property != null) property.Set(instance, value);
			else
			{
				// suitable CT field not found -> add it to RT fields
				// (note: care must be taken so that the serialize(unserialize($x)) round
				// trip returns $x even if user classes specified in $x are not declared)
                if (instance.RuntimeFields == null) instance.RuntimeFields = new PhpArray();
				instance.RuntimeFields[name] = value;
			}
		}
開發者ID:hansdude,項目名稱:Phalanger,代碼行數:49,代碼來源:Serialization.cs

示例4: isSubclassOf

        public virtual object isSubclassOf(ScriptContext/*!*/context, object @class)
        {
            var classname = PhpVariable.AsString(@class);

            if (!string.IsNullOrEmpty(classname) && this.typedesc != null)
            {
                var dtype = context.ResolveType(classname, null, null, null, ResolveTypeFlags.ThrowErrors | ResolveTypeFlags.UseAutoload);
                return dtype != null && this.typedesc.IsAssignableFrom(dtype);
            }

            return false;
        }
開發者ID:hansdude,項目名稱:Phalanger,代碼行數:12,代碼來源:ReflectionClass.cs

示例5: EnumerateSerializableProperties

		/// <summary>
		/// Returns names and values of properties whose names have been returned by <c>__sleep</c>.
		/// </summary>
		/// <param name="instance">The instance being serialized.</param>
		/// <param name="sleepResult">The array returned by <c>__sleep</c>.</param>
		/// <param name="context">Current <see cref="ScriptContext"/>.</param>
		/// <returns>Name-value pairs. Names are properly formatted for serialization.</returns>
		/// <exception cref="PhpException">Property of the name returned from <c>__sleep</c> does not exist.</exception>
		/// <remarks>
		/// This method returns exactly <paramref name="sleepResult"/>'s <see cref="PhpHashtable.Count"/> items.
		/// </remarks>
		public static IEnumerable<KeyValuePair<string, object>> EnumerateSerializableProperties(
			DObject/*!*/ instance,
			PhpArray/*!*/ sleepResult,
			ScriptContext/*!*/ context)
		{
			foreach (object item in sleepResult.Values)
			{
				PhpMemberAttributes visibility;
				string name = PHP.Core.Convert.ObjectToString(item);
				string declaring_type_name;
				string property_name = ParsePropertyName(name, out declaring_type_name, out visibility);

				DTypeDesc declarer;
				if (declaring_type_name == null) declarer = instance.TypeDesc;
				else
				{
					declarer = context.ResolveType(declaring_type_name);
					if (declarer == null)
					{
						// property name refers to an unknown class -> value will be null
						yield return new KeyValuePair<string, object>(name, null);
						continue;
					}
				}

				// obtain the property desc and decorate the prop name according to its visibility and declaring class
				DPropertyDesc property;
				if (instance.TypeDesc.GetProperty(new VariableName(property_name), declarer, out property) ==
					GetMemberResult.OK && !property.IsStatic)
				{
					if ((Enums.VisibilityEquals(visibility, property.MemberAttributes) &&
						visibility != PhpMemberAttributes.Public)
						||
						(visibility == PhpMemberAttributes.Private &&
						declarer != property.DeclaringType))
					{
						// if certain conditions are met, serialize the property as null
						// (this is to precisely mimic the PHP behavior)
						yield return new KeyValuePair<string, object>(name, null);
						continue;
					}
					name = FormatPropertyName(property, property_name);
				}
				else property = null;

				// obtain the property value
				object val = null;

				if (property != null)
				{
					val = property.Get(instance);
				}
				else if (instance.RuntimeFields == null || !instance.RuntimeFields.TryGetValue(name, out val))
				{
					// this is new in PHP 5.1
					PhpException.Throw(PhpError.Notice, CoreResources.GetString("sleep_returned_bad_field", name));
				}

				yield return new KeyValuePair<string, object>(name, val);
			}
		}
開發者ID:hansdude,項目名稱:Phalanger,代碼行數:72,代碼來源:Serialization.cs

示例6: GetUninitializedInstance

		/// <summary>
		/// Returns an unitialized instance of the specified type or <see cref="__PHP_Incomplete_Class"/>.
		/// </summary>
		/// <param name="typeName">The type name.</param>
		/// <param name="context">Current <see cref="ScriptContext"/>.</param>
		/// <returns>The newly created instance or <B>null</B> if <paramref name="typeName"/> denotes
		/// a primitive type.</returns>
		/// <remarks>
		/// If the <paramref name="typeName"/> denotes a CLR type, no constructor is executed. If the
		/// <paramref name="typeName"/> denotes a PHP type, no user constructor (e.g. <c>__construct</c>)
		/// is executed.
		/// </remarks>
		public static DObject GetUninitializedInstance(string/*!*/ typeName, ScriptContext/*!*/ context)
		{
			// resolve the specified type
			DTypeDesc type = context.ResolveType(typeName);
			if (type == null || type.IsAbstract)
			{
				PhpCallback callback = context.Config.Variables.DeserializationCallback;
				if (callback != null && !callback.IsInvalid)
				{
					callback.Invoke(typeName);
					type = context.ResolveType(typeName);

					if (type == null || type.IsAbstract)
					{
						// unserialize_callback_func failed
						PhpException.Throw(PhpError.Warning, CoreResources.GetString("unserialize_callback_failed",
							((IPhpConvertible)callback).ToString()));
					}
				}
			}

			if (type == null || type.IsAbstract)
			{
				// type not found -> create __PHP_Incomplete_Class
				__PHP_Incomplete_Class pic = new __PHP_Incomplete_Class(context, false);
				pic.__PHP_Incomplete_Class_Name.Value = typeName;
				pic.__PHP_Incomplete_Class_Name.IsSet = true;

				return pic;
			}
			else
			{
				// create the instance
				return type.New(context) as DObject;
			}
		}
開發者ID:hansdude,項目名稱:Phalanger,代碼行數:48,代碼來源:Serialization.cs

示例7: ClassNameOrObjectToType

		/// <summary>
		/// Converts a class name or class instance to <see cref="DTypeDesc"/> object.
		/// </summary>
		/// <param name="scriptContext">Current <see cref="ScriptContext"/>.</param>
		/// <param name="namingContext">Current <see cref="NamingContext"/>.</param>
        /// <param name="caller">The caller of the method to resolve visible properties properly. Can be UnknownTypeDesc.</param>
        /// <param name="classNameOrObject">The class name or class instance (<see cref="DObject"/>).</param>
		/// <param name="useAutoload"><B>True</B> iff the <c>__autoload</c> magic function should be used.</param>
		/// <returns>The type desc that corresponds to <paramref name="classNameOrObject"/> or <B>null</B>
		/// if the type could not be found or <paramref name="classNameOrObject"/> is neither a string
		/// nor <see cref="DObject"/>.</returns>
		internal static DTypeDesc ClassNameOrObjectToType(ScriptContext/*!*/ scriptContext, NamingContext namingContext,
			DTypeDesc caller, object classNameOrObject, bool useAutoload)
		{
			string class_name = PhpVariable.AsString(classNameOrObject);
			if (class_name != null)
			{
				// lookup the Type
				return scriptContext.ResolveType(class_name, namingContext, caller, null,
					(useAutoload ? ResolveTypeFlags.UseAutoload : ResolveTypeFlags.None));
			}
			else
			{
				DObject obj = classNameOrObject as DObject;
				if (obj != null) return obj.TypeDesc;
			}

			return null;
		}
開發者ID:kripper,項目名稱:Phalanger,代碼行數:29,代碼來源:Objects.cs

示例8: __construct

        public virtual object __construct(ScriptContext context, object @class, object methodname)
        {
            string methodnameStr = PhpVariable.AsString(methodname);

            this.dtype = null;
            this.method = null;

            DObject dobj;
            
            if ((dobj = (@class as DObject)) != null)
            {
                this.dtype = dobj.TypeDesc;
            }
            else
            {
                var str = PhpVariable.AsString(@class);
                if (str != null)
                    this.dtype = context.ResolveType(str, null, null, null, ResolveTypeFlags.UseAutoload);

                if (this.dtype == null)
                {
                    PhpException.Throw(PhpError.Error, string.Format("Class {0} does not exist", str));
                    return false;
                }
            }
            
            if (this.dtype.GetMethod(new Name(methodnameStr), dtype, out this.method) == GetMemberResult.NotFound)
            {
                PhpException.Throw(PhpError.Error, string.Format("Method {0}::{1}() does not exist", dtype.MakeFullName(), methodnameStr));  
                return false;
            }

            return null;
        }
開發者ID:hansdude,項目名稱:Phalanger,代碼行數:34,代碼來源:ReflectionFunction.cs

示例9: LoadAndMatch

		/// <summary>
        /// Try to load all <paramref name="providedTypes"/>. This can invoke autoloading if necessary.
        /// Check if they were not modified, so calling compilation unit has to be invalidated and recompiled.
        /// </summary>
		/// <param name="providedTypes">a list of provided type declarators. Can be a <B>null</B> reference.</param>
		/// <param name="target">The script context to be checked.</param>
        /// <param name="caller">Current class context.</param>
		/// <returns><paramref name="providedTypes"/> are loadable and match in context of <paramref name="target"/>.</returns>
        public static bool LoadAndMatch(List<ProvidedType> providedTypes, ScriptContext/*!*/ target, DTypeDesc caller)
		{
			Debug.Assert(target != null);

            if (providedTypes != null && providedTypes.Count > 0)
			{
                //// there is less declarators than we require:
                //if (target.DeclaredTypes.Count < providedTypes.Count) return false;

				// looks up each provided declarator in the target context:
				foreach (ProvidedType declarator in providedTypes)
				{
                    //DTypeDesc decl_type;
                    //target.DeclaredTypes.TryGetValue(declarator.Key, out decl_type);

                    // When class is compiled in runtime, autoload is invoked on base class (if isn't already declared). 
                    // We have to call autoload on the base class also in transient assembly
                    var decl_type = target.ResolveType(declarator.Key, null, caller, null, ResolveTypeFlags.UseAutoload);
                    if (decl_type == null || decl_type.RealType != declarator.Value.RealType)
						return false;
				}
			}

			return true;
		}
開發者ID:dw4dev,項目名稱:Phalanger,代碼行數:33,代碼來源:DynamicCode.cs

示例10: __construct

        public virtual object __construct(ScriptContext context, object @class, object methodname)
        {
            string methodnameStr = PhpVariable.AsString(methodname);

            if (@class == null || string.IsNullOrEmpty(methodnameStr))
                return false;

            this.dtype = null;
            this.method = null;

            DObject dobj;
            string str;

            if ((dobj = (@class as DObject)) != null)
            {
                this.dtype = dobj.TypeDesc;
            }
            else if ((str = PhpVariable.AsString(@class)) != null)
            {
                this.dtype = context.ResolveType(str, null, null, null, ResolveTypeFlags.UseAutoload);
            }

            if (this.dtype == null)
                return false;

            if (this.dtype.GetMethod(new Name(methodnameStr), dtype, out this.method) == GetMemberResult.NotFound)
                return false;

            return null;
        }
開發者ID:tiaohai,項目名稱:Phalanger,代碼行數:30,代碼來源:ReflectionFunction.cs

示例11: __construct

        public virtual object __construct(ScriptContext context, object @class, object propertyname)
        {
            string propertynameStr = PhpVariable.AsString(propertyname);

            if (@class == null || string.IsNullOrEmpty(propertynameStr))
                return false;

            this.dtype = null;
            this.property = null;

            DObject dobj;
            string str;

            if ((dobj = (@class as DObject)) != null)
            {
                this.dtype = dobj.TypeDesc;
            }
            else if ((str = PhpVariable.AsString(@class)) != null)
            {
                this.dtype = context.ResolveType(str, null, null, null, ResolveTypeFlags.UseAutoload);
            }

            if (this.dtype == null)
                return false;

            if (this.dtype.GetProperty(new VariableName(propertynameStr), dtype, out this.property) == GetMemberResult.NotFound)
            {
                object runtimeValue;
                if (dobj != null && dobj.RuntimeFields != null && dobj.RuntimeFields.TryGetValue(propertynameStr, out runtimeValue))
                {
                    // create desc of runtime field:
                    this.property = new RuntimePhpProperty(dtype,
                        (instance) => ((DObject)instance).GetRuntimeField(this.name, null),
                        (instance, value) => ((DObject)instance).SetRuntimeField(this.name, value, null, null, null));
                    this.property.Member = new KnownRuntimeProperty(this.property, propertynameStr);
                }
                else
                {
                    return false;
                }
            }

            return null;
        }
開發者ID:dw4dev,項目名稱:Phalanger,代碼行數:44,代碼來源:Reflection.cs


注:本文中的PHP.Core.ScriptContext.ResolveType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。