Ejemplo n.º 1
0
        public AdvTypeConverter()
        {
            Type t = typeof(TType);

            this.parse        = ParseMethodAttribute.GetParseMethod(t);
            this.descriptions = AdvBrowsableAttribute.GetDispMembers(t);
            if (descriptions != null)
            {
                this.instanceNoArgsCtor = t.GetConstructor(Type.EmptyTypes);
                this.instanceCtor       = InstanceConstructorAttribute.GetConstructor(t, out instanceCtorParamNames);
                if (this.instanceCtor != null)
                {
                    ParameterInfo[] paraminfos = instanceCtor.GetParameters();
                    if (paraminfos.Length == instanceCtorParamNames.Length)
                    {
                        for (int index = 0; index < instanceCtorParamNames.Length; ++index)
                        {
                            string             name       = instanceCtorParamNames[index];
                            PropertyDescriptor descriptor = descriptions.Find(name, false);
                            if (descriptor == null || descriptor.PropertyType != paraminfos[index].ParameterType)
                            {
                                instanceCtor = null;
                                break;
                            }
                        }
                    }
                    else
                    {
                        instanceCtor = null;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static ConstructorInfo GetConstructor(Type t, out string[] paramNames)
        {
            foreach (ConstructorInfo method in t.GetConstructors())
            {
                object[] atts = method.GetCustomAttributes(typeof(InstanceConstructorAttribute), true);

                if (atts.Length > 0)
                {
                    InstanceConstructorAttribute att = (InstanceConstructorAttribute)atts[0];
                    if (method.GetParameters().Length == att.ParameterNames.Length)
                    {
                        paramNames = att.ParameterNames;
                        return(method);
                    }
                }
            }
            paramNames = null;
            return(null);
        }
Ejemplo n.º 3
0
        public static ConstructorInfo GetConstructor(Type t, out string[] paramNames)
        {
            foreach (ConstructorInfo method in t.GetTypeInfo().DeclaredConstructors)
            {
                IEnumerable <Attribute> atts = method.GetCustomAttributes(typeof(InstanceConstructorAttribute), true);
                IEnumerator <Attribute> en   = atts.GetEnumerator();

                if (en.MoveNext())
                {
                    InstanceConstructorAttribute att = (InstanceConstructorAttribute)en.Current;
                    if (method.GetParameters().Length == att.ParameterNames.Length)
                    {
                        paramNames = att.ParameterNames;
                        return(method);
                    }
                }
            }
            paramNames = null;
            return(null);
        }