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


C# FieldInfo.Clone方法代码示例

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


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

示例1: BindToField

        public override FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo[] match, object value, CultureInfo cultureInfo)
        {
            int num;
            if (match == null)
            {
                throw new ArgumentNullException("match");
            }
            int num2 = 0;
            Type c = null;
            FieldInfo[] infoArray = (FieldInfo[]) match.Clone();
            if ((bindingAttr & BindingFlags.SetField) != BindingFlags.Default)
            {
                c = value.GetType();
                for (num = 0; num < infoArray.Length; num++)
                {
                    Type fieldType = infoArray[num].FieldType;
                    if (fieldType == c)
                    {
                        infoArray[num2++] = infoArray[num];
                    }
                    else if ((value == Empty.Value) && fieldType.IsClass)
                    {
                        infoArray[num2++] = infoArray[num];
                    }
                    else if (fieldType == typeof(object))
                    {
                        infoArray[num2++] = infoArray[num];
                    }
                    else if (fieldType.IsPrimitive)
                    {
                        if (CanConvertPrimitiveObjectToType(value, (RuntimeType) fieldType))
                        {
                            infoArray[num2++] = infoArray[num];
                        }
                    }
                    else if (fieldType.IsAssignableFrom(c))
                    {
                        infoArray[num2++] = infoArray[num];
                    }
                }
                switch (num2)
                {
                    case 0:
                        throw new MissingFieldException(Environment.GetResourceString("MissingField"));

                    case 1:
                        return infoArray[0];
                }
            }
            int index = 0;
            bool flag = false;
            for (num = 1; num < num2; num++)
            {
                switch (FindMostSpecificField(infoArray[index], infoArray[num]))
                {
                    case 0:
                        flag = true;
                        break;

                    case 2:
                        index = num;
                        flag = false;
                        break;
                }
            }
            if (flag)
            {
                throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
            }
            return infoArray[index];
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:71,代码来源:DefaultBinder.cs

示例2: BindToField

        [System.Security.SecuritySafeCritical]  // auto-generated
        public override FieldInfo BindToField(BindingFlags bindingAttr,FieldInfo[] match, Object value,CultureInfo cultureInfo)
        {
            if (match == null) {
                throw new ArgumentNullException("match");
            }

            int i;
            // Find the method that match...
            int CurIdx = 0;

            Type valueType = null;

            FieldInfo[] candidates = (FieldInfo[]) match.Clone();
            
            // If we are a FieldSet, then use the value's type to disambiguate
            if ((bindingAttr & BindingFlags.SetField) != 0) {
                valueType = value.GetType();
                
                for (i=0;i<candidates.Length;i++) {
                    Type pCls = candidates[i].FieldType;
                    if (pCls == valueType) {
                        candidates[CurIdx++] = candidates[i];
                        continue;
                    }
                    if (value == Empty.Value) {
                        // the object passed in was null which would match any non primitive non value type
                        if (pCls.IsClass) {
                            candidates[CurIdx++] = candidates[i];
                            continue;
                        }
                    }
                    if (pCls == typeof(Object)) {
                        candidates[CurIdx++] = candidates[i];
                        continue;
                    }
                    if (pCls.IsPrimitive) {
                        if (CanConvertPrimitiveObjectToType(value,(RuntimeType)pCls)) {
                            candidates[CurIdx++] = candidates[i];
                            continue;
                        }
                    }
                    else {
                        if (pCls.IsAssignableFrom(valueType)) {
                            candidates[CurIdx++] = candidates[i];
                            continue;
                        }
                    }
                }
                if (CurIdx == 0)
                    throw new MissingFieldException(Environment.GetResourceString("MissingField"));
                if (CurIdx == 1)
                    return candidates[0];
            }
            
            // Walk all of the methods looking the most specific method to invoke
            int currentMin = 0;
            bool ambig = false;
            for (i=1;i<CurIdx;i++) {
                int newMin = FindMostSpecificField(candidates[currentMin], candidates[i]);
                if (newMin == 0)
                    ambig = true;
                else {
                    if (newMin == 2) {
                        currentMin = i;
                        ambig = false;
                    }
                }
            }
            if (ambig)
                throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
            return candidates[currentMin];
        }
开发者ID:destinyclown,项目名称:coreclr,代码行数:73,代码来源:DefaultBinder.cs

示例3: BindToField

		public override FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo[] match, object value, CultureInfo cultureInfo)
		{
			if (match == null)
			{
				throw new ArgumentNullException("match");
			}
			int num = 0;
			FieldInfo[] array = (FieldInfo[])match.Clone();
			if ((bindingAttr & BindingFlags.SetField) != BindingFlags.Default)
			{
				Type type = value.GetType();
				for (int i = 0; i < array.Length; i++)
				{
					Type fieldType = array[i].FieldType;
					if (fieldType == type)
					{
						array[num++] = array[i];
					}
					else
					{
						if (value == Empty.Value && fieldType.IsClass)
						{
							array[num++] = array[i];
						}
						else
						{
							if (fieldType == typeof(object))
							{
								array[num++] = array[i];
							}
							else
							{
								if (fieldType.IsPrimitive)
								{
									if (DefaultBinder.CanConvertPrimitiveObjectToType(value, (RuntimeType)fieldType))
									{
										array[num++] = array[i];
									}
								}
								else
								{
									if (fieldType.IsAssignableFrom(type))
									{
										array[num++] = array[i];
									}
								}
							}
						}
					}
				}
				if (num == 0)
				{
					throw new MissingFieldException(Environment.GetResourceString("MissingField"));
				}
				if (num == 1)
				{
					return array[0];
				}
			}
			int num2 = 0;
			bool flag = false;
			for (int i = 1; i < num; i++)
			{
				int num3 = DefaultBinder.FindMostSpecificField(array[num2], array[i]);
				if (num3 == 0)
				{
					flag = true;
				}
				else
				{
					if (num3 == 2)
					{
						num2 = i;
						flag = false;
					}
				}
			}
			if (flag)
			{
				throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
			}
			return array[num2];
		}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:83,代码来源:DefaultBinder.cs


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