コード例 #1
0
 protected ModelMethodParameter(ModelMethod method, string name, Type parameterType, ModelType referenceType, bool isList)
 {
     this.Method        = method;
     this.Name          = name;
     this.ParameterType = parameterType;
     this.ReferenceType = referenceType;
     this.IsList        = isList;
 }
コード例 #2
0
 protected internal ReflectionModelMethodParameter(ModelMethod method, string name, Type parameterType, ModelType referenceType, bool isList)
     : base(method, name, parameterType, referenceType, isList)
 {
 }
コード例 #3
0
            protected internal override void OnInit()
            {
                ReflectionModelTypeProvider provider = (ReflectionModelTypeProvider)Provider;

                Type listItemType;

                // Determine if any inherited properties on the type have been replaced using the new keyword
                Dictionary <string, bool> isNewProperty = new Dictionary <string, bool>();

                foreach (PropertyInfo property in UnderlyingType.GetProperties())
                {
                    isNewProperty[property.Name] = isNewProperty.ContainsKey(property.Name);
                }

                // Process all properties on the instance type to create references.  Process static properties
                // last since they would otherwise complicate calculated indexes when dealing with sub types.
                foreach (PropertyInfo property in GetEligibleProperties().OrderBy(p => (p.GetGetMethod(true) ?? p.GetSetMethod(true)).IsStatic).ThenBy(p => p.Name))
                {
                    // Exit immediately if the property was not in the list of valid declaring types
                    if (ModelContext.Current.GetModelType(property.DeclaringType) == null || (isNewProperty[property.Name] && property.DeclaringType != UnderlyingType))
                    {
                        continue;
                    }

                    ModelType referenceType;

                    // Copy properties inherited from base model types
                    if (BaseType != null && BaseType.Properties.Contains(property.Name) && !(isNewProperty[property.Name] || property.GetGetMethod().IsStatic))
                    {
                        AddProperty(BaseType.Properties[property.Name]);
                    }

                    // Create references based on properties that relate to other instance types
                    else if ((referenceType = Context.GetModelType(property.PropertyType)) != null)
                    {
                        var format    = property.GetCustomAttributes(true).OfType <ModelFormatAttribute>().Select(a => a.Format).FirstOrDefault();
                        var reference = provider.CreateReferenceProperty(this, property, property.Name, null, null, format, property.GetGetMethod().IsStatic, referenceType, false, property.GetSetMethod() == null, property.GetSetMethod() != null, property.GetCustomAttributes(true).Cast <Attribute>().ToArray());
                        if (reference != null)
                        {
                            AddProperty(reference);
                        }
                    }

                    else if (TryGetListItemType(property.PropertyType, out listItemType))
                    {
                        if ((referenceType = Context.GetModelType(listItemType)) != null)
                        {
                            // Create references based on properties that are lists of other instance types
                            var format    = property.GetCustomAttributes(true).OfType <ModelFormatAttribute>().Select(a => a.Format).FirstOrDefault();
                            var reference = provider.CreateReferenceProperty(this, property, property.Name, null, null, format, property.GetGetMethod().IsStatic, referenceType, true, false, true, property.GetCustomAttributes(true).Cast <Attribute>().ToArray());
                            if (reference != null)
                            {
                                AddProperty(reference);
                            }
                        }
                        else
                        {
                            // Create references based on properties that are lists of values
                            // TODO: Should the property type be 'listItemType'?
                            var value = provider.CreateValueProperty(this, property, property.Name, null, null, null, property.GetGetMethod().IsStatic, property.PropertyType, TypeDescriptor.GetConverter(listItemType), true, false, true, property.GetCustomAttributes(true).Cast <Attribute>().ToArray());
                            if (value != null)
                            {
                                AddProperty(value);
                            }
                        }
                    }

                    // Create values for all other properties
                    else
                    {
                        var value = provider.CreateValueProperty(this, property, property.Name, null, null, null, property.GetGetMethod().IsStatic, property.PropertyType, TypeDescriptor.GetConverter(property.PropertyType), false, property.GetSetMethod() == null, property.GetSetMethod() != null, property.GetCustomAttributes(true).Cast <Attribute>().ToArray());
                        if (value != null)
                        {
                            AddProperty(value);
                        }
                    }
                }

                // Process all public methods on the underlying type
                foreach (MethodInfo method in UnderlyingType.GetMethods()
                         .Where(method => !method.IsSpecialName && method.Name != "ToString" && (method.DeclaringType == UnderlyingType || (BaseType != null && BaseType.Methods.Contains(method.Name))))
                         .OrderBy(method => method.Name)
                         .ThenBy(method => method.GetParameters().Length))
                {
                    ModelMethod gm = provider.CreateMethod(this, method, method.Name, method.IsStatic, method.GetCustomAttributes(true).Cast <Attribute>().ToArray());
                    if (gm != null)
                    {
                        AddMethod(gm);
                    }
                }

                // Force all subtypes to load too
                foreach (Type subType in provider.supportedTypes.Where(t => t.IsSubclassOf(UnderlyingType)))
                {
                    Context.GetModelType(subType);
                }
            }