当前位置: 首页>>代码示例>>C#>>正文


C# FieldInfo.GetRequiredCustomModifiers方法代码示例

本文整理汇总了C#中System.Reflection.FieldInfo.GetRequiredCustomModifiers方法的典型用法代码示例。如果您正苦于以下问题:C# FieldInfo.GetRequiredCustomModifiers方法的具体用法?C# FieldInfo.GetRequiredCustomModifiers怎么用?C# FieldInfo.GetRequiredCustomModifiers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.FieldInfo的用法示例。


在下文中一共展示了FieldInfo.GetRequiredCustomModifiers方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsVolatile

        public static bool IsVolatile(FieldInfo field)
        {
            // field builder doesn't implement GetRequiredCustomModifiers
            if (field is FieldBuilder) return false;

            return Array.IndexOf(field.GetRequiredCustomModifiers(), typeof(System.Runtime.CompilerServices.IsVolatile)) >= 0;
        }
开发者ID:zhuozhuowang,项目名称:Sigil,代码行数:7,代码来源:ExtensionMethods.cs

示例2: HasVolatileModifier

		protected override bool HasVolatileModifier (FieldInfo field)
		{
			var reqs = field.GetRequiredCustomModifiers ();
			if (reqs.Length > 0) {
				foreach (var t in reqs) {
					if (t == typeof (IsVolatile))
						return true;
				}
			}

			return false;
		}
开发者ID:carlosaml,项目名称:monodevelop,代码行数:12,代码来源:reflection.cs

示例3: IsVolatile

        private static bool IsVolatile(FieldInfo fi)
        {
            // Cannot work with signatures on uncreated types
            {
                Type t = fi.DeclaringType;
                TypeBuilder tb = t as TypeBuilder;
                if (tb != null && !tb.IsCreated())
                    return false;
            }

            #if MONO
            foreach (Type t in fi.GetRequiredCustomModifiers() )
                if ( t == typeof(IsVolatile) )
                    return true;
            return false;
            #else
            return FieldSigReader.IsVolatile(fi);
            #endif
        }
开发者ID:EricThorsen,项目名称:clojure-clr,代码行数:19,代码来源:IlGen.cs

示例4: 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());
        }
开发者ID:crummel,项目名称:dotnet_coreclr,代码行数:88,代码来源:ModuleBuilder.cs

示例5: 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);
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:46,代码来源:MetadataSignatureHelper.cs

示例6: 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 );
		}
开发者ID:nagyist,项目名称:msgpack-cli,代码行数:50,代码来源:TracingILGenerator.cs

示例7: 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());
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:77,代码来源:ModuleBuilder.cs

示例8: CreateField

		public FieldSpec CreateField (FieldInfo fi, TypeSpec declaringType)
		{
			Modifiers mod = 0;
			var fa = fi.Attributes;
			switch (fa & FieldAttributes.FieldAccessMask) {
				case FieldAttributes.Public:
					mod = Modifiers.PUBLIC;
					break;
				case FieldAttributes.Assembly:
					mod = Modifiers.INTERNAL;
					break;
				case FieldAttributes.Family:
					mod = Modifiers.PROTECTED;
					break;
				case FieldAttributes.FamORAssem:
					mod = Modifiers.PROTECTED | Modifiers.INTERNAL;
					break;
				default:
					// Ignore private fields (even for error reporting) to not require extra dependencies
					if (IgnorePrivateMembers || HasAttribute (CustomAttributeData.GetCustomAttributes (fi), typeof (CompilerGeneratedAttribute)))
						return null;

					mod = Modifiers.PRIVATE;
					break;
			}

			var definition = new ImportedMemberDefinition (fi);
			TypeSpec field_type;

			try {
				field_type = ImportType (fi.FieldType, fi, 0);
			} catch (Exception e) {
				// TODO: I should construct fake TypeSpec based on TypeRef signature
				// but there is no way to do it with System.Reflection
				throw new InternalErrorException (e, "Cannot import field `{0}.{1}' referenced in assembly `{2}'",
					declaringType.GetSignatureForError (), fi.Name, declaringType.MemberDefinition.DeclaringAssembly);
			}

			if ((fa & FieldAttributes.Literal) != 0) {
				var c = Constant.CreateConstantFromValue (field_type, fi.GetRawConstantValue (), Location.Null);
				return new ConstSpec (declaringType, definition, field_type, fi, mod, c);
			}

			if ((fa & FieldAttributes.InitOnly) != 0) {
				if (field_type == TypeManager.decimal_type) {
					var dc = ReadDecimalConstant (CustomAttributeData.GetCustomAttributes (fi));
					if (dc != null)
						return new ConstSpec (declaringType, definition, field_type, fi, mod, dc);
				}

				mod |= Modifiers.READONLY;
			} else {
				var reqs = fi.GetRequiredCustomModifiers ();
				if (reqs.Length > 0) {
					foreach (var t in reqs) {
						if (t == typeof (System.Runtime.CompilerServices.IsVolatile)) {
							mod |= Modifiers.VOLATILE;
							break;
						}
					}
				}
			}

			if ((fa & FieldAttributes.Static) != 0)
				mod |= Modifiers.STATIC;

			if (declaringType.IsStruct && field_type.IsStruct && field_type.IsNested && 
				HasAttribute (CustomAttributeData.GetCustomAttributes (fi), typeof (FixedBufferAttribute))) {

				var element_field = CreateField (fi.FieldType.GetField (FixedField.FixedElementName), declaringType);
				return new FixedFieldSpec (declaringType, definition, fi, element_field, mod);
			}

			return new FieldSpec (declaringType, definition, field_type, fi, mod);
		}
开发者ID:davidwaters,项目名称:mono,代码行数:75,代码来源:import.cs


注:本文中的System.Reflection.FieldInfo.GetRequiredCustomModifiers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。