Example #1
0
		///<summary>
		/// This method sets the concrete property on a concrete widget. It is the most important
		/// method to get the defined properties reflected in the User Interface
		///</summary>
		///<param name="uiObject">The (widget set dependent) object that represents the part in the widget set</param>
		///<param name="p"></param>
		///<param name="part"></param>
		///<param name="tclassType"></param>
		private System.Object ApplyProperty(ref System.Object uiObject, Property p, Part part, Type tclassType)
		{
			if (p.IsVirtual)
			{
				// don't do anything, just return the widget
				return uiObject;
			}
			string setter = Voc.GetPropertySetter(p.Name, part.Class);
            DParam[] parameters = Voc.GetParams(p.Name, part.Class, "setMethod");

			//try to use Properties first,
			//if that fails, look for the appropriate setters in the available methods
			try
			{
				Type classType = tclassType;
				System.Object targetObject = uiObject;
				PropertyInfo pInfo = null;
				int j = setter.IndexOf('.');
				while(j!=-1)
				{
					String parentType = setter.Substring(0,j);
					setter=setter.Substring(j+1,setter.Length-j-1);
					pInfo = classType.GetProperty(parentType);
					classType = pInfo.PropertyType;
					targetObject = pInfo.GetValue(targetObject, null);
					j = setter.IndexOf('.');
				}

                MemberInfo memInfo = GetMemberInfo(setter, classType, part, p);

                if (memInfo == null)
                {
                    // throw some error here, about not having the appropriate member
                    Console.WriteLine("Warning: could not load setter \"{0}\" for {1} (type {2}), please check your vocabulary", setter, part.Identifier, tclassType.FullName);
                    return uiObject;
                }

				//if lazy, resolve property value first
				if(p.Lazy)
					p.Resolve(this);

				//
				if (memInfo is PropertyInfo)
					SetProperty(targetObject, p, (PropertyInfo)memInfo);
				else
					InvokeMethod(targetObject, part, p, (MethodInfo)memInfo);
			}
			/*
			catch(TypeLoadException tle)
			{
				return ApplyAdHocProperty(ref uiObject, part, p);
			} 
			*/
			catch(NullReferenceException nre)
			{
				Console.WriteLine("Warning: could not load setter \"{0}\" for {1} (type {2}), please check your vocabulary", setter, part.Identifier, tclassType.FullName);
			}
			catch(Exception e)
			{
				Console.WriteLine("Setting property [{0}] with value [{1}] failed for [{2}]", setter, p.Value, part.Identifier);
				Console.WriteLine(e);
				Console.WriteLine("Trying to continue...");
			}
			return uiObject;
		}