Example #1
0
        public IBinding ToBinding(System.Reflection.MemberInfo mi)
        {
            switch (mi.MemberType)
            {
            case MemberTypes.Method:
            {
                return(new ExternalMethodBinding(this, (System.Reflection.MethodInfo)mi));
            }

            case MemberTypes.Constructor:
            {
                return(new ExternalConstructorBinding(this, (System.Reflection.ConstructorInfo)mi));
            }

            case MemberTypes.Field:
            {
                return(new ExternalFieldBinding(this, (System.Reflection.FieldInfo)mi));
            }

            case MemberTypes.Property:
            {
                return(new ExternalPropertyBinding(this, (System.Reflection.PropertyInfo)mi));
            }

            case MemberTypes.Event:
            {
                return(new ExternalEventBinding(this, (System.Reflection.EventInfo)mi));
            }

            default:
            {
                throw new NotImplementedException(mi.ToString());
            }
            }
        }
Example #2
0
 void ProcessMember(System.Reflection.MemberInfo memInfo)
 {
     System.Reflection.MethodInfo methodInfo = memInfo as System.Reflection.MethodInfo;
     if (methodInfo != null)
     {
         ProcessMethod(methodInfo);
     }
     else
     {
         System.Reflection.ConstructorInfo constructorInfo = memInfo as ConstructorInfo;
         if (constructorInfo != null)
         {
             ProcessConstructor(constructorInfo);
         }
         else
         {
             PropertyInfo propertyInfo = memInfo as PropertyInfo;
             if (propertyInfo != null)
             {
                 ProcessProperty(propertyInfo);
             }
             else
             {
                 EventInfo eventInfo = memInfo as EventInfo;
                 if (eventInfo != null)
                 {
                     ProcessEvent(eventInfo);
                 }
                 else
                 {
                     Debug.WriteLine("Add member " + memInfo.ToString());
                 }
             }
         }
     }
 }
Example #3
0
		private void AddNode (NodeInfoCollection c, NodeInfo parent, MemberInfo mi, object instance)
		{
			// FIXME: there has to be a cleaner way than this...
			// Don't add node if we don't want to display them.
			bool quit = false;
			switch (mi.MemberType) {
				case MemberTypes.Constructor:
					quit = !ShowConstructors;
					break;
				case MemberTypes.Event:
					quit = !ShowEvents;
					break;
				case MemberTypes.Field:
					quit = !ShowFields;
					break;
				case MemberTypes.Method:
					quit = !ShowMethods;
					break;
				case MemberTypes.Property:
					quit = !ShowProperties;
					break;
				case MemberTypes.TypeInfo:
					// either a Base type or an Interface
					// this is bound to produce buggy behavior...
					quit = !ShowBase && !ShowInterfaces;
					break;

				// case MemberTypes.NestedType
				// we don't break out nested types yet
			}

			if (quit)
				return;

			if (!seenReflectionObjects.Found (mi)) {
				seenReflectionObjects.Add (mi);
				NodeInfo n = new NodeInfo (parent, mi, instance);
				c.Add (n);
			}
			else {
				NodeInfo n = new NodeInfo (parent, "Seen: " + mi.ToString());
				n.NodeType = NodeTypes.Alias;
				c.Add (n);
			}
		}
Example #4
0
        public static string ToCref(MemberInfo member)
        {
            switch (member.MemberType)
            {
                case MemberTypes.Event:
                    return String.Concat(@"E:", member.DeclaringType.FullName, ".", member.Name);

                case MemberTypes.Field:
                    return String.Concat(@"F:", member.DeclaringType.FullName, ".", member.Name);

                case MemberTypes.Constructor:
                case MemberTypes.Method:
                    return String.Concat(@"M:", member.DeclaringType.FullName, ".", member.Name);

                case MemberTypes.Property:
                    return String.Concat(@"P:", member.DeclaringType.FullName, ".", member.Name);

                case MemberTypes.TypeInfo:
                case MemberTypes.NestedType:
                    return String.Concat(@"T:", ((Type)member).FullName);

                default:
                    return String.Concat("?", member.ToString());
            }
        }
Example #5
0
 private static string Evaluate(object holder, MemberInfo member)
 {
     if (member is FieldInfo)
     {
         return ((FieldInfo) member).GetValue(holder).ToString();
     }
     if (member is PropertyInfo)
     {
         return ((PropertyInfo) member).GetValue(holder, null).ToString();
     }
     return member.ToString();
 }
Example #6
0
		/// <summary>
		///		Emits appropriate storing member instructions.
		/// </summary>
		/// <param name="il">IL generator to be emitted to.</param>
		/// <param name="member"><see cref="MemberInfo"/> to be stored.</param>
		public static void EmitStoreValue( TracingILGenerator il, MemberInfo member )
		{
			Contract.Requires( il != null );
			Contract.Requires( member != null );

			var asProperty = member as PropertyInfo;
			if ( asProperty != null )
			{
				if ( !asProperty.CanWrite )
				{
					throw new SerializationException( String.Format( CultureInfo.CurrentCulture, "Cannot set value to '{0}.{1}' property.", asProperty.DeclaringType, asProperty.Name ) );
				}

				il.EmitSetProperty( asProperty );
			}
			else
			{
				Contract.Assert( member is FieldInfo, member.ToString() + ":" + member.MemberType );
				var asField = member as FieldInfo;
				if ( asField.IsInitOnly )
				{
					throw new SerializationException( String.Format( CultureInfo.CurrentCulture, "Cannot set value to '{0}.{1}' field.", asField.DeclaringType, asField.Name ) );
				}

				il.EmitStfld( asField );
			}
		}
 void GetStringFromInstance( MemberInfo info )
 {
     content.Clear();
     if( !content.ContainsKey( info.Name ) )
     {
         content[info.Name] = new List<string>();
     }
     content[info.Name].Add( info.ToString() );
 }
 private static MemberSetter ThrowGetOnlyMemberIsInvalid(MemberInfo member)
 {
     var asProperty = member as PropertyInfo;
     if (asProperty != null)
     {
         throw new SerializationException(String.Format(CultureInfo.CurrentCulture, "Cannot set value to '{0}.{1}' property.", asProperty.DeclaringType, asProperty.Name));
     }
     else
     {
         Contract.Assert(member is FieldInfo, member.ToString() + ":" + member.GetType());
         throw new SerializationException(
             String.Format(
                 CultureInfo.CurrentCulture, "Cannot set value to '{0}.{1}' field.", member.DeclaringType, member.Name
             )
         );
     }
 }
Example #9
0
        /// <summary>
        /// Called within exception catch blocks to format the exception.source property.
        /// Mostly for Trace.Writes.
        /// </summary>
        /// <param name="memberInfo">Current method info via reflection</param>
        /// <param name="errorFormat">Enum of ErrorFormat determines if Message or Source</param>
        /// <param name="errorMessage">exception.Message property</param>
        /// <param name="errorSource">exception.Source property</param>
        /// <returns>fomatted string</returns>
        public static string FormatError(MemberInfo memberInfo, ErrorFormat errorFormat,
            String errorMessage, string errorSource)
        {
            if (null == memberInfo)
                throw new ArgumentNullException("memberInfo");

            if (string.IsNullOrEmpty(errorMessage)) { errorMessage = string.Empty; }

            switch (errorFormat)
            {
                case ErrorFormat.Message:
                    return string.Format(CultureInfo.CurrentCulture, ErrorMessageFormat,
                                     memberInfo.ReflectedType.ToString(),
                                     memberInfo.ToString(), errorMessage, errorSource);

                default: // default to source
                    return string.Format(CultureInfo.CurrentCulture, ErrorSourceFormat,
                                     memberInfo.ReflectedType.ToString(),
                                     memberInfo.ToString(), errorSource);

            }
        }
Example #10
0
        /// <summary>
        /// Used primarily to format error information for logging 
        /// </summary>
        /// <param name="memberInfo">MemberInfo class to derive current 
        /// executing method signature information from</param>
        /// <param name="exception">System.Exception object to retreive string
        /// information from</param>
        /// <returns>formatted string</returns>
        public static string FormatEvent(MemberInfo memberInfo, System.Exception exception)
        {
            if (null == memberInfo)
                throw new ArgumentNullException("memberInfo");
            if (null == exception)
                throw new ArgumentNullException("exception");

            return string.Format(CultureInfo.CurrentCulture, EventLogFormat,
                                     exception.Message,memberInfo.ReflectedType.ToString(),
                                     memberInfo.ToString(), exception.Source ?? string.Empty, exception.TargetSite == null ? string.Empty : exception.TargetSite.ToString(), exception.StackTrace ?? string.Empty);
        }
Example #11
0
        /// <summary>
        /// Used primarily to format warning information for logging 
        /// </summary>
        /// <param name="memberInfo">MemberInfo class to derive current 
        /// executing method signature information from</param>
        /// <param name="message">message to log</param>
        /// <returns>formatted string</returns>
        public static string FormatEvent(MemberInfo memberInfo, string message)
        {
            if (null == memberInfo)
                throw new ArgumentNullException("memberInfo");
            if (string.IsNullOrEmpty(message))
                throw new ArgumentNullException("message");

            return string.Format(CultureInfo.CurrentCulture, EventLogMessageFormat,
                                     memberInfo.ToString(), memberInfo.ReflectedType.ToString(),
                                     message);
        }
Example #12
0
		// Adds cast information, if the memberInfo is null, this 
		// cast is not rememebered at all
		internal static CastInfo AddCast(MemberInfo memberInfo,
										Type castType,
										bool perm,
										Object currentObj)
		{
			CastInfo ci;
			if (memberInfo == null) {
				ci = new CastInfo(castType);
			} else {
				ci = new CastInfo(memberInfo.ToString(),
								 memberInfo.DeclaringType.FullName,
								 castType,
								 perm);
			}
			// Optionally make sure the cast will work for a 
			// specified object
			if (currentObj != null)
				ci.DoCast(currentObj);
			// We don't try to remember if if there is no memberInfo
			if (memberInfo == null)
				return ci;
			lock (_casts) {
				if (_casts[ci.Key] == null) {
					_casts.Add(ci.Key, ci);
				} else {
					// Get rid of the permanent key if it was there
					if (!perm) {
						ComponentInspectorProperties.SavedCasts.Remove(ci.DeclaringType, ci.MemberSig);
					}
				}
			}
			if (perm) {
				ComponentInspectorProperties.SavedCasts.Remove(memberInfo.DeclaringType.FullName, memberInfo.ToString());
				SavedCastInfo savedCast = new SavedCastInfo(memberInfo.DeclaringType.FullName, memberInfo.ToString(), castType.FullName);
				ComponentInspectorProperties.SavedCasts.Add(savedCast);
			}
			return ci;
		}
Example #13
0
		protected static String FormMemberKey(MemberInfo mi)
		{
			return mi.DeclaringType.FullName + "/" + mi.ToString();
		}
Example #14
0
		// castInfo is an existing CastInfo if any, currentObj is
		// the current value to be cast.  We will try the cast with
		// this value to make sure its possible before accepting the
		// new cast.
		internal CastDialog(CastInfo castInfo,
							MemberInfo member,
							Object currentObj) : base(!INCLUDE_BUTTONS)
		{
			_memberInfo = member;
			_castInfo = castInfo;
			_currentObj = currentObj;

			Activated += new EventHandler(ActivateHandler);

			if (_memberInfo != null)
				Text = StringParser.Parse("${res:ComponentInspector.CastDialog.CastForTitle} ") + _memberInfo.ToString();
			else
				Text = StringParser.Parse("${res:ComponentInspector.CastDialog.CastTitle}");
			Width = 400;
			Height = 170;

			// Panel for dialog contents
			Panel panel = new Panel();
			panel.Dock = DockStyle.Top;
			Controls.Add(panel);

			if (_memberInfo != null) {
				_rememberCheck = new CheckBox();
				_rememberCheck.Dock = DockStyle.Top;
				_rememberCheck.Text = StringParser.Parse("${res:ComponentInspector.CastDialog.RememberCastCheckBox}");
				if (_castInfo != null)
					_rememberCheck.Checked = _castInfo.Perm;
				else
					_rememberCheck.Checked = true;
				panel.Controls.Add(_rememberCheck);
			}

			// Spacing
			Label l = new Label();
			l.Dock = DockStyle.Top;
			panel.Controls.Add(l);

			// Panel for textbox
			Panel textPanel = new Panel();
			textPanel.Dock = DockStyle.Top;
			panel.Controls.Add(textPanel);

			_textBox = new TextBox();
			_textBox.Dock = DockStyle.Fill;
			if (_castInfo != null)
				_textBox.Text = _castInfo.CastType.FullName;
			textPanel.Controls.Add(_textBox);

			l = new Label();
			l.Dock = DockStyle.Left;
			l.Text = StringParser.Parse("${res:ComponentInspector.CastDialog.CastToLabel} ");
			l.AutoSize = true;
			textPanel.Controls.Add(l);

			textPanel.Height = _textBox.Height;

			Panel bp = new Panel();
			bp.Dock = DockStyle.Bottom;

			l = new Label();
			l.Dock = DockStyle.Fill;
			bp.Controls.Add(l);

			Button ok = Utils.MakeButton(StringParser.Parse("${res:Global.OKButtonText}"));
			ok.Dock = DockStyle.Right;
			ok.DialogResult = DialogResult.OK;
			AcceptButton = ok;
			bp.Controls.Add(ok);

			if (_castInfo != null)
			{
				Button b = Utils.MakeButton(StringParser.Parse("${res:Global.RemoveButtonText}"));
				b.Dock = DockStyle.Right;
				b.DialogResult = DialogResult.OK;
				b.Click += new EventHandler(RemoveClick);
				bp.Controls.Add(b);
			}

			Button cancel = Utils.MakeButton(StringParser.Parse("${res:Global.CancelButtonText}"));
			cancel.Dock = DockStyle.Right;
			cancel.DialogResult = DialogResult.Cancel;
			bp.Controls.Add(cancel);

			bp.Height = Utils.BUTTON_HEIGHT;

			Controls.Add(bp);

		}
Example #15
0
		public OptionDetails(MemberInfo memberInfo, OptionAttribute option, Options optionBundle)
		{
			ShortForm = ("" + option.ShortForm).Trim();
			if (option.LongForm == null)
				LongForm = string.Empty;
			else
				LongForm = (option.LongForm == string.Empty) ? memberInfo.Name : option.LongForm;
			AlternateForm = option.AlternateForm;
			ShortDescription = ExtractParamName(option.ShortDescription);
			Occurs = 0;
			OptionBundle = optionBundle;
			BooleanOption = false;
			MemberInfo = memberInfo;
			NeedsParameter = false;
			Values = null;
			MaxOccurs = 1;
			VBCStyleBoolean = option.VBCStyleBoolean;
			SecondLevelHelp = option.SecondLevelHelp;
			Hidden = false; // TODO: check other attributes

			ParameterType = TypeOfMember(memberInfo);

			if (ParameterType != null)
			{
				if (ParameterType.FullName != "System.Boolean")
				{
					if (LongForm.IndexOf(':') >= 0)
						throw new InvalidOperationException(
							"Options with an embedded colon (':') in their visible name must be boolean!!! [" +
							MemberInfo.ToString() + " isn't]");

					NeedsParameter = true;

					if (option.MaxOccurs != 1)
					{
						if (ParameterType.IsArray)
						{
							Values = new ArrayList();
							MaxOccurs = option.MaxOccurs;
						}
						else
						{
							if (MemberInfo is MethodInfo || MemberInfo is PropertyInfo)
								MaxOccurs = option.MaxOccurs;
							else
								throw new InvalidOperationException("MaxOccurs set to non default value (" + option.MaxOccurs + ") for a [" +
								                                    MemberInfo.ToString() + "] option");
						}
					}
				}
				else
				{
					BooleanOption = true;
					if (option.MaxOccurs != 1)
					{
						if (MemberInfo is MethodInfo || MemberInfo is PropertyInfo)
							MaxOccurs = option.MaxOccurs;
						else
							throw new InvalidOperationException("MaxOccurs set to non default value (" + option.MaxOccurs + ") for a [" +
							                                    MemberInfo.ToString() + "] option");
					}
				}
			}
		}
 private XElement CreateMemberReferenceElement(string typeName, MemberInfo member)
 {
     return new XElement("Member-Reference",
                   new XAttribute("ref", _memberIdentifierGenerator.GetIdentifier(member)),
                   new XAttribute("type", typeName),
                   new XAttribute("member-name", member.Name),
                   new XAttribute("member-signature", member.ToString()));
 }
Example #17
0
	static string MakeMemberSignature(MemberInfo mi) {
		if (mi is ConstructorInfo) return MakeConstructorSignature((ConstructorInfo)mi);
		if (mi is MethodInfo) return MakeMethodSignature((MethodInfo)mi);
		if (mi is PropertyInfo) return MakePropertySignature((PropertyInfo)mi);
		if (mi is FieldInfo) return MakeFieldSignature((FieldInfo)mi);
		if (mi is EventInfo) return MakeEventSignature((EventInfo)mi);
		throw new ArgumentException(mi.ToString());
	}
Example #18
0
        public IEntity Map(MemberInfo mi)
        {
            IEntity tag = (IEntity)_entityCache[GetCacheKey(mi)];
            if (null == tag)
            {
                switch (mi.MemberType)
                {
                    case MemberTypes.Method:
                    {
                        return Map((MethodInfo)mi);
                    }

                    case MemberTypes.Constructor:
                    {
                        return Map((ConstructorInfo)mi);
                    }

                    case MemberTypes.Field:
                    {
                        tag = new ExternalField(this, (FieldInfo)mi);
                        break;
                    }

                    case MemberTypes.Property:
                    {
                        tag = new ExternalProperty(this, (PropertyInfo)mi);
                        break;
                    }

                    case MemberTypes.Event:
                    {
                        tag = new ExternalEvent(this, (EventInfo)mi);
                        break;
                    }

                    case MemberTypes.NestedType:
                    {
                        return Map((Type)mi);
                    }

                    default:
                    {
                        throw new NotImplementedException(mi.ToString());
                    }
                }
                _entityCache.Add(GetCacheKey(mi), tag);
            }
            return tag;
        }
 virtual public bool TestGetCustomAttributes (MemberInfo mem)
   {
   Util.print ("\n\n" + this.GetType ().ToString () + " - TestGetCustomAttributes() started.");
   Util.print ("For: " + mem.GetType ().ToString () + "\n");
   string strLoc="L_11_000";
   Attribute[] attrs = null;
   try  
     {
     do
       {
       iCountTestcases++;
       strLoc="L_11_001";
       if (mem == null) {
       iCountErrors++;
       Util.printerr ("E_11_75yhg - mem == null");
       return false;
       }
       iCountTestcases++;
       strLoc="L_11_001.2";
       attrs = Attribute.GetCustomAttributes (mem, true);
       if (attrs == null) {
       iCountErrors++;
       Util.printerr ("E_11_gfh4 - attrs == null");
       return false;
       }
       iCountTestcases++;
       strLoc="L_11_001.3";

        if (attrs.Length != iCountTotalAttrs) {
                iCountErrors++;
                Util.printerr ("E_11_jhd4 - attrs.Length Failed!");
                Util.print ("Expected: " + iCountTotalAttrs.ToString() + "; Returned: " + attrs.Length);
                Util.printerr(mem.ToString());
                for(int i=0; i< attrs.Length; i++ )
                {
                    Util.printerr ("E_11_jhd4 - " + attrs[i] );
                }

            }
        
       iCountTestcases++;
       strLoc="L_11_001.3";
       TestAttributes (attrs, mem);
       } while ( false );
     }
   catch( Exception exc_runTest ) {
   ++iCountErrors;
   Util.printerr ("Err_888un! - Uncaught Exception caught in TestGetCustomAttributes(); strLoc == " + strLoc);
   Util.printexc (exc_runTest);
   Util.print (exc_runTest.StackTrace);
   }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
Example #20
0
		/// <summary>
		///		Emits appropriate loading member instructions.
		/// </summary>
		/// <param name="il">IL generator to be emitted to.</param>
		/// <param name="member"><see cref="MemberInfo"/> to be loaded.</param>
		public static void EmitLoadValue( TracingILGenerator il, MemberInfo member )
		{
			Contract.Requires( il != null );
			Contract.Requires( member != null );

			var asProperty = member as PropertyInfo;
			if ( asProperty != null )
			{
				il.EmitGetProperty( asProperty );
			}
			else
			{
				Contract.Assert( member is FieldInfo, member.ToString() + ":" + member.MemberType );
				il.EmitLdfld( member as FieldInfo );
			}
		}
Example #21
0
		internal static void Resolve (
			TestSuite suite, TestFixture parent, MemberInfo member,
			out IDictionary<Type, TestCategoryAttribute> categories,
			out IList<TestWarning> warnings, out TestConfiguration config,
			out bool disabled)
		{
			disabled = false;
			config = null;

			bool hasConfig = false;
			warnings = new List<TestWarning> ();
			categories = new Dictionary<Type, TestCategoryAttribute> ();

			if (parent != null) {
				config = parent.Configuration;
				hasConfig = config != null;
				foreach (var category in parent.Categories)
					categories [category.GetType ()] = category;
			}

			string fullName;
			if (member is Type)
				fullName = ((Type)member).FullName;
			else if (member is MethodInfo) {
				var method = (MethodInfo)member;
				fullName = method.DeclaringType.FullName + "." + method.Name;
			} else {
				fullName = member.ToString ();
			}

			var attrs = member.GetCustomAttributes (typeof(TestCategoryAttribute), false);

			foreach (var obj in attrs) {
				var category = obj as TestCategoryAttribute;
				if (category == null)
					continue;

				if (categories.ContainsKey (category.GetType ())) {
					suite.Log ("Duplicate [{0}] in {1}.",
					           category.GetType ().FullName, fullName);
					continue;
				}

				var configAttr = obj as ConfigurableTestCategoryAttribute;
				if (configAttr == null) {
					categories [category.GetType ()] = category;
					continue;
				}

				if (hasConfig) {
					suite.Log ("Only one single [ConfigurableTestCategory] is " +
					           "allowed in {0}", fullName);
					continue;
				}

				config = configAttr.Resolve ();
				if ((config != null) && config.IsEnabled)
					categories [category.GetType ()] = category;
				else
					disabled = true;
			}

			var wattrs = member.GetCustomAttributes (typeof(TestWarningAttribute), false);

			foreach (var obj in wattrs) {
				var attr = obj as TestWarningAttribute;
				if (attr == null)
					continue;

				string message;
				if (member is MethodInfo)
					message = member.Name + ": " + attr.Message;
				else
					message = attr.Message;
				warnings.Add (new TestWarning (message));
			}
		}
Example #22
0
		/// <summary>
		/// Returns a string that can be used for representing a(ny) member in log entries.
		/// </summary>
		/// <param name="info"></param>
		/// <param name="includeDeclaringType">If true, the members declaring type is included in the returned name.</param>
		/// <returns></returns>
		public static string MemberInfo(MemberInfo info, bool includeDeclaringType = true)
		{
			if (info is MethodInfo)
				return MethodInfo(info as MethodInfo, includeDeclaringType);
			else if (info is ConstructorInfo)
				return ConstructorInfo(info as ConstructorInfo, includeDeclaringType);
			else if (info is PropertyInfo)
				return PropertyInfo(info as PropertyInfo, includeDeclaringType);
			else if (info is FieldInfo)
				return FieldInfo(info as FieldInfo, includeDeclaringType);
			else if (info is EventInfo)
				return EventInfo(info as EventInfo, includeDeclaringType);
			else if (info is Type)
				return Type(info as Type);
			else if (info != null)
				return info.ToString();
			else
				return "null";
		}
Example #23
0
		// Finds the specified member within this object
		internal ObjectTypeTreeNode FindMember(MemberInfo member)
		{
			Type memberInfoType = member.GetType();
			// Make sure we have the members populated
			ExpandNode();
			foreach (Object node in LogicalNodes)
			{
				if (node is ObjectTypeTreeNode)
				{
					ObjectInfo objInfo = ((ObjectTypeTreeNode)node).ObjectInfo;
					if (objInfo != null)
					{
						MemberInfo mi = objInfo.ObjMemberInfo;
						if (!mi.GetType().Equals(memberInfoType))
							continue;
						if (objInfo.ObjMemberInfo.ToString().
							Equals(member.ToString()))
							return (ObjectTypeTreeNode)node;
					}
				}
			}
			return null;
		}