コード例 #1
0
        public bool ShouldReflectProperty(IDesignTypeGeneratorContext context, BuildingTypeInfo typeInfo, PropertyInfo sourceProperty)
        {
            if (!this.IsSpecialCollection(typeInfo))
            {
                return(true);
            }
            PropertyInfo property = typeof(IList <>).GetProperty(sourceProperty.Name);

            if (property == null)
            {
                property = typeof(IList).GetProperty(sourceProperty.Name);
                if (property == null)
                {
                    return(true);
                }
            }
            if (sourceProperty.Name == "Items")
            {
                ParameterInfo[] indexParameters = property.GetIndexParameters();
                if ((int)indexParameters.Length != 1 || indexParameters[0].ParameterType != typeof(int))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
 public void OnTypeCloned(IDesignTypeGeneratorContext context, BuildingTypeInfo typeInfo)
 {
     if (this.IsSpecialCollection(typeInfo))
     {
         (new CollectionGenerator(this.platformMetadata, typeInfo)).EmitCollectionImplementation(context);
     }
 }
コード例 #3
0
 public bool ShouldReflectMethod(IDesignTypeGeneratorContext context, BuildingTypeInfo typeInfo, MethodInfo sourceMethod)
 {
     if (sourceMethod.Name == "Clear" && sourceMethod.ReturnType == typeof(void) && this.IsSpecialCollection(typeInfo) && (int)sourceMethod.GetParameters().Length == 0)
     {
         return(false);
     }
     return(true);
 }
コード例 #4
0
        public Type GetDesignType(IDesignTypeGeneratorContext context, Type runtimeType)
        {
            if (runtimeType == null)
            {
                return(runtimeType);
            }
            if (PlatformTypes.IsExpressionInteractiveType(runtimeType))
            {
                return(runtimeType);
            }
            if (runtimeType.IsPrimitive || runtimeType.IsGenericParameter)
            {
                return(runtimeType);
            }
            if (!this.IsCorePlatformType(runtimeType))
            {
                return(null);
            }
            Type replacementForPlatformType = this.GetReplacementForPlatformType(runtimeType);

            if (replacementForPlatformType != null)
            {
                return(replacementForPlatformType);
            }
            if (runtimeType.IsInterface)
            {
                return(null);
            }
            if (!runtimeType.IsGenericType)
            {
                if (runtimeType.IsArray && this.GetDesignType(context, DesignTypeGenerator.GetArrayItemType(runtimeType)) == null)
                {
                    return(null);
                }
                return(runtimeType);
            }
            Type[] genericArguments = runtimeType.GetGenericArguments();
            for (int i = 0; i < (int)genericArguments.Length; i++)
            {
                if (this.GetDesignType(context, genericArguments[i]) == null)
                {
                    return(null);
                }
            }
            return(runtimeType);
        }
コード例 #5
0
        private void InitializeItemType(IDesignTypeGeneratorContext context)
        {
            Type genericArguments = null;

            KeyValuePair <int, Type>[] keyValuePair      = new KeyValuePair <int, Type>[] { new KeyValuePair <int, Type>(0, this.platformMetadata.ResolveType(PlatformTypes.IListT).RuntimeType), new KeyValuePair <int, Type>(1, this.platformMetadata.ResolveType(PlatformTypes.ICollectionT).RuntimeType), new KeyValuePair <int, Type>(2, this.platformMetadata.ResolveType(PlatformTypes.IEnumerableT).RuntimeType) };
            KeyValuePair <int, Type>[] keyValuePairArray = keyValuePair;
            int length = (int)keyValuePairArray.Length;

            Type[] interfaces = this.sourceType.GetInterfaces();
            for (int i = 0; i < (int)interfaces.Length; i++)
            {
                Type type = interfaces[i];
                if (type.IsGenericType && !type.IsGenericTypeDefinition)
                {
                    Type genericTypeDefinition = type.GetGenericTypeDefinition();
                    for (int j = 0; j < length; j++)
                    {
                        if (genericTypeDefinition.Equals(keyValuePairArray[j].Value))
                        {
                            genericArguments = type.GetGenericArguments()[0];
                            if (genericArguments != typeof(object))
                            {
                                length = j;
                                break;
                            }
                        }
                    }
                    if (length == 0)
                    {
                        break;
                    }
                }
            }
            if (genericArguments == null)
            {
                this.itemType = typeof(object);
                return;
            }
            this.itemType = context.GetDesignType(genericArguments);
        }
コード例 #6
0
 public void OnPropertySet(IDesignTypeGeneratorContext context, TypeBuilder designTimeType, PropertyInfo propertyInfo, ILGenerator setMethod)
 {
 }
コード例 #7
0
 public void EmitCollectionImplementation(IDesignTypeGeneratorContext context)
 {
     this.InitializeItemType(context);
     this.CreateCollectionField();
     this.Emit();
 }