Jypeli 10
The simple game programming library
InstanceConstructorAttribute.cs
Siirry tämän tiedoston dokumentaatioon.
1#region MIT License
2/*
3 * Copyright (c) 2005-2008 Jonathan Mark Porter. http://physics2d.googlepages.com/
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22#endregion
23
24
25
26
27using System;
28using System.Reflection;
29
30namespace AdvanceMath.Design
31{
32 [global::System.AttributeUsage(AttributeTargets.Constructor, Inherited = false, AllowMultiple = false)]
33 public sealed class InstanceConstructorAttribute : Attribute
34 {
36
37
38
40 {
41 this.parameterNames = parameterNames.Split(',');
42 }
43 public string[] ParameterNames
44 {
45 get { return parameterNames; }
46 }
47
48#if !WINDOWS_STOREAPP
49 public static ConstructorInfo GetConstructor(Type t, out string[] paramNames)
50 {
51 foreach (ConstructorInfo method in t.GetConstructors())
52 {
53 object[] atts = method.GetCustomAttributes(typeof(InstanceConstructorAttribute), true);
54
55 if (atts.Length > 0)
56 {
58 if (method.GetParameters().Length == att.ParameterNames.Length)
59 {
60 paramNames = att.ParameterNames;
61 return method;
62 }
63 }
64 }
65 paramNames = null;
66 return null;
67 }
68#else
69 public static ConstructorInfo GetConstructor(Type t, out string[] paramNames)
70 {
71 foreach (ConstructorInfo method in t.GetTypeInfo().DeclaredConstructors)
72 {
73 IEnumerable<Attribute> atts = method.GetCustomAttributes(typeof(InstanceConstructorAttribute), true);
74 IEnumerator<Attribute> en = atts.GetEnumerator();
75
76 if ( en.MoveNext() )
77 {
79 if (method.GetParameters().Length == att.ParameterNames.Length)
80 {
81 paramNames = att.ParameterNames;
82 return method;
83 }
84 }
85 }
86 paramNames = null;
87 return null;
88 }
89#endif
90 }
91}
static ConstructorInfo GetConstructor(Type t, out string[] paramNames)