Esempio n. 1
0
        public CommandResult Handle(object command)
        {
            var     handlerType = typeof(ICommandHandler <>).MakeGenericType(command.GetType());
            dynamic handler     = _typeResolver.GetType(handlerType);

            var result = handler.Handle((dynamic)command);

            return(result);
        }
Esempio n. 2
0
        public TResult Map <TResult>(object source)
        {
            if (source == null)
            {
                return(default(TResult));
            }

            var sourceType = typeResolver.GetType(source);
            var mapper     = context.Resolve(typeof(IMap <,>).MakeGenericType(sourceType, typeof(TResult)));

            return((TResult)mapper.GetType().GetMethod("Map", new[] { sourceType }).Invoke(mapper, new[] { source }));
        }
Esempio n. 3
0
        public IMember Clone(ITypeResolver typeResolver)
        {
            string name;
            string str;

            if (typeResolver == this.typeResolver)
            {
                return(this);
            }
            if (this.IsGenericType)
            {
                if (this.RuntimeType == null)
                {
                    return(null);
                }
                return(typeResolver.GetType(this.RuntimeType));
            }
            if (this.xmlNamespace != null)
            {
                return(typeResolver.GetType(this.xmlNamespace, this.Name));
            }
            if (this.typeResolver.ProjectAssembly != null)
            {
                name = this.typeResolver.ProjectAssembly.Name;
            }
            else
            {
                name = null;
            }
            string str1 = name;

            if (typeResolver.ProjectAssembly != null)
            {
                str = typeResolver.ProjectAssembly.Name;
            }
            else
            {
                str = null;
            }
            string str2 = str;
            string str3 = (this.assemblyName == null ? str1 : this.assemblyName);

            if (str2 == str3)
            {
                str3 = null;
            }
            return(typeResolver.GetType(str3, TypeHelper.CombineNamespaceAndTypeName(this.Namespace, this.Name)));
        }
        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 ReadOnlyCollection <DefaultStateRecord> GetDefaultStateRecords(IType controlType, ITypeResolver typeResolver)
        {
            List <DefaultStateRecord> list = new List <DefaultStateRecord>();

            if (controlType == null || typeResolver == null || (typeResolver.PlatformMetadata.IsNullType((ITypeId)controlType) || typeResolver.PlatformMetadata.IsNullType((ITypeId)typeResolver.ResolveType(ProjectNeutralTypes.VisualStateManager))))
            {
                return(new ReadOnlyCollection <DefaultStateRecord>((IList <DefaultStateRecord>)list));
            }
            foreach (Attribute attribute in TypeUtilities.GetAttributes(controlType.RuntimeType))
            {
                Type  type1 = attribute.GetType();
                IType type2 = typeResolver.GetType(type1);
                if (!typeResolver.PlatformMetadata.IsNullType((ITypeId)type2) && ProjectNeutralTypes.TemplateVisualStateAttribute.IsAssignableFrom((ITypeId)type2))
                {
                    DefaultStateRecord defaultStateRecord = new DefaultStateRecord();
                    PropertyInfo       property1          = type1.GetProperty("Name");
                    defaultStateRecord.StateName = property1.GetValue((object)attribute, (object[])null) as string;
                    PropertyInfo property2 = type1.GetProperty("GroupName");
                    defaultStateRecord.GroupName = property2.GetValue((object)attribute, (object[])null) as string;
                    if (!string.IsNullOrEmpty(defaultStateRecord.StateName) && !string.IsNullOrEmpty(defaultStateRecord.GroupName))
                    {
                        list.Add(defaultStateRecord);
                    }
                }
            }
            return(new ReadOnlyCollection <DefaultStateRecord>((IList <DefaultStateRecord>)list));
        }
Esempio n. 6
0
        internal static IType GetTypeId(ITypeResolver typeResolver, ClrNamespaceUriParseCache documentNamespaces, XmlNamespace xmlNamespace, string typeName, bool instantiateUnrecognizedTypes, bool inMarkupExtension)
        {
            IType designTimeType = typeResolver.PlatformMetadata.GetDesignTimeType(typeResolver, (IXmlNamespace)xmlNamespace, typeName);

            if (designTimeType != null)
            {
                return(designTimeType);
            }
            AssemblyNamespace assemblyNamespace;

            documentNamespaces.GetNamespace((IXmlNamespace)xmlNamespace, out assemblyNamespace);
            IType type;

            if (assemblyNamespace != null)
            {
                type = XamlTypeHelper.ResolveType(typeResolver, (IXmlNamespaceTypeResolver)documentNamespaces, xmlNamespace, typeName, inMarkupExtension);
                if (type == null && instantiateUnrecognizedTypes)
                {
                    IAssembly assembly     = assemblyNamespace.Assembly;
                    string    clrNamespace = assemblyNamespace.ClrNamespace;
                    type = typeResolver.GetType(assembly.Name, TypeHelper.CombineNamespaceAndTypeName(clrNamespace, typeName)) ?? typeResolver.PlatformMetadata.CreateUnknownType(typeResolver, assembly, clrNamespace, typeName);
                }
            }
            else
            {
                type = XamlTypeHelper.ResolveType(typeResolver, typeResolver.ProjectNamespaces, xmlNamespace, typeName, inMarkupExtension);
                if (type == null && instantiateUnrecognizedTypes)
                {
                    type = typeResolver.PlatformMetadata.CreateUnknownType(typeResolver, (IXmlNamespace)xmlNamespace, typeName);
                }
            }
            return(type);
        }
Esempio n. 7
0
        /// <summary>
        /// Registers the default implementation for the given interface <paramref name="implementationTypeName"/>
        /// so that <see cref="CreateGrain{TInterface}(object[])"/> can be used.
        /// </summary>
        /// <typeparam name="TInterface"></typeparam>
        public void RegisterDefaultImplementation <TInterface>(string implementationTypeName)
            where TInterface : class
        {
            Type implementationType;

            if (_customTypeResolver != null)
            {
                implementationType = _customTypeResolver.GetType(implementationTypeName);
            }
            else
            {
                implementationType = TypeResolver.GetType(implementationTypeName);
            }

            _registry.RegisterDefaultImplementation(implementationType, typeof(TInterface));
        }
        public QualifiedType Add(GenericName identifier, ITypeResolver resolver)
        {
            var type = Type;

            if (type != null)
            {
                throw new InvalidOperationException("Cannot further qualify an existing type.");
            }

            var typeArguments = identifier.TypeArguments;
            var typeName      = TypeName != null ? TypeName + "." + identifier.Name : identifier.Name;

            if (typeArguments != Type.EmptyTypes)
            {
                typeName += "`" + typeArguments.Length;
            }

            type = resolver.GetType(typeName);
            if (typeArguments != Type.EmptyTypes)
            {
                type = type.MakeGenericType(typeArguments);
            }

            return(new QualifiedType(type, typeName));
        }
        private IDocumentNodePropertyBuilder GetDefaultHandler(ITypeResolver typeResolver, Type type)
        {
            IDocumentNodePropertyBuilder documentNodePropertyBuilder;

            base.InitializeIfNecessary();
            IType type1 = typeResolver.GetType(type);

            if (type1 != null)
            {
                if (type.IsValueType && type1.TypeConverter != null && !PlatformTypes.TypeConverter.Equals(typeResolver.GetType(type1.TypeConverter.GetType())))
                {
                    return(null);
                }
                MemberAccessTypes allowableMemberAccess = TypeHelper.GetAllowableMemberAccess(typeResolver, type1);
                using (IEnumerator <IProperty> enumerator = type1.Metadata.Properties.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        IProperty current = enumerator.Current;
                        if (!current.ShouldSerialize || !TypeHelper.IsSet(allowableMemberAccess, current.WriteAccess) && current.PropertyType.ItemType == null)
                        {
                            continue;
                        }
                        documentNodePropertyBuilder = this.defaultPropertyBuilder;
                        return(documentNodePropertyBuilder);
                    }
                    return(null);
                }
                return(documentNodePropertyBuilder);
            }
            return(null);
        }
Esempio n. 10
0
        private Type ReadTypeInformation(BinaryReader reader)
        {
            var typeName = ReadValueAsString(reader);
            var type     = _typeResolver?.GetType(typeName) ?? Type.GetType(typeName);

            return(type);
        }
Esempio n. 11
0
 private void LogContainerInitialization()
 {
     _logger.LogDebugDetails(BootstrapLogEvents.BOOTSTRAP_INITIALIZE, "Container Setup", new
     {
         TypeResolver = _typeResover.GetType(),
         Configs      = _configs.Keys.Select(ct => ct.AssemblyQualifiedName)
     });
 }
Esempio n. 12
0
 public IMember Clone(ITypeResolver typeResolver)
 {
     if (this.PlatformMetadata == typeResolver.PlatformMetadata)
     {
         return(this);
     }
     return(typeResolver.GetType(this.type));
 }
Esempio n. 13
0
        public T Handle <T>(IQuery <T> query)
        {
            var     handlerType = typeof(IQueryHandler <,>).MakeGenericType(query.GetType(), typeof(T));
            dynamic handler     = _typeResolver.GetType(handlerType);

            var result = handler.Handle((dynamic)query);

            return(result);
        }
Esempio n. 14
0
        private Type GetType(string assemblyQualifiedName)
        {
            if (_customTypeResolver != null)
            {
                return(_customTypeResolver.GetType(assemblyQualifiedName));
            }

            return(TypeResolver.GetType(assemblyQualifiedName));
        }
Esempio n. 15
0
        public static bool IsAccessibleType(ITypeResolver typeResolver, Type type)
        {
            IType type1 = typeResolver.GetType(type);

            if (type1 != null)
            {
                return(TypeHelper.IsAccessibleType(typeResolver, type1));
            }
            return(false);
        }
Esempio n. 16
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);
        }
Esempio n. 17
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);
        }
Esempio n. 18
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);
        }
Esempio n. 19
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);
 }
Esempio n. 20
0
        private static IType GetItemType(ITypeResolver typeResolver, Type type)
        {
            CollectionAdapterDescription adapterDescription = CollectionAdapterDescription.GetAdapterDescription(type);
            IType type1 = null;

            if (adapterDescription != null)
            {
                type1 = typeResolver.GetType(adapterDescription.ItemType);
            }
            return(type1);
        }
Esempio n. 21
0
        private Type ResolveTypeName(string typeName)
        {
            Type type;

            if (TypeNameTobuiltInType.TryGetValue(typeName, out type))
            {
                return(type);
            }

            type = _typeResolver?.GetType(typeName) ?? Type.GetType(typeName);
            return(type);
        }
        protected virtual DocumentCompositeNode CreateCompositeNode(IDocumentContext documentContext, Type instanceType, Type childType)
        {
            ITypeResolver typeResolver = documentContext.TypeResolver;
            IType         type         = typeResolver.GetType(instanceType);

            if (type == null || !TypeHelper.IsAccessibleType(typeResolver, type))
            {
                return(null);
            }
            IType type1 = null;

            if (childType != null)
            {
                type1 = typeResolver.GetType(childType);
                if (type1 == null || !TypeHelper.IsAccessibleType(typeResolver, type1))
                {
                    return(null);
                }
            }
            return(new DocumentCompositeNode(documentContext, type, type1));
        }
Esempio n. 23
0
        public static IEvent GetEvent(ITypeResolver typeResolver, Type targetType, string memberName)
        {
            IType type = typeResolver.GetType(targetType);

            if (type == null)
            {
                return((IEvent)null);
            }
            MemberAccessTypes allowableMemberAccess = TypeHelper.GetAllowableMemberAccess(typeResolver, type);

            return((IEvent)type.GetMember(MemberType.Event, memberName, allowableMemberAccess));
        }
Esempio n. 24
0
        public static IMemberId GetRoutedCommandMember(ITypeResolver typeResolver, Type type, string commandName)
        {
            IType type1 = typeResolver.GetType(type);

            if (type1 == null)
            {
                return((IMemberId)null);
            }
            MemberAccessTypes allowableMemberAccess = TypeHelper.GetAllowableMemberAccess(typeResolver, type1);

            return(type1.GetMember(MemberType.LocalProperty | MemberType.Field, commandName, allowableMemberAccess) ?? type1.GetMember(MemberType.LocalProperty | MemberType.Field, commandName + "Command", allowableMemberAccess));
        }
Esempio n. 25
0
        public static bool CanCreateTypeInXaml(ITypeResolver typeResolver, Type type)
        {
            IType type1 = typeResolver.GetType(type);

            if (typeResolver.PlatformMetadata.IsNullType(type1) || !TypeHelper.IsAccessibleType(typeResolver, type1) || Nullable.GetUnderlyingType(type) != null)
            {
                return(false);
            }
            if (type == typeof(string) || TypeUtilities.HasDefaultConstructor(type, typeResolver.InTargetAssembly(type1)))
            {
                return(true);
            }
            return(type1.TypeConverter.CanConvertFrom(typeof(string)));
        }
Esempio n. 26
0
 public IType GetType(ITypeResolver typeResolver, string typeName)
 {
     if (this.Assembly.IsLoaded)
     {
         string typeName1 = TypeHelper.CombineNamespaceAndTypeName(this.ClrNamespace, typeName);
         try
         {
             return(typeResolver.GetType(this.Assembly, typeName1));
         }
         catch (Exception ex)
         {
         }
     }
     return((IType)null);
 }
Esempio n. 27
0
        public static IEvent GetEvent(ITypeResolver typeResolver, RoutedEvent routedEvent)
        {
            IType type = typeResolver.GetType(routedEvent.OwnerType);

            if (type != null)
            {
                MemberAccessTypes allowableMemberAccess = TypeHelper.GetAllowableMemberAccess(typeResolver, type);
                Event             @event = (Event)type.GetMember(MemberType.Event, routedEvent.Name, allowableMemberAccess);
                if (@event != null && @event.RoutedEvent == routedEvent)
                {
                    return((IEvent)@event);
                }
            }
            return((IEvent)null);
        }
Esempio n. 28
0
        private static IList GetVisualStateGroups(object hostElement, ITypeResolver typeResolver)
        {
            IType type1 = typeResolver.ResolveType(ProjectNeutralTypes.VisualStateManager);

            typeResolver.ResolveType(ProjectNeutralTypes.VisualStateGroup);
            IType type2 = typeResolver.GetType(hostElement.GetType());

            if (!PlatformTypes.FrameworkElement.IsAssignableFrom((ITypeId)type2))
            {
                return((IList) new List <object>());
            }
            return(PlatformTypeHelper.GetMethod(type1.RuntimeType, "GetVisualStateGroups").Invoke(null, new object[1]
            {
                hostElement
            }) as IList);
        }
Esempio n. 29
0
        private static ReferenceStep GetContentProperty(ITypeResolver typeResolver, Type type, string propertyName)
        {
            IType type1 = typeResolver.GetType(type);

            if (type1 == null)
            {
                return(null);
            }
            MemberAccessTypes allowableMemberAccess = TypeHelper.GetAllowableMemberAccess(typeResolver, type1);

            if (PlatformTypes.UserControl.IsAssignableFrom(type1))
            {
                allowableMemberAccess = allowableMemberAccess | MemberAccessTypes.Protected;
            }
            return((ReferenceStep)type1.GetMember(MemberType.Property, propertyName, allowableMemberAccess));
        }
Esempio n. 30
0
        public static IEnumerable <PropertyInformation> GetPropertiesForType(Type objectType, ITypeResolver typeResolver)
        {
            IType type = typeResolver.GetType(objectType);

            if (type != null)
            {
                foreach (IProperty property in ITypeExtensions.GetProperties(type, MemberAccessTypes.PublicOrInternal, true))
                {
                    DependencyPropertyReferenceStep dependencyPropertyReferenceStep = property as DependencyPropertyReferenceStep;
                    if (dependencyPropertyReferenceStep != null)
                    {
                        yield return(new PropertyInformation(dependencyPropertyReferenceStep));
                    }
                }
            }
        }