本文整理汇总了C#中System.Reflection.FieldInfo.GetOptionalCustomModifiers方法的典型用法代码示例。如果您正苦于以下问题:C# FieldInfo.GetOptionalCustomModifiers方法的具体用法?C# FieldInfo.GetOptionalCustomModifiers怎么用?C# FieldInfo.GetOptionalCustomModifiers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.FieldInfo
的用法示例。
在下文中一共展示了FieldInfo.GetOptionalCustomModifiers方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFieldTokenNoLock
[System.Security.SecurityCritical] // auto-generated
private FieldToken GetFieldTokenNoLock(FieldInfo field)
{
if (field == null) {
throw new ArgumentNullException("con");
}
Contract.EndContractBlock();
int tr;
int mr = 0;
FieldBuilder fdBuilder = null;
RuntimeFieldInfo rtField = null;
FieldOnTypeBuilderInstantiation fOnTB = null;
if ((fdBuilder = field as FieldBuilder) != null)
{
if (field.DeclaringType != null && field.DeclaringType.IsGenericType)
{
int length;
byte[] sig = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out length);
tr = GetTokenFromTypeSpec(sig, length);
mr = GetMemberRef(this, tr, fdBuilder.GetToken().Token);
}
else if (fdBuilder.Module.Equals(this))
{
// field is defined in the same module
return fdBuilder.GetToken();
}
else
{
// field is defined in a different module
if (field.DeclaringType == null)
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
}
tr = GetTypeTokenInternal(field.DeclaringType).Token;
mr = GetMemberRef(field.ReflectedType.Module, tr, fdBuilder.GetToken().Token);
}
}
else if ( (rtField = field as RuntimeFieldInfo) != null)
{
// FieldInfo is not an dynamic field
// We need to get the TypeRef tokens
if (field.DeclaringType == null)
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
}
if (field.DeclaringType != null && field.DeclaringType.IsGenericType)
{
int length;
byte[] sig = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out length);
tr = GetTokenFromTypeSpec(sig, length);
mr = GetMemberRefOfFieldInfo(tr, field.DeclaringType.GetTypeHandleInternal(), rtField);
}
else
{
tr = GetTypeTokenInternal(field.DeclaringType).Token;
mr = GetMemberRefOfFieldInfo(tr, field.DeclaringType.GetTypeHandleInternal(), rtField);
}
}
else if ( (fOnTB = field as FieldOnTypeBuilderInstantiation) != null)
{
FieldInfo fb = fOnTB.FieldInfo;
int length;
byte[] sig = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out length);
tr = GetTokenFromTypeSpec(sig, length);
mr = GetMemberRef(fb.ReflectedType.Module, tr, fOnTB.MetadataTokenInternal);
}
else
{
// user defined FieldInfo
tr = GetTypeTokenInternal(field.ReflectedType).Token;
SignatureHelper sigHelp = SignatureHelper.GetFieldSigHelper(this);
sigHelp.AddArgument(field.FieldType, field.GetRequiredCustomModifiers(), field.GetOptionalCustomModifiers());
int length;
byte[] sigBytes = sigHelp.InternalGetSignature(out length);
mr = GetMemberRefFromSignature(tr, field.Name, sigBytes, length);
}
return new FieldToken(mr, field.GetType());
}
示例2: TraceField
private void TraceField( FieldInfo field )
{
// <instr_field> <type> <typeSpec> :: <id>
Contract.Assert( field != null );
WriteType( this._trace, field.FieldType );
this._trace.Write( " " );
// TODO: NLiblet
#if !SILVERLIGHT
var asFieldBuilder = field as FieldBuilder;
if ( asFieldBuilder == null )
{
var modreqs = field.GetRequiredCustomModifiers();
if ( 0 < modreqs.Length )
{
this._trace.Write( "modreq(" );
foreach ( var modreq in modreqs )
{
WriteType( this._trace, modreq );
}
this._trace.Write( ") " );
}
var modopts = field.GetOptionalCustomModifiers();
if ( 0 < modopts.Length )
{
this._trace.Write( "modopt(" );
foreach ( var modopt in modopts )
{
WriteType( this._trace, modopt );
}
this._trace.Write( ") " );
}
}
#endif
#if !SILVERLIGHT
if ( this._isInDynamicMethod || asFieldBuilder == null ) // declaring type of the field should be omitted for same type.
#endif
{
WriteType( this._trace, field.DeclaringType );
}
this._trace.Write( "::" );
this._trace.Write( field.Name );
}
示例3: AppendFieldInfo
static private void AppendFieldInfo(FieldInfo field, StringBuilder sb)
{
sb.Append(".field ");
foreach (var attribute in field.GetCustomAttributesData())
{
AppendCustomAttributeData(attribute, sb);
sb.Append(" ");
}
foreach (var modreq in field.GetRequiredCustomModifiers())
{
sb.Append("modreq(");
AppendType(modreq, sb);
sb.Append(") ");
}
foreach (var modopt in field.GetOptionalCustomModifiers())
{
sb.Append("modopt(");
AppendType(modopt, sb);
sb.Append(") ");
}
if (field.IsPrivate) sb.Append("private ");
if (field.IsPublic) sb.Append("public ");
if (field.IsFamily) sb.Append("family ");
if (field.IsAssembly) sb.Append("assembly ");
if (field.IsFamilyOrAssembly) sb.Append("famorassem ");
if (field.IsFamilyAndAssembly) sb.Append("famandassem ");
if (field.IsInitOnly) sb.Append("initonly ");
if (field.IsLiteral) sb.Append("literal ");
if (field.IsNotSerialized) sb.Append("notserialized ");
if (field.Attributes.HasFlag(FieldAttributes.SpecialName)) sb.Append("specialname ");
if (field.Attributes.HasFlag(FieldAttributes.RTSpecialName)) sb.Append("rtspecialname ");
if (field.IsPinvokeImpl) sb.Append("pinvokeimpl ");
sb.Append(field.IsStatic ? "static " : "instance ");
AppendType(field.FieldType, sb);
sb.Append(" ");
sb.Append(field.Name);
if (field.IsLiteral)
{
AppendValue(field.GetRawConstantValue(), sb);
}
}
示例4: GetFieldTokenNoLock
private FieldToken GetFieldTokenNoLock(FieldInfo field)
{
int tokenFromTypeSpec;
if (field == null)
{
throw new ArgumentNullException("con");
}
int num2 = 0;
FieldBuilder builder = null;
FieldOnTypeBuilderInstantiation instantiation = null;
builder = field as FieldBuilder;
if (builder != null)
{
if ((field.DeclaringType != null) && field.DeclaringType.IsGenericType)
{
int num3;
byte[] signature = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out num3);
tokenFromTypeSpec = this.GetTokenFromTypeSpec(signature, num3);
num2 = this.GetMemberRef(this, tokenFromTypeSpec, builder.GetToken().Token);
}
else
{
if (builder.Module.Equals(this))
{
return builder.GetToken();
}
if (field.DeclaringType == null)
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
}
tokenFromTypeSpec = this.GetTypeTokenInternal(field.DeclaringType).Token;
num2 = this.GetMemberRef(field.ReflectedType.Module, tokenFromTypeSpec, builder.GetToken().Token);
}
}
else if (field is RuntimeFieldInfo)
{
if (field.DeclaringType == null)
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotImportGlobalFromDifferentModule"));
}
int metadataToken = field.MetadataToken;
if ((field.DeclaringType != null) && field.DeclaringType.IsGenericType)
{
int num5;
byte[] buffer2 = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out num5);
tokenFromTypeSpec = this.GetTokenFromTypeSpec(buffer2, num5);
num2 = this.GetMemberRefOfFieldInfo(tokenFromTypeSpec, field.DeclaringType.GetTypeHandleInternal(), metadataToken);
}
else
{
tokenFromTypeSpec = this.GetTypeTokenInternal(field.DeclaringType).Token;
num2 = this.GetMemberRefOfFieldInfo(tokenFromTypeSpec, field.DeclaringType.GetTypeHandleInternal(), metadataToken);
}
}
else
{
instantiation = field as FieldOnTypeBuilderInstantiation;
if (instantiation != null)
{
int num6;
FieldInfo fieldInfo = instantiation.FieldInfo;
byte[] buffer3 = SignatureHelper.GetTypeSigToken(this, field.DeclaringType).InternalGetSignature(out num6);
tokenFromTypeSpec = this.GetTokenFromTypeSpec(buffer3, num6);
num2 = this.GetMemberRef(fieldInfo.ReflectedType.Module, tokenFromTypeSpec, instantiation.MetadataTokenInternal);
}
else
{
int num7;
tokenFromTypeSpec = this.GetTypeTokenInternal(field.ReflectedType).Token;
SignatureHelper fieldSigHelper = SignatureHelper.GetFieldSigHelper(this);
fieldSigHelper.AddArgument(field.FieldType, field.GetRequiredCustomModifiers(), field.GetOptionalCustomModifiers());
byte[] buffer4 = fieldSigHelper.InternalGetSignature(out num7);
num2 = this.GetMemberRefFromSignature(tokenFromTypeSpec, field.Name, buffer4, num7);
}
}
return new FieldToken(num2, field.GetType());
}