Exemplo n.º 1
0
        public TypeMetadata(Type type)
        {
            TypeEnum = TypeEnumFactory.CreateTypeMetadataClass(type);

            FullTypeName     = type.FullName;
            TypeName         = type.Name;
            NamespaceName    = type.Namespace;
            GenericArguments = !type.IsGenericTypeDefinition && !type.IsConstructedGenericType ? null : EmitGenericArguments(type.GetGenericArguments());
            Modifiers        = EmitModifiers(type);
            Attributes       = AttributeMetadata.EmitAttributes(type);

            DeclaringType = EmitDeclaringType(type.DeclaringType);

            BaseType = EmitExtends(type.BaseType);
            ImplementedInterfaces = EmitImplements(type.GetInterfaces());

            BindingFlags flagsToGetAll = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;

            Fields       = FieldMetadata.EmitFields(type.GetFields(flagsToGetAll));
            Methods      = MethodMetadata.EmitMethods(type.GetMethods(flagsToGetAll));
            Properties   = PropertyMetadata.EmitProperties(type.GetProperties(flagsToGetAll));
            Indexers     = IndexerMetadata.EmitIndexers(type.GetProperties(flagsToGetAll));
            Events       = EventMetadata.EmitEvents(type.GetEvents(flagsToGetAll));
            Constructors = ConstructorMetadata.EmitConstructors(type.GetConstructors(flagsToGetAll));
            NestedTypes  = EmitNestedTypes(type.GetNestedTypes(flagsToGetAll));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the metadata for the properties of a type.
        /// </summary>
        /// <param name="type">the type to get the properties of.</param>
        /// <returns>a dictionary of properties on the type, keyed by name.</returns>
        private static (IImmutableList <IndexerMetadata>, IImmutableDictionary <string, PropertyMetadata>) GetPropertyMetadata(Type type)
        {
            var indexers   = new List <IndexerMetadata>();
            var properties = new Dictionary <string, PropertyMetadata>();

            foreach (PropertyInfo property in type.GetProperties())
            {
                if (property.Name == "Item")
                {
                    MethodInfo idxGetter = property.GetGetMethod();
                    MethodInfo idxSetter = property.GetSetMethod();

                    var idxGetterMetadata = idxGetter == null ? null : new IndexerGetterMetadata(
                        GetProtectionLevel(idxGetter.Attributes),
                        idxGetter.IsStatic);

                    var idxSetterMetadata = idxSetter == null ? null : new IndexerSetterMetadata(
                        GetProtectionLevel(idxSetter.Attributes),
                        idxSetter.IsStatic);

                    var indexer = new IndexerMetadata(ProtectionLevel.Public, false)
                    {
                        CustomAttributes = GetCustomAttributes(property.CustomAttributes),
                        Getter           = idxGetterMetadata,
                        Setter           = idxSetterMetadata,
                        Type             = FromType(idxGetter?.ReturnType ?? idxSetter?.GetParameters()[1].ParameterType),
                        IndexType        = FromType(idxGetter?.GetParameters()[0].ParameterType ?? idxSetter?.GetParameters()[0].ParameterType)
                    };

                    indexers.Add(indexer);
                }

                MethodInfo getter = property.GetGetMethod();
                MethodInfo setter = property.GetSetMethod();

                TypeMetadata propertyType = FromType(property.PropertyType);

                var getterMetadata = getter == null ? null : new PropertyGetterMetadata(
                    property.Name,
                    GetProtectionLevel(getter.Attributes),
                    getter.IsStatic)
                {
                    CustomAttributes = GetCustomAttributes(getter.GetCustomAttributesData()),
                    ReturnType       = propertyType
                };

                var setterMetadata = setter == null ? null : new PropertySetterMetadata(
                    property.Name,
                    GetProtectionLevel(setter.Attributes),
                    setter.IsStatic)
                {
                    CustomAttributes = GetCustomAttributes(setter.GetCustomAttributesData()),
                    ParameterTypes   = new [] { propertyType }.ToImmutableArray()
                };

                var propertyMetadata = new PropertyMetadata(
                    property.Name,
                    ProtectionLevel.Public, // TODO: Correct this later
                    ReadPropertyIsStatic(getter, setter))
                {
                    CustomAttributes  = GetCustomAttributes(property.GetCustomAttributesData()),
                    Getter            = getterMetadata,
                    Setter            = setterMetadata,
                    Type              = propertyType,
                    GenericParameters = ImmutableArray <GenericParameterMetadata> .Empty
                };

                properties.Add(property.Name, propertyMetadata);
            }

            return(indexers.ToImmutableArray(), properties.ToImmutableDictionary());
        }
Exemplo n.º 3
0
 public IndexerViewModel(IndexerMetadata metadata)
 {
     mName     = metadata.Name;
     mTypeName = metadata.TypeName;
 }