• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Reflection.FieldInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



FieldInfo类属于System.Reflection命名空间,在下文中一共展示了FieldInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetSerializableMembers2

 private static MemberInfo[] GetSerializableMembers2(Type type)
 {
     // get the list of all fields
     FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
     int countProper = 0;
     for (int i = 0; i < fields.Length; i++)
     {
         if ((fields[i].Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized)
             continue;
         countProper++;
     }
     if (countProper != fields.Length)
     {
         FieldInfo[] properFields = new FieldInfo[countProper];
         countProper = 0;
         for (int i = 0; i < fields.Length; i++)
         {
             if ((fields[i].Attributes & FieldAttributes.NotSerialized) == FieldAttributes.NotSerialized)
                 continue;
             properFields[countProper] = fields[i];
             countProper++;
         }
         return properFields;
     }
     else
         return fields;
 }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:27,代码来源:FormatterServicesNoSerializableCheck.cs


示例2: CreateMessage

 public static string CreateMessage(FieldInfo field)
 {
     return String.Format("Instance could not be created for field '{0}' of type '{1}' in Assembly '{2}'",
                             field.Name,
                             field.DeclaringType.FullName,
                             field.Module);
 }
开发者ID:Rostamzadeh,项目名称:WorkflowExtractor,代码行数:7,代码来源:CouldNotCreateInstanceException.cs


示例3: FindActionWindow

        /// <summary>
        /// Find the UIPartActionWindow for a part. Usually this is useful just to mark it as dirty.
        /// </summary>
        public static UIPartActionWindow FindActionWindow(this Part part)
        {
            if (part == null)
                return null;

            // We need to do quite a bit of piss-farting about with reflection to 
            // dig the thing out. We could just use Object.Find, but that requires hitting a heap more objects.
            UIPartActionController controller = UIPartActionController.Instance;
            if (controller == null)
                return null;

            if (windowListField == null)
            {
                Type cntrType = typeof(UIPartActionController);
                foreach (FieldInfo info in cntrType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
                {
                    if (info.FieldType == typeof(List<UIPartActionWindow>))
                    {
                        windowListField = info;
                        goto foundField;
                    }
                }
                Debug.LogWarning("*PartUtils* Unable to find UIPartActionWindow list");
                return null;
            }
            foundField:

            List<UIPartActionWindow> uiPartActionWindows = (List<UIPartActionWindow>)windowListField.GetValue(controller);
            if (uiPartActionWindows == null)
                return null;

            return uiPartActionWindows.FirstOrDefault(window => window != null && window.part == part);
        }
开发者ID:Yitscar,项目名称:KSPInterstellar,代码行数:36,代码来源:PartExtensions.cs


示例4: FieldGetter

 public FieldGetter(FieldInfo fieldInfo)
 {
     _fieldInfo = fieldInfo;
     _name = fieldInfo.Name;
     _memberType = fieldInfo.FieldType;
     _lateBoundFieldGet = DelegateFactory.CreateGet(fieldInfo);
 }
开发者ID:nikson,项目名称:AutoMapper,代码行数:7,代码来源:FieldGetter.cs


示例5: DynamicScopeTokenResolver

        static DynamicScopeTokenResolver()
        {
            BindingFlags s_bfInternal = BindingFlags.NonPublic | BindingFlags.Instance;
            s_indexer = Type.GetType("System.Reflection.Emit.DynamicScope").GetProperty("Item", s_bfInternal);
            s_scopeFi = Type.GetType("System.Reflection.Emit.DynamicILGenerator").GetField("m_scope", s_bfInternal);

            s_varArgMethodType = Type.GetType("System.Reflection.Emit.VarArgMethod");
            s_varargFi1 = s_varArgMethodType.GetField("m_method", s_bfInternal);
            s_varargFi2 = s_varArgMethodType.GetField("m_signature", s_bfInternal);

            s_genMethodInfoType = Type.GetType("System.Reflection.Emit.GenericMethodInfo");
            s_genmethFi1 = s_genMethodInfoType.GetField("m_methodHandle", s_bfInternal);
            s_genmethFi2 = s_genMethodInfoType.GetField("m_context", s_bfInternal);

            s_genFieldInfoType = Type.GetType("System.Reflection.Emit.GenericFieldInfo", false);
            if (s_genFieldInfoType != null)
            {
                s_genfieldFi1 = s_genFieldInfoType.GetField("m_fieldHandle", s_bfInternal);
                s_genfieldFi2 = s_genFieldInfoType.GetField("m_context", s_bfInternal);
            }
            else
            {
                s_genfieldFi1 = s_genfieldFi2 = null;
            }
        }
开发者ID:taolin123,项目名称:ExpressionFutures,代码行数:25,代码来源:DynamicScopeTokenResolver.cs


示例6: ProcessField

		/// <summary>
		/// Dispatches the call to the extensions.
		/// </summary>
		/// <param name="fi">The field info reflection object.</param>
		/// <param name="model">The model.</param>
		public void ProcessField(FieldInfo fi, ActiveRecordModel model)
		{
			foreach(IModelBuilderExtension extension in extensions)
			{
				extension.ProcessField(fi, model);
			}
		}
开发者ID:pallmall,项目名称:WCell,代码行数:12,代码来源:ModelBuilderExtensionComposite.cs


示例7: GetFieldValueAccess

		/// <summary>
		/// Creates a <see cref="ValueAccess"/> suitable for accessing the value in <paramref name="fieldInfo"/>.
		/// </summary>
		/// <param name="fieldInfo">The <see cref="FieldInfo"/></param> representing the field for which a
		/// <see cref="ValueAccess"/> is required.
		/// <returns>The <see cref="ValueAccess"/> that allows for accessing the value in <paramref name="fieldInfo"/>.</returns>
		/// <exception cref="ArgumentNullException">when <paramref name="fieldInfo"/> is <see langword="null"/>.</exception>
		public ValueAccess GetFieldValueAccess(FieldInfo fieldInfo)
		{
			if (null == fieldInfo)
				throw new ArgumentNullException("fieldInfo");

			return DoGetFieldValueAccess(fieldInfo);
		}
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:14,代码来源:MemberValueAccessBuilder.cs


示例8: FieldGetter

 public FieldGetter(FieldInfo fieldInfo)
 {
     _fieldInfo = fieldInfo;
     Name = fieldInfo.Name;
     MemberType = fieldInfo.FieldType;
     _lateBoundFieldGet = LazyFactory.Create(() => DelegateFactory.CreateGet(fieldInfo));
 }
开发者ID:AnatolyKulakov,项目名称:AutoMapper,代码行数:7,代码来源:FieldGetter.cs


示例9: checkFields

        private List<string> _list; //Store the list of existing languages

        //[TestMethod]
        //public void TestAllLanguageTranslationsExists()
        //{
        //    Language defaultlang = new Language(); //Load the English version
        //    defaultlang.General.TranslatedBy = "Translated by ..."; // to avoid assertion

        //    foreach (String cultureName in _list) //Loop over all language files
        //    {
        //        //Load language
        //        var reader = new System.IO.StreamReader(Path.Combine(Configuration.BaseDirectory, "Languages") + Path.DirectorySeparatorChar + cultureName + ".xml");
        //        Language lang = Language.Load(reader);

        //        //Loop over all field in language
        //        checkFields(cultureName, defaultlang, lang, defaultlang.GetType().GetFields());

        //        checkProperty(cultureName, defaultlang, lang, defaultlang.GetType().GetProperties());

        //        //If u want to save a kind of fixed lang file
        //        //Disabled the assert fail function for it!
        //      //  lang.Save("Languagesnew\\" + cultureName + ".xml");
        //        reader.Close();
        //    }
        //}

        private void checkFields(string cultureName, object completeLang, object cultureLang, FieldInfo[] fields)
        {
            foreach (FieldInfo fieldInfo in fields)
            {
                if (fieldInfo.IsPublic && fieldInfo.FieldType.Namespace.Equals("Nikse.SubtitleEdit.Logic")) {
                    object completeLangatt = fieldInfo.GetValue(completeLang);
                    object cultureLangatt = fieldInfo.GetValue(cultureLang);

                    if ((cultureLangatt == null) || (completeLangatt == null))
                    {
                        Assert.Fail(fieldInfo.Name + " is mssing");
                    }
                    //Console.Out.WriteLine("Field: " + fieldInfo.Name + " checked of type:" + fieldInfo.FieldType.FullName);
                    if (!fieldInfo.FieldType.FullName.Equals("System.String"))
                    {
                        checkFields(cultureName, completeLang, cultureLang, fieldInfo.FieldType.GetFields());
                        checkProperty(cultureName, completeLangatt, cultureLangatt, fieldInfo.FieldType.GetProperties());
                    }
                    else
                    {
                        Assert.Fail("no expecting a string here");
                    }
                }
            }
        }
开发者ID:IlgnerBri,项目名称:subtitleedit,代码行数:51,代码来源:languageTest.cs


示例10: ProccessField

        /// <summary>
        /// 判断字段的过虑条件。
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        public static bool ProccessField(FieldInfo field)
        {
            if(field.FieldType.IsSubclassOf(typeof(Delegate)))
                return  false;

            return true;
        }
开发者ID:hxzqlh,项目名称:enode,代码行数:12,代码来源:TypeFilter.cs


示例11: CreateProxiedMethod

		public void CreateProxiedMethod(FieldInfo field, MethodInfo method, TypeBuilder typeBuilder)
		{
			const MethodAttributes methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig |
																								MethodAttributes.Virtual;
			ParameterInfo[] parameters = method.GetParameters();

			MethodBuilder methodBuilder = typeBuilder.DefineMethod(method.Name, methodAttributes,
			                                                       CallingConventions.HasThis, method.ReturnType,
			                                                       parameters.Select(param => param.ParameterType).ToArray());

			System.Type[] typeArgs = method.GetGenericArguments();

			if (typeArgs.Length > 0)
			{
				var typeNames = new List<string>();

				for (int index = 0; index < typeArgs.Length; index++)
				{
					typeNames.Add(string.Format("T{0}", index));
				}

				methodBuilder.DefineGenericParameters(typeNames.ToArray());
			}

			ILGenerator IL = methodBuilder.GetILGenerator();

			Debug.Assert(MethodBodyEmitter != null);
			MethodBodyEmitter.EmitMethodBody(IL, method, field);
		}
开发者ID:pontillo,项目名称:PowerNap,代码行数:29,代码来源:DefaultProxyMethodBuilder.cs


示例12: Create

 private static IGetterAndSetter Create(FieldInfo fieldInfo)
 {
     var setter = typeof(GetterAndSetter<,>).MakeGenericType(fieldInfo.DeclaringType, fieldInfo.FieldType);
     var constructorInfo = setter.GetConstructor(new[] { typeof(FieldInfo) });
     //// ReSharper disable once PossibleNullReferenceException nope, not here
     return (IGetterAndSetter)constructorInfo.Invoke(new object[] { fieldInfo });
 }
开发者ID:JohanLarsson,项目名称:Gu.State,代码行数:7,代码来源:GetterAndSetter.cs


示例13: GlideInfo

 public GlideInfo(object target, FieldInfo info)
 {
     Target = target;
     field = info;
     PropertyName = info.Name;
     PropertyType = info.FieldType;
 }
开发者ID:mtesseracttech,项目名称:ArcadeGame,代码行数:7,代码来源:GlideInfo.cs


示例14: RubyFieldInfo

 public RubyFieldInfo(FieldInfo/*!*/ fieldInfo, RubyMemberFlags flags, RubyModule/*!*/ declaringModule, bool isSetter, bool isDetached)
     : base(flags, declaringModule) {
     Assert.NotNull(fieldInfo, declaringModule);
     _fieldInfo = fieldInfo;
     _isSetter = isSetter;
     _isDetached = isDetached;
 }
开发者ID:Hank923,项目名称:ironruby,代码行数:7,代码来源:RubyFieldInfo.cs


示例15: Decorate

        public virtual object Decorate(FieldInfo field)
        {
            if (!(typeof(IWebElement).IsAssignableFrom(field.FieldType)
                  || IsDecoratableList(field)))
            {
                return null;
            }

            IElementLocator locator = factory.CreateLocator(field);
            if (locator == null)
            {
                return null;
            }

            if (typeof(IWebElement).IsAssignableFrom(field.FieldType))
            {
                return ProxyForLocator(locator);
            }
            else if (typeof(IList).IsAssignableFrom(field.FieldType))
            {
                return ProxyForListLocator(locator);
            }
            else
            {
                return null;
            }
        }
开发者ID:kool79,项目名称:htmlelements-dotnet,代码行数:27,代码来源:DefaultFieldDecorator.cs


示例16: ApplyToFieldInfo

 public override void ApplyToFieldInfo(FieldInfo Info, ISerializablePacket Packet, Type Field)
 {
     if (Field.Equals(typeof(bool)))
         Info.SetValue(Packet, val);
     else
         Info.SetValue(Packet, Convert.ChangeType((bool)val, Info.FieldType));
 }
开发者ID:TheGhostGroup,项目名称:RiftEMU,代码行数:7,代码来源:BoolBit.cs


示例17: Visit

        public void Visit(string settingsNamesapce, string fieldPath, FieldInfo rawSettingsField, object rawSettings)
        {
            // Skip 'sealed' fields.
            if (rawSettingsField.IsDefined<SealedAttribute>()) return;

            if (rawSettingsField.FieldType == typeof(string))
            {
                var originalString = (string)rawSettingsField.GetValue(rawSettings);
                if (originalString != null)
                {
                    var expandedString = ExpandVariables(originalString, _variables);
                    rawSettingsField.SetValue(rawSettings, expandedString);
                }
            }
            else if (rawSettingsField.FieldType == typeof(string[]))
            {
                string[] arr = (string[])rawSettingsField.GetValue(rawSettings);
                for (int i = 0; i < arr.Length; i++)
                {
                    string originalString = arr[i];
                    if (originalString != null)
                    {
                        var expandedString = ExpandVariables(originalString, _variables);
                        arr[i] = expandedString;
                    }
                }
            }
        }
开发者ID:lukyad,项目名称:Eco,代码行数:28,代码来源:ConfigurationVariableExpander.cs


示例18: GenerateEnumMemberAttributes

	private void GenerateEnumMemberAttributes(FieldInfo fieldInfo)
	{	
		EnumMemberAttribute enumMemberAttr = (EnumMemberAttribute)Attribute.GetCustomAttribute(fieldInfo, typeof(EnumMemberAttribute));
        if (enumMemberAttr != null)
        {

this.Write("[System.Runtime.Serialization.EnumMember");


            string value = enumMemberAttr.Value;
            if (!string.IsNullOrEmpty(value))
            {

this.Write("(Value=");

this.Write(this.ToStringHelper.ToStringWithCulture(value.ToString()));

this.Write(")\r\n");


            }
this.Write("]");


		}
		
		this.GenerateAttributes(fieldInfo.GetCustomAttributes(false).Cast<Attribute>().Where(a => a.GetType() != typeof(EnumMemberAttribute)));
	}
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:28,代码来源:CSharpEnumGenerator.cs


示例19: EmitIL

 public void EmitIL(ILGenerator body, FieldInfo tape, FieldInfo ptr)
 {
     body.Emit(OpCodes.Ldsfld, ptr);
     body.Emit(OpCodes.Ldc_I4_1);
     body.Emit(OpCodes.Sub);
     body.Emit(OpCodes.Stsfld, ptr);
 }
开发者ID:paf31,项目名称:BF,代码行数:7,代码来源:DecrPtr.cs


示例20: CustomAttributeBuilder

 // public constructor to form the custom attribute with constructor and constructor
 // parameters.
 public CustomAttributeBuilder(ConstructorInfo con, Object[] constructorArgs,
                               PropertyInfo[] namedProperties, Object[] propertyValues,
                               FieldInfo[] namedFields, Object[] fieldValues)
 {
     InitCustomAttributeBuilder(con, constructorArgs, namedProperties,
                                propertyValues, namedFields, fieldValues);
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:9,代码来源:customattributebuilder.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Reflection.MemberInfo类代码示例发布时间:2022-05-26
下一篇:
C# Reflection.EventInfo类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap