コード例 #1
0
ファイル: DefaultBinder.cs プロジェクト: destinyclown/coreclr
        [System.Security.SecuritySafeCritical]  // auto-generated
        public override PropertyInfo SelectProperty(BindingFlags bindingAttr,PropertyInfo[] match,Type returnType,
                    Type[] indexes,ParameterModifier[] modifiers)
        {
            // Allow a null indexes array. But if it is not null, every element must be non-null as well.
            if (indexes != null && !Contract.ForAll(indexes, delegate(Type t) { return t != null; }))
            {
                Exception e;  // Written this way to pass the Code Contracts style requirements.
#if FEATURE_LEGACYNETCF
                if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8)
                    e = new NullReferenceException();
                else
#endif
                    e = new ArgumentNullException("indexes");
                throw e;
            }
            if (match == null || match.Length == 0)
                throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match");
            Contract.EndContractBlock();

            PropertyInfo[] candidates = (PropertyInfo[]) match.Clone();

            int i,j = 0;
                
            // Find all the properties that can be described by type indexes parameter
            int CurIdx = 0;
            int indexesLength = (indexes != null) ? indexes.Length : 0;
            for (i=0;i<candidates.Length;i++) {

                if (indexes != null)
                {
                    ParameterInfo[] par = candidates[i].GetIndexParameters();
                    if (par.Length != indexesLength)
                        continue;
                        
                    for (j=0;j<indexesLength;j++) {
                        Type pCls = par[j]. ParameterType;
                        
                        // If the classes  exactly match continue
                        if (pCls == indexes[j])
                            continue;
                        if (pCls == typeof(Object))
                            continue;
                        
                        if (pCls.IsPrimitive) {
                            if (!(indexes[j].UnderlyingSystemType is RuntimeType) ||
                                !CanConvertPrimitive((RuntimeType)indexes[j].UnderlyingSystemType,(RuntimeType)pCls.UnderlyingSystemType))
                                break;
                        }
                        else {
                            if (!pCls.IsAssignableFrom(indexes[j]))
                                break;
                        }
                    }
                }
                
                if (j == indexesLength) {
                    if (returnType != null) {
                        if (candidates[i].PropertyType.IsPrimitive) {
                            if (!(returnType.UnderlyingSystemType is RuntimeType) ||
                                !CanConvertPrimitive((RuntimeType)returnType.UnderlyingSystemType,(RuntimeType)candidates[i].PropertyType.UnderlyingSystemType))
                                continue;
                        }
                        else {
                            if (!candidates[i].PropertyType.IsAssignableFrom(returnType))
                                continue;
                        }
                    }
                    candidates[CurIdx++] = candidates[i];
                }
            }
            if (CurIdx == 0)
                return null;
            if (CurIdx == 1)
                return candidates[0];
                
            // Walk all of the properties looking the most specific method to invoke
            int currentMin = 0;
            bool ambig = false;
            int[] paramOrder = new int[indexesLength];
            for (i=0;i<indexesLength;i++)
                paramOrder[i] = i;
            for (i=1;i<CurIdx;i++) {
                int newMin = FindMostSpecificType(candidates[currentMin].PropertyType, candidates[i].PropertyType,returnType);
                if (newMin == 0 && indexes != null)
                    newMin = FindMostSpecific(candidates[currentMin].GetIndexParameters(),
                                              paramOrder,
                                              null,
                                              candidates[i].GetIndexParameters(),
                                              paramOrder,
                                              null,
                                              indexes, 
                                              null);
                if (newMin == 0)
                {
                    newMin = FindMostSpecificProperty(candidates[currentMin], candidates[i]);
                    if (newMin == 0)
                        ambig = true;
                }
                if (newMin == 2) {
                    ambig = false;
                    currentMin = i;
                }
            }

            if (ambig)
                throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
            return candidates[currentMin];
        }
コード例 #2
0
ファイル: DefaultBinder.cs プロジェクト: er0dr1guez/corefx
        public static PropertyInfo SelectProperty(PropertyInfo[] match, Type returnType, Type[] indexes)
        {
            // Allow a null indexes array. But if it is not null, every element must be non-null as well.
            if (indexes != null && !Contract.ForAll(indexes, delegate (Type t) { return t != null; }))
            {
                Exception e;  // Written this way to pass the Code Contracts style requirements.
                e = new ArgumentNullException("indexes");
                throw e;
            }
            if (match == null || match.Length == 0)
            {
                throw new ArgumentException(SR.Arg_EmptyArray, "match");
            }

            PropertyInfo[] candidates = (PropertyInfo[])match.Clone();

            int i, j = 0;

            // Find all the properties that can be described by type indexes parameter
            int CurIdx = 0;
            int indexesLength = (indexes != null) ? indexes.Length : 0;
            for (i = 0; i < candidates.Length; i++)
            {
                if (indexes != null)
                {
                    ParameterInfo[] par = candidates[i].GetIndexParameters();
                    if (par.Length != indexesLength)
                    {
                        continue;
                    }

                    for (j = 0; j < indexesLength; j++)
                    {
                        Type pCls = par[j].ParameterType;

                        // If the classes  exactly match continue
                        if (pCls == indexes[j])
                        {
                            continue;
                        }
                        if (pCls == typeof(Object))
                        {
                            continue;
                        }

                        if (pCls.GetTypeInfo().IsPrimitive)
                        {
                            if (!CanConvertPrimitive(indexes[j], pCls))
                            {
                                break;
                            }
                        }
                        else
                        {
                            if (!pCls.GetTypeInfo().IsAssignableFrom(indexes[j].GetTypeInfo()))
                            {
                                break;
                            }
                        }
                    }
                }

                if (j == indexesLength)
                {
                    if (returnType != null)
                    {
                        if (candidates[i].PropertyType.GetTypeInfo().IsPrimitive)
                        {
                            if (!CanConvertPrimitive(returnType, candidates[i].PropertyType))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (!candidates[i].PropertyType.GetTypeInfo().IsAssignableFrom(returnType.GetTypeInfo()))
                            {
                                continue;
                            }
                        }
                    }
                    candidates[CurIdx++] = candidates[i];
                }
            }
            if (CurIdx == 0)
            {
                return null;
            }
            if (CurIdx == 1)
            {
                return candidates[0];
            }

            // Walk all of the properties looking the most specific method to invoke
            int currentMin = 0;
            bool ambig = false;
            int[] paramOrder = new int[indexesLength];
            for (i = 0; i < indexesLength; i++)
            {
                paramOrder[i] = i;
            }
            for (i = 1; i < CurIdx; i++)
            {
                int newMin = FindMostSpecificType(candidates[currentMin].PropertyType, candidates[i].PropertyType, returnType);
                if (newMin == 0 && indexes != null)
                    newMin = FindMostSpecific(candidates[currentMin].GetIndexParameters(),
                                              paramOrder,
                                              null,
                                              candidates[i].GetIndexParameters(),
                                              paramOrder,
                                              null,
                                              indexes,
                                              null);
                if (newMin == 0)
                {
                    newMin = FindMostSpecificProperty(candidates[currentMin], candidates[i]);
                    if (newMin == 0)
                    {
                        ambig = true;
                    }
                }
                if (newMin == 2)
                {
                    ambig = false;
                    currentMin = i;
                }
            }

            if (ambig)
            {
                throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
            }

            return candidates[currentMin];
        }
コード例 #3
0
        public override PropertyInfo SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type returnType, Type[] indexes, ParameterModifier[] modifiers)
        {
            int num;
            if ((indexes != null) && !Contract.ForAll<Type>(indexes, t => t != null))
            {
                throw new ArgumentNullException("indexes");
            }
            if ((match == null) || (match.Length == 0))
            {
                throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match");
            }
            PropertyInfo[] infoArray = (PropertyInfo[]) match.Clone();
            int index = 0;
            int num3 = 0;
            int num4 = (indexes != null) ? indexes.Length : 0;
            for (num = 0; num < infoArray.Length; num++)
            {
                if (indexes != null)
                {
                    ParameterInfo[] indexParameters = infoArray[num].GetIndexParameters();
                    if (indexParameters.Length != num4)
                    {
                        continue;
                    }
                    index = 0;
                    while (index < num4)
                    {
                        Type parameterType = indexParameters[index].ParameterType;
                        if ((parameterType != indexes[index]) && (parameterType != typeof(object)))
                        {
                            if (parameterType.IsPrimitive)
                            {
                                if (!(indexes[index].UnderlyingSystemType is RuntimeType) || !CanConvertPrimitive((RuntimeType) indexes[index].UnderlyingSystemType, (RuntimeType) parameterType.UnderlyingSystemType))
                                {
                                    break;
                                }
                            }
                            else if (!parameterType.IsAssignableFrom(indexes[index]))
                            {
                                break;
                            }
                        }
                        index++;
                    }
                }
                if (index != num4)
                {
                    continue;
                }
                if (returnType != null)
                {
                    if (infoArray[num].PropertyType.IsPrimitive)
                    {
                        if ((returnType.UnderlyingSystemType is RuntimeType) && CanConvertPrimitive((RuntimeType) returnType.UnderlyingSystemType, (RuntimeType) infoArray[num].PropertyType.UnderlyingSystemType))
                        {
                            goto Label_0173;
                        }
                        continue;
                    }
                    if (!infoArray[num].PropertyType.IsAssignableFrom(returnType))
                    {
                        continue;
                    }
                }
            Label_0173:
                infoArray[num3++] = infoArray[num];
            }
            switch (num3)
            {
                case 0:
                    return null;

                case 1:
                    return infoArray[0];
            }
            int num5 = 0;
            bool flag = false;
            int[] numArray = new int[num4];
            for (num = 0; num < num4; num++)
            {
                numArray[num] = num;
            }
            for (num = 1; num < num3; num++)
            {
                int num6 = FindMostSpecificType(infoArray[num5].PropertyType, infoArray[num].PropertyType, returnType);
                if ((num6 == 0) && (indexes != null))
                {
                    num6 = FindMostSpecific(infoArray[num5].GetIndexParameters(), numArray, null, infoArray[num].GetIndexParameters(), numArray, null, indexes, null);
                }
                if (num6 == 0)
                {
                    num6 = FindMostSpecificProperty(infoArray[num5], infoArray[num]);
                    if (num6 == 0)
                    {
                        flag = true;
                    }
                }
                if (num6 == 2)
                {
                    flag = false;
                    num5 = num;
                }
            }
            if (flag)
            {
                throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
            }
            return infoArray[num5];
        }
コード例 #4
0
ファイル: LayoutPanel.cs プロジェクト: saihe/Effekseer
            /// <summary>
            /// プロパティから生成
            /// </summary>
            /// <param name="properties"></param>
            public TypeRow(PropertyInfo[] properties, List<TypeRow> sameLayer, TypeRow parent)
            {
                Parent = parent;

                var p = properties.LastOrDefault();
                var attributes = p.GetCustomAttributes(false);

                Control gui = null;

                var undo = attributes.Where(_ => _.GetType() == typeof(Effekseer.Data.UndoAttribute)).FirstOrDefault() as Effekseer.Data.UndoAttribute;
                if (undo != null && !undo.Undo)
                {
                    EnableUndo = false;
                }
                else
                {
                    EnableUndo = true;
                }

                var shown = attributes.Where(_ => _.GetType() == typeof(Effekseer.Data.ShownAttribute)).FirstOrDefault() as Effekseer.Data.ShownAttribute;

                if (shown != null && !shown.Shown)
                {
                    gui = null;
                    return;
                }
                else if (p.PropertyType == typeof(Data.Value.String))
                {
                    gui = new String();
                }
                else if (p.PropertyType == typeof(Data.Value.Boolean))
                {
                    gui = new Boolean();
                }
                else if (p.PropertyType == typeof(Data.Value.Int))
                {
                    gui = new Int();
                }
                else if (p.PropertyType == typeof(Data.Value.IntWithInifinite))
                {
                    gui = new IntWithInifinite();
                }
                else if (p.PropertyType == typeof(Data.Value.IntWithRandom))
                {
                    gui = new IntWithRandom();
                }
                else if (p.PropertyType == typeof(Data.Value.Float))
                {
                    gui = new Float();
                }
                else if (p.PropertyType == typeof(Data.Value.FloatWithRandom))
                {
                    gui = new FloatWithRandom();
                }
                else if (p.PropertyType == typeof(Data.Value.Vector2D))
                {
                    gui = new Vector2D();
                }
                else if (p.PropertyType == typeof(Data.Value.Vector2DWithRandom))
                {
                    gui = new Vector2DWithRandom();
                }
                else if (p.PropertyType == typeof(Data.Value.Vector3D))
                {
                    gui = new Vector3D();
                }
                else if (p.PropertyType == typeof(Data.Value.Vector3DWithRandom))
                {
                    gui = new Vector3DWithRandom();
                }
                else if (p.PropertyType == typeof(Data.Value.Color))
                {
                    gui = new ColorCtrl();
                }
                else if (p.PropertyType == typeof(Data.Value.ColorWithRandom))
                {
                    gui = new ColorWithRandom();
                }
                else if (p.PropertyType == typeof(Data.Value.Path))
                {
                    gui = new Path();
                }
                else if (p.PropertyType == typeof(Data.Value.PathForImage))
                {
                    gui = new PathForImage();
                }
                else if (p.PropertyType == typeof(Data.Value.PathForSound))
                {
                    gui = new PathForSound();
                }
                else if (p.PropertyType == typeof(Data.Value.FCurveVector3D))
                {
                    FCurveButton button = new FCurveButton();
                    button.Text = "Fカーブ";
                    gui = button;
                }
                else if (p.PropertyType == typeof(Data.Value.FCurveColorRGBA))
                {
                    FCurveButton button = new FCurveButton();
                    button.Text = "Fカーブ";
                    gui = button;
                }
                else if (p.PropertyType == typeof(Data.Value.FCurve<float>))
                {
                    gui = null;
                    return;
                }
                else if (p.PropertyType == typeof(Data.Value.FCurve<byte>))
                {
                    gui = null;
                    return;
                }
                else if (p.PropertyType == typeof(Data.Value.IFCurveKey))
                {
                    gui = null;
                    return;
                }
                else if (p.PropertyType.IsGenericType)
                {
                    var types = p.PropertyType.GetGenericArguments();
                    var generic_type = typeof(Enum<>).MakeGenericType(types);
                    var constructor = generic_type.GetConstructor(new Type[] { });
                    gui = constructor.Invoke(null) as Control;
                }

                var selector_attribute = (from a in attributes where a is Data.SelectorAttribute select a).FirstOrDefault() as Data.SelectorAttribute;
                if (selector_attribute != null)
                {
                    IsSelector = true;
                    SelectorID = selector_attribute.ID;
                }
                else
                {
                    IsSelector = false;
                    SelectorID = -1;
                }

                Properties = properties.Clone() as PropertyInfo[];
                Title = NameAttribute.GetName(attributes);
                Description = DescriptionAttribute.GetDescription(attributes);
                Control = gui;

                // Selector
                var selected_attribute = (from a in attributes where a is Data.SelectedAttribute select a).FirstOrDefault() as Data.SelectedAttribute;
                if (selected_attribute != null)
                {
                    var selector = sameLayer.Where(_ => _.IsSelector && _.SelectorID == selected_attribute.ID).LastOrDefault();

                    if (selector != null)
                    {
                        Selector = selector;
                        SelectorValue = selected_attribute.Value;
                    }
                }

                Label = new Label();
                Label.Width = 0;
                Label.AutoSize = true;
                Label.Text = Title;
                Label.TextAlign = ContentAlignment.MiddleCenter;
                Label.Font = new Font(Label.Font.FontFamily, 9);
                ControlDynamic = Control;

                if (Control != null && !(Control is Button))
                {
                    ControlDynamic.EnableUndo = EnableUndo;
                }
            }
コード例 #5
0
		public override PropertyInfo SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type returnType, Type[] indexes, ParameterModifier[] modifiers)
		{
			if (indexes != null)
			{
				if (!Contract.ForAll<Type>(indexes, (Type t) => t != null))
				{
					throw new ArgumentNullException("indexes");
				}
			}
			if (match == null || match.Length == 0)
			{
				throw new ArgumentException(Environment.GetResourceString("Arg_EmptyArray"), "match");
			}
			PropertyInfo[] array = (PropertyInfo[])match.Clone();
			int i = 0;
			int num = 0;
			int num2 = (indexes != null) ? indexes.Length : 0;
			int j = 0;
			while (j < array.Length)
			{
				if (indexes == null)
				{
					goto IL_113;
				}
				ParameterInfo[] indexParameters = array[j].GetIndexParameters();
				if (indexParameters.Length == num2)
				{
					for (i = 0; i < num2; i++)
					{
						Type parameterType = indexParameters[i].ParameterType;
						if (!(parameterType == indexes[i]) && !(parameterType == typeof(object)))
						{
							if (parameterType.IsPrimitive)
							{
								if (!(indexes[i].UnderlyingSystemType is RuntimeType))
								{
									break;
								}
								if (!DefaultBinder.CanConvertPrimitive((RuntimeType)indexes[i].UnderlyingSystemType, (RuntimeType)parameterType.UnderlyingSystemType))
								{
									break;
								}
							}
							else
							{
								if (!parameterType.IsAssignableFrom(indexes[i]))
								{
									break;
								}
							}
						}
					}
					goto IL_113;
				}
				IL_17D:
				j++;
				continue;
				IL_113:
				if (i == num2)
				{
					if (returnType != null)
					{
						if (array[j].PropertyType.IsPrimitive)
						{
							if (!(returnType.UnderlyingSystemType is RuntimeType))
							{
								goto IL_17D;
							}
							if (!DefaultBinder.CanConvertPrimitive((RuntimeType)returnType.UnderlyingSystemType, (RuntimeType)array[j].PropertyType.UnderlyingSystemType))
							{
								goto IL_17D;
							}
						}
						else
						{
							if (!array[j].PropertyType.IsAssignableFrom(returnType))
							{
								goto IL_17D;
							}
						}
					}
					array[num++] = array[j];
					goto IL_17D;
				}
				goto IL_17D;
			}
			if (num == 0)
			{
				return null;
			}
			if (num == 1)
			{
				return array[0];
			}
			int num3 = 0;
			bool flag = false;
			int[] array2 = new int[num2];
			for (j = 0; j < num2; j++)
			{
				array2[j] = j;
			}
			for (j = 1; j < num; j++)
			{
				int num4 = DefaultBinder.FindMostSpecificType(array[num3].PropertyType, array[j].PropertyType, returnType);
				if (num4 == 0 && indexes != null)
				{
					num4 = DefaultBinder.FindMostSpecific(array[num3].GetIndexParameters(), array2, null, array[j].GetIndexParameters(), array2, null, indexes, null);
				}
				if (num4 == 0)
				{
					num4 = DefaultBinder.FindMostSpecificProperty(array[num3], array[j]);
					if (num4 == 0)
					{
						flag = true;
					}
				}
				if (num4 == 2)
				{
					flag = false;
					num3 = j;
				}
			}
			if (flag)
			{
				throw new AmbiguousMatchException(Environment.GetResourceString("Arg_AmbiguousMatchException"));
			}
			return array[num3];
		}