Ejemplo n.º 1
0
        private static MethodInfo GetMethod(Type type, string methodName, int numberOfArguments, BindingFlags bindingFlags)
        {
            MemberInfo[] member      = type.GetMember(methodName, MemberTypes.Method, bindingFlags);
            MethodInfo   methodInfo1 = (MethodInfo)null;

            foreach (MethodInfo methodInfo2 in member)
            {
                if (methodInfo2 != (MethodInfo)null)
                {
                    if (numberOfArguments >= 0)
                    {
                        ParameterInfo[] parameters = PlatformTypeHelper.GetParameters(methodInfo2);
                        if (parameters == null || parameters.Length != numberOfArguments)
                        {
                            continue;
                        }
                    }
                    if (methodInfo1 == (MethodInfo)null || methodInfo1.DeclaringType != methodInfo2.DeclaringType && methodInfo1.DeclaringType.IsAssignableFrom(methodInfo2.DeclaringType))
                    {
                        methodInfo1 = methodInfo2;
                    }
                }
            }
            return(methodInfo1);
        }
        public AttachedClrPropertyImplementation(IPlatformMetadata platformMetadata, string name, MethodInfo getMethod, MethodInfo setMethod) : base(platformMetadata)
        {
            Type valueType;
            Type type;

            if (getMethod == null && setMethod == null)
            {
                throw new ArgumentNullException();
            }
            this.name      = name;
            this.getMethod = getMethod;
            this.setMethod = setMethod;
            if (this.getMethod == null)
            {
                ParameterInfo[] parameters = this.setMethod.GetParameters();
                valueType = PlatformTypeHelper.GetValueType(parameters[0]);
                type      = PlatformTypeHelper.GetValueType(parameters[1]);
            }
            else
            {
                valueType = PlatformTypeHelper.GetValueType(this.getMethod.GetParameters()[0]);
                type      = PlatformTypeHelper.GetValueType(this.getMethod);
            }
            this.targetType = (valueType != null ? valueType : typeof(DependencyObject));
            this.valueType  = (type != null ? type : typeof(object));
            this.isResolved = type != null;
        }
        public static IndexedClrPropertyReferenceStep GetReferenceStep(ITypeResolver typeResolver, Type declaringType, int index, bool throwOnFailure)
        {
            Type[] typeArray = new Type[] { typeof(int) };
            string str       = "Item";

            System.Reflection.PropertyInfo property = declaringType.GetProperty(str, BindingFlags.Instance | BindingFlags.Public, null, null, typeArray, null);
            if (property == null)
            {
                if (typeof(IList).IsAssignableFrom(declaringType))
                {
                    property = typeof(IList).GetProperty(str, BindingFlags.Instance | BindingFlags.Public, null, null, typeArray, null);
                }
                if (property == null)
                {
                    if (throwOnFailure)
                    {
                        CultureInfo currentCulture = CultureInfo.CurrentCulture;
                        string      typeDoesNotDeclareAnIndexer = ExceptionStringTable.TypeDoesNotDeclareAnIndexer;
                        object[]    name = new object[] { declaringType.Name };
                        throw new ArgumentException(string.Format(currentCulture, typeDoesNotDeclareAnIndexer, name), "declaringType");
                    }
                    return(null);
                }
            }
            IType             type             = typeResolver.GetType(declaringType);
            IType             propertyTypeId   = PlatformTypeHelper.GetPropertyTypeId(typeResolver, property);
            IPlatformMetadata platformMetadata = typeResolver.PlatformMetadata;

            object[] objArray = new object[] { index };
            ClrPropertyImplementationBase localClrPropertyImplementation = new LocalClrPropertyImplementation(platformMetadata, property, null, objArray);

            return(new IndexedClrPropertyReferenceStep(type, str, propertyTypeId, localClrPropertyImplementation, index));
        }
Ejemplo n.º 4
0
 public static System.Type GetGenericCollectionType(System.Type type)
 {
     if (type == null)
     {
         return(null);
     }
     System.Type[] interfaces = PlatformTypeHelper.GetInterfaces(type);
     if (interfaces != null)
     {
         System.Type[] typeArray = interfaces;
         for (int i = 0; i < (int)typeArray.Length; i++)
         {
             System.Type genericCollectionTypeFromInterface = CollectionAdapterDescription.GetGenericCollectionTypeFromInterface(typeArray[i]);
             if (genericCollectionTypeFromInterface != null)
             {
                 return(genericCollectionTypeFromInterface);
             }
         }
     }
     if (!type.IsInterface)
     {
         return(null);
     }
     return(CollectionAdapterDescription.GetGenericCollectionTypeFromInterface(type));
 }
Ejemplo n.º 5
0
        public static IList <IConstructor> GetConstructors(ITypeResolver typeResolver, IType typeId)
        {
            Type runtimeType         = typeId.RuntimeType;
            List <IConstructor> list = (List <IConstructor>)null;

            if (runtimeType != (Type)null)
            {
                ConstructorInfo[] constructors = PlatformTypeHelper.GetConstructors(runtimeType);
                if (constructors != null && constructors.Length > 0)
                {
                    foreach (ConstructorInfo constructorInfo in constructors)
                    {
                        if (PlatformTypeHelper.IsAccessibleConstructor(constructorInfo))
                        {
                            if (list == null)
                            {
                                list = new List <IConstructor>(constructors.Length);
                            }
                            list.Add((IConstructor) new Constructor(typeResolver, typeId, constructorInfo, PlatformTypeHelper.GetNameWithParameters((MethodBase)constructorInfo)));
                        }
                    }
                }
            }
            if (list != null)
            {
                return((IList <IConstructor>) new ReadOnlyCollection <IConstructor>((IList <IConstructor>)list));
            }
            return((IList <IConstructor>)ReadOnlyCollections <IConstructor> .Empty);
        }
Ejemplo n.º 6
0
 public IConstructorArgumentProperties GetConstructorArgumentProperties()
 {
     if (this.constructorArgumentProperties == null)
     {
         this.constructorArgumentProperties = PlatformTypeHelper.GetConstructorArgumentProperties(this);
     }
     return(this.constructorArgumentProperties);
 }
Ejemplo n.º 7
0
 public IList <IConstructor> GetConstructors()
 {
     if (this.constructors == null)
     {
         this.constructors = PlatformTypeHelper.GetConstructors(this.platformTypes.DefaultTypeResolver, this);
     }
     return(this.constructors);
 }
Ejemplo n.º 8
0
 public IList <IType> GetGenericTypeArguments()
 {
     if (this.genericTypeArguments == null)
     {
         this.genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(this.platformTypes.DefaultTypeResolver, this.type);
     }
     return(this.genericTypeArguments);
 }
 public LocalClrPropertyImplementation(IPlatformMetadata platformMetadata, System.Reflection.PropertyInfo propertyInfo, Type declaringType, object[] indexParameters) : base(platformMetadata)
 {
     this.declaringType   = declaringType ?? propertyInfo.DeclaringType;
     this.propertyInfo    = propertyInfo;
     this.getMethod       = this.propertyInfo.GetGetMethod(true);
     this.setMethod       = this.propertyInfo.GetSetMethod(true);
     this.indexParameters = indexParameters;
     this.isResolved      = PlatformTypeHelper.GetPropertyType(this.propertyInfo) != null;
 }
Ejemplo n.º 10
0
        public static IType GetFieldTypeId(ITypeResolver typeResolver, FieldInfo fieldInfo)
        {
            Type fieldType = PlatformTypeHelper.GetFieldType(fieldInfo);

            if (fieldType != (Type)null)
            {
                return(typeResolver.GetType(fieldType));
            }
            return((IType)null);
        }
Ejemplo n.º 11
0
        public static IType GetPropertyTypeId(ITypeResolver typeResolver, PropertyInfo propertyInfo)
        {
            Type propertyType = PlatformTypeHelper.GetPropertyType(propertyInfo);

            if (propertyType != (Type)null)
            {
                return(typeResolver.GetType(propertyType));
            }
            return((IType)null);
        }
Ejemplo n.º 12
0
 bool Microsoft.Expression.DesignModel.Metadata.ICachedMemberInfo.Refresh()
 {
     System.Reflection.MethodInfo method = PlatformTypeHelper.GetMethod(base.DeclaringType.NearestResolvedType.RuntimeType, this.Name);
     if (method == null)
     {
         return(false);
     }
     this.Initialize(method);
     return(true);
 }
Ejemplo n.º 13
0
        internal static Type GetType(IAssembly assembly, string typeName)
        {
            Assembly reflectionAssembly = AssemblyHelper.GetReflectionAssembly(assembly);

            if (reflectionAssembly != (Assembly)null)
            {
                return(PlatformTypeHelper.GetType(reflectionAssembly, typeName));
            }
            return((Type)null);
        }
Ejemplo n.º 14
0
        internal static IType GetType(ITypeResolver typeResolver, IAssembly assembly, string typeName)
        {
            Type type = PlatformTypeHelper.GetType(assembly, typeName);

            if (type != (Type)null)
            {
                return(typeResolver.GetType(type));
            }
            return((IType)null);
        }
Ejemplo n.º 15
0
        public static KeyValuePair <bool, object> GetDefaultValue(PlatformTypes platformTypes, MemberInfo memberInfo, Type valueType)
        {
            object result;

            if (PlatformNeutralAttributeHelper.TryGetAttributeValue <object>((IEnumerable)platformTypes.GetCustomAttributes(memberInfo), PlatformTypes.DefaultValueAttribute, "Value", out result) && (!valueType.IsValueType && (result == null || valueType.IsAssignableFrom(result.GetType())) || valueType.IsValueType && result != null && valueType.IsAssignableFrom(result.GetType())))
            {
                return(new KeyValuePair <bool, object>(true, result));
            }
            return(PlatformTypeHelper.GetDefaultValue(valueType));
        }
Ejemplo n.º 16
0
        public void Initialize(IXmlNamespace xmlNamespace, Type type, string key)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            PlatformTypes platformMetadata = (PlatformTypes)this.PlatformMetadata;

            this.isBuilt      = true;
            this.xmlNamespace = xmlNamespace;
            this.type         = type;
            Type nearestSupportedType = platformMetadata.GetNearestSupportedType(this.type);

            if (nearestSupportedType != null)
            {
                this.nearestSupportedType = platformMetadata.GetType(nearestSupportedType);
            }
            this.lastResolvedType = this.type;
            this.name             = ProjectContextType.GetNameIncludingAnyDeclaringTypes(this.type);
            Assembly  assembly        = this.type.Assembly;
            IAssembly projectAssembly = this.typeResolver.ProjectAssembly;

            if (projectAssembly == null || !projectAssembly.CompareTo(assembly))
            {
                this.assemblyName = AssemblyHelper.GetAssemblyName(assembly).Name;
                if (projectAssembly != null)
                {
                    bool name = this.assemblyName == projectAssembly.Name;
                }
            }
            this.members  = new MemberCollection(this.typeResolver, this);
            this.assembly = this.GetAssembly(this.typeResolver, this.assemblyName);
            if (type.IsArray)
            {
                this.arrayItemType = ProjectContextType.GetItemType(this.typeResolver, type);
                this.arrayRank     = type.GetArrayRank();
            }
            this.genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(this.typeResolver, this.type);
            if (this.genericTypeArguments.Count > 0)
            {
                foreach (IType genericTypeArgument in this.genericTypeArguments)
                {
                    ProjectContextType projectContextType = genericTypeArgument as ProjectContextType;
                    if (projectContextType == null)
                    {
                        continue;
                    }
                    this.genericDepth = Math.Max(projectContextType.genericDepth + 1, this.genericDepth);
                }
            }
            this.Cache();
            this.hashCode = key.GetHashCode();
        }
Ejemplo n.º 17
0
 public AttachedEventImplementation(string name, MethodInfo addMethod)
 {
     this.name      = name;
     this.addMethod = addMethod;
     ParameterInfo[] parameters = PlatformTypeHelper.GetParameters(this.addMethod);
     if (parameters != null && (int)parameters.Length == 2)
     {
         this.targetType  = parameters[0].ParameterType;
         this.handlerType = parameters[1].ParameterType;
     }
     this.access = PlatformTypeHelper.GetMemberAccess(this.addMethod);
 }
Ejemplo n.º 18
0
 private static System.Type GetGenericCollectionTypeFromInterface(System.Type type)
 {
     System.Type genericTypeDefinition = PlatformTypeHelper.GetGenericTypeDefinition(type);
     if (genericTypeDefinition != null && typeof(ICollection <>).IsAssignableFrom(genericTypeDefinition))
     {
         System.Type[] genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(type);
         if (genericTypeArguments != null)
         {
             return(genericTypeArguments[0]);
         }
     }
     return(null);
 }
Ejemplo n.º 19
0
 bool Microsoft.Expression.DesignModel.Metadata.ICachedMemberInfo.Refresh()
 {
     System.Reflection.FieldInfo fieldInfo = PlatformTypeHelper.GetFieldInfo(base.DeclaringType.NearestResolvedType.RuntimeType, this.Name);
     if (fieldInfo == null)
     {
         this.implementation = FieldReferenceStep.UndefinedFieldImplementation.Instance;
     }
     else
     {
         this.implementation = new FieldReferenceStep.FieldImplementation(this, fieldInfo);
     }
     return(this.implementation.IsResolved);
 }
Ejemplo n.º 20
0
        public static bool HasDefaultConstructor(Type type, bool supportInternal)
        {
            ConstructorAccessibility constructorAccessibility;

            PlatformTypeHelper.GetDefaultConstructor(type, supportInternal, out constructorAccessibility);
            ConstructorAccessibility constructorAccessibility1 = constructorAccessibility;

            if (constructorAccessibility1 != ConstructorAccessibility.Accessible && constructorAccessibility1 != ConstructorAccessibility.TypeIsValueType)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 21
0
 public static bool HasUnboundTypeArguments(Type type)
 {
     if (type.IsGenericType)
     {
         foreach (Type type1 in PlatformTypeHelper.GetGenericTypeArguments(type))
         {
             if (type1.IsGenericParameter || PlatformTypeHelper.HasUnboundTypeArguments(type1))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 22
0
        public static Type GetNullableType(Type type)
        {
            Type genericTypeDefinition = PlatformTypeHelper.GetGenericTypeDefinition(type);

            if (genericTypeDefinition != (Type)null && typeof(Nullable <>).IsAssignableFrom(genericTypeDefinition))
            {
                Type[] genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(type);
                if (genericTypeArguments != null && genericTypeArguments.Length == 1)
                {
                    return(genericTypeArguments[0]);
                }
            }
            return((Type)null);
        }
Ejemplo n.º 23
0
 public FieldImplementation(FieldReferenceStep referenceStep, System.Reflection.FieldInfo fieldInfo)
 {
     this.referenceStep           = referenceStep;
     this.fieldInfo               = fieldInfo;
     this.isResolved              = PlatformTypeHelper.GetFieldType(this.fieldInfo) != null;
     this.serializationVisibility = new DelayedInstance <DesignerSerializationVisibility>(() => PlatformTypeHelper.GetSerializationVisibility(this.PlatformTypes, this.fieldInfo));
     this.defaultValue            = new DelayedInstance <KeyValuePair <bool, object> >(() => {
         Type fieldType = PlatformTypeHelper.GetFieldType(this.fieldInfo);
         if (fieldType == null)
         {
             return(new KeyValuePair <bool, object>(false, null));
         }
         return(PlatformTypeHelper.GetDefaultValue(this.PlatformTypes, this.fieldInfo, fieldType));
     });
 }
Ejemplo n.º 24
0
 private static ConstructorInfo GetConstructor(Type type, IList <IParameter> arguments)
 {
     ConstructorInfo[] constructors = PlatformTypeHelper.GetConstructors(type);
     if (constructors != null && (int)constructors.Length > 0)
     {
         ConstructorInfo[] constructorInfoArray = constructors;
         for (int i = 0; i < (int)constructorInfoArray.Length; i++)
         {
             ConstructorInfo constructorInfo = constructorInfoArray[i];
             if ((int)constructorInfo.GetParameters().Length == arguments.Count)
             {
                 return(constructorInfo);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 25
0
 public static IList <IType> GetGenericTypeArguments(ITypeResolver typeResolver, Type type)
 {
     if (type != (Type)null && type.IsGenericType)
     {
         Type[] genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(type);
         if (genericTypeArguments != null)
         {
             List <IType> list = new List <IType>(genericTypeArguments.Length);
             foreach (Type type1 in genericTypeArguments)
             {
                 IType type2 = typeResolver.GetType(type1);
                 list.Add(type2);
             }
             return((IList <IType>) new ReadOnlyCollection <IType>((IList <IType>)list));
         }
     }
     return((IList <IType>)ReadOnlyCollections <IType> .Empty);
 }
Ejemplo n.º 26
0
        protected virtual IList <IPropertyId> GetStyleProperties()
        {
            IList <IPropertyId> propertyIds = new List <IPropertyId>();
            Type runtimeType = null;

            foreach (IProperty property in this.Properties)
            {
                if (runtimeType == null)
                {
                    runtimeType = property.DeclaringType.PlatformMetadata.ResolveType(PlatformTypes.Style).RuntimeType;
                }
                if (!runtimeType.IsAssignableFrom(PlatformTypeHelper.GetPropertyType(property)))
                {
                    continue;
                }
                propertyIds.Add(property);
            }
            return(propertyIds);
        }
Ejemplo n.º 27
0
 public void Initialize(UnbuiltTypeDescription typeInfo, string key)
 {
     this.isBuilt             = false;
     this.baseType            = this.typeResolver.ResolveType(typeInfo.BaseType);
     this.type                = this.baseType.RuntimeType;
     this.xmlNamespace        = typeInfo.XmlNamespace;
     this.name                = typeInfo.TypeName;
     this.unbuiltClrNamespace = typeInfo.ClrNamespace;
     this.assembly            = typeInfo.AssemblyReference;
     if (this.assembly != this.typeResolver.ProjectAssembly)
     {
         this.assemblyName = this.assembly.Name;
     }
     this.lastResolvedType     = this.type;
     this.members              = new MemberCollection(this.typeResolver, this);
     this.genericTypeArguments = PlatformTypeHelper.GetGenericTypeArguments(this.typeResolver, null);
     this.Cache();
     this.hashCode = key.GetHashCode();
 }
Ejemplo n.º 28
0
			public Type GetType(string typeName)
			{
				Type type;
				Type type1 = null;
				if (this.typeNameCache.TryGetValue(typeName, out type1))
				{
					return type1;
				}
				using (IEnumerator<XmlnsDefinitionMap.AssemblyNamespace> enumerator = this.AssemblyNamespaces.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						XmlnsDefinitionMap.AssemblyNamespace current = enumerator.Current;
						IAssembly assembly = current.Assembly;
						string str = TypeHelper.CombineNamespaceAndTypeName(current.ClrNamespace, typeName);
						try
						{
							type1 = PlatformTypeHelper.GetType(assembly, str);
							if (type1 != null)
							{
								IType type2 = this.typeResolver.GetType(type1);
								if (!this.typeResolver.PlatformMetadata.IsNullType(type2))
								{
									if (TypeHelper.IsSet((assembly.CompareTo(this.targetAssembly) ? MemberAccessTypes.PublicOrInternal : MemberAccessTypes.Public), PlatformTypeHelper.GetMemberAccess(type1)))
									{
										this.typeNameCache.Add(typeName, type1);
										type = type1;
										return type;
									}
								}
							}
						}
						catch (ArgumentException argumentException)
						{
							type = null;
							return type;
						}
					}
					this.typeNameCache.Add(typeName, null);
					return null;
				}
				return type;
			}
Ejemplo n.º 29
0
        public IType GetType(string assemblyName, string typeName)
        {
            if (string.IsNullOrEmpty(assemblyName))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentException(ExceptionStringTable.GetTypeCannotBeCalledWithNullOrEmptyTypeName, "typeName");
            }
            IAssembly platformAssembly = this.platformTypes.GetPlatformAssembly(assemblyName);
            Type      type             = PlatformTypeHelper.GetType(platformAssembly, typeName);

            if (type == null)
            {
                return(null);
            }
            return(this.platformTypes.GetType(type));
        }
Ejemplo n.º 30
0
 internal static IMember GetMember(ITypeResolver typeResolver, Type type, MemberType memberTypes, string memberName)
 {
     if (TypeHelper.IsSet(memberTypes, MemberType.Property))
     {
         ITypeId   typeId   = (ITypeId)typeResolver.GetType(type);
         IProperty property = (IProperty)PlatformTypeHelper.GetProperty(typeResolver, typeId, memberTypes & MemberType.Property, memberName);
         if (property != null)
         {
             return((IMember)property);
         }
     }
     if (TypeHelper.IsSet(memberTypes, MemberType.Event))
     {
         IEvent @event = PlatformTypeHelper.GetEvent(typeResolver, type, memberName);
         if (@event != null)
         {
             return((IMember)@event);
         }
     }
     if (TypeHelper.IsSet(memberTypes, MemberType.Field))
     {
         FieldInfo fieldInfo = PlatformTypeHelper.GetFieldInfo(type, memberName);
         if (fieldInfo != (FieldInfo)null)
         {
             return((IMember)FieldReferenceStep.GetReferenceStep(typeResolver, fieldInfo));
         }
     }
     if (TypeHelper.IsSet(memberTypes, MemberType.Method))
     {
         MethodInfo method = PlatformTypeHelper.GetMethod(type, memberName);
         if (method != (MethodInfo)null)
         {
             IType type1 = typeResolver.GetType(method.DeclaringType);
             if (type1 == null)
             {
                 return((IMember)null);
             }
             return((IMember)Method.GetMethod(typeResolver, type1, method));
         }
     }
     return((IMember)null);
 }