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)); }
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)); }
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); }
public IConstructorArgumentProperties GetConstructorArgumentProperties() { if (this.constructorArgumentProperties == null) { this.constructorArgumentProperties = PlatformTypeHelper.GetConstructorArgumentProperties(this); } return(this.constructorArgumentProperties); }
public IList <IConstructor> GetConstructors() { if (this.constructors == null) { this.constructors = PlatformTypeHelper.GetConstructors(this.platformTypes.DefaultTypeResolver, this); } return(this.constructors); }
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; }
public static IType GetFieldTypeId(ITypeResolver typeResolver, FieldInfo fieldInfo) { Type fieldType = PlatformTypeHelper.GetFieldType(fieldInfo); if (fieldType != (Type)null) { return(typeResolver.GetType(fieldType)); } return((IType)null); }
public static IType GetPropertyTypeId(ITypeResolver typeResolver, PropertyInfo propertyInfo) { Type propertyType = PlatformTypeHelper.GetPropertyType(propertyInfo); if (propertyType != (Type)null) { return(typeResolver.GetType(propertyType)); } return((IType)null); }
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); }
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); }
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); }
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)); }
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(); }
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); }
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); }
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); }
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); }
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); }
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); }
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)); }); }
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); }
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); }
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); }
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(); }
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; }
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)); }
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); }