本文整理汇总了C#中System.Reflection.MemberInfo.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo.ToString方法的具体用法?C# MemberInfo.ToString怎么用?C# MemberInfo.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddNode
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);
}
}
示例2: OptionDetails
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");
}
}
}
}
示例3: Resolve
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));
}
}
示例4: ToCref
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());
}
}
示例5: EmitStoreValue
/// <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 );
}
}
示例6: Evaluate
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();
}
示例7: FormatError
/// <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);
}
}
示例8: GetStringFromInstance
void GetStringFromInstance( MemberInfo info )
{
content.Clear();
if( !content.ContainsKey( info.Name ) )
{
content[info.Name] = new List<string>();
}
content[info.Name].Add( info.ToString() );
}
示例9: FormatEvent
/// <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);
}
示例10: AddCast
// 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;
}
示例11: FormMemberKey
protected static String FormMemberKey(MemberInfo mi)
{
return mi.DeclaringType.FullName + "/" + mi.ToString();
}
示例12: CastDialog
// 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);
}
示例13: CreateMemberReferenceElement
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()));
}
示例14: MakeMemberSignature
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());
}
示例15: ThrowGetOnlyMemberIsInvalid
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
)
);
}
}