Example #1
0
        private void ResolveProperty(MosaProperty property)
        {
            GenericArgumentResolver resolver = new GenericArgumentResolver();

            if (property.DeclaringType.GenericArguments.Count > 0)
            {
                resolver.PushTypeGenericArguments(property.DeclaringType.GenericArguments.GetGenericArguments());
            }

            using (var mosaProperty = metadata.Controller.MutateProperty(property))
            {
                mosaProperty.PropertyType = metadata.Loader.GetType(resolver.Resolve(property.GetPropertySig().RetType));

                ResolveCustomAttributes(mosaProperty, property.GetUnderlyingObject <UnitDesc <PropertyDef, PropertySig> >().Definition);
            }
        }
        private void ResolveProperty(MosaProperty property)
        {
            GenericArgumentResolver resolver = new GenericArgumentResolver();

            if (property.DeclaringType.GenericArguments.Count > 0)
                resolver.PushTypeGenericArguments(property.DeclaringType.GenericArguments.GetGenericArguments());

            using (var mosaProperty = metadata.Controller.MutateProperty(property))
            {
                mosaProperty.PropertyType = metadata.Loader.GetType(resolver.Resolve(property.GetPropertySig().RetType));

                ResolveCustomAttributes(mosaProperty, property.GetUnderlyingObject<UnitDesc<PropertyDef, PropertySig>>().Definition);
            }
        }
Example #3
0
 public static PropertySig GetPropertySig(this MosaProperty property)
 {
     return(property.GetUnderlyingObject <UnitDesc <PropertyDef, PropertySig> >().Signature);
 }
        private void Load(MosaModule module, TypeDef typeDef)
        {
            TypeSig typeSig = typeDef.ToTypeSig();

            // Check to see if its one of our classes we need for SZ Arrays
            if (typeDef.Name.Contains("SZArrayHelper`1"))
            {
                szHelperSig = typeSig as ClassOrValueTypeSig;
            }
            else if (typeDef.Name.Contains("IList`1"))
            {
                iListSig = typeSig as ClassOrValueTypeSig;
            }

            MosaType mosaType = metadata.Controller.CreateType();

            using (var type = metadata.Controller.MutateType(mosaType))
            {
                type.Module           = module;
                type.UnderlyingObject = new UnitDesc <TypeDef, TypeSig>(typeDef.Module, typeDef, typeSig);

                type.Namespace = typeDef.Namespace;
                type.Name      = typeDef.Name;

                type.IsInterface = typeDef.IsInterface;
                type.IsEnum      = typeDef.IsEnum;
                type.IsDelegate  =
                    typeDef.BaseType != null && typeDef.BaseType.DefinitionAssembly.IsCorLib() &&
                    (typeDef.BaseType.FullName == "System.Delegate" || typeDef.BaseType.FullName == "System.MulticastDelegate");
                type.IsModule = typeDef.IsGlobalModuleType;

                type.IsExplicitLayout = typeDef.IsExplicitLayout;
                if (typeDef.IsExplicitLayout)
                {
                    type.ClassSize   = (int)typeDef.ClassSize;
                    type.PackingSize = typeDef.PackingSize;
                }
                type.TypeAttributes = (MosaTypeAttributes)typeDef.Attributes;
                type.TypeCode       = (MosaTypeCode)typeSig.ElementType;

                // Load members

                foreach (var fieldDef in typeDef.Fields)
                {
                    MosaField mosaField = metadata.Controller.CreateField();

                    using (var field = metadata.Controller.MutateField(mosaField))
                        LoadField(mosaType, field, fieldDef);

                    type.Fields.Add(mosaField);
                    metadata.Cache.AddField(mosaField);
                    LoadedUnits.Add(mosaField);
                }

                foreach (var methodDef in typeDef.Methods)
                {
                    MosaMethod mosaMethod = metadata.Controller.CreateMethod();

                    using (var method = metadata.Controller.MutateMethod(mosaMethod))
                        LoadMethod(mosaType, method, methodDef);

                    type.Methods.Add(mosaMethod);
                    metadata.Cache.AddMethod(mosaMethod);
                    LoadedUnits.Add(mosaMethod);
                }

                foreach (var propertyDef in typeDef.Properties)
                {
                    MosaProperty mosaProperty = metadata.Controller.CreateProperty();

                    using (var property = metadata.Controller.MutateProperty(mosaProperty))
                        LoadProperty(mosaType, property, propertyDef);

                    type.Properties.Add(mosaProperty);
                    metadata.Cache.AddProperty(mosaProperty);
                    LoadedUnits.Add(mosaProperty);
                }
            }
            typeCache[typeSig] = mosaType;
            metadata.Controller.AddType(mosaType);
            metadata.Cache.AddType(mosaType);
            LoadedUnits.Add(mosaType);
        }
Example #5
0
 public void AddProperty(MosaProperty property)
 {
     propertyLookup.Add(property.GetUnderlyingObject<UnitDesc<PropertyDef, PropertySig>>().Token, property);
 }
        private MosaType LoadGenericTypeInstanceSig(GenericInstSig typeSig)
        {
            //Debug.Assert(false, typeSig.FullName);
            MosaType origin = GetType(typeSig.GenericType);
            MosaType result = metadata.Controller.CreateType(origin);
            var      desc   = result.GetUnderlyingObject <UnitDesc <TypeDef, TypeSig> >();

            using (var resultType = metadata.Controller.MutateType(result))
            {
                resultType.UnderlyingObject = desc.Clone(typeSig);
                resultType.ElementType      = origin;

                foreach (var genericArg in typeSig.GenericArguments)
                {
                    resultType.GenericArguments.Add(GetType(genericArg));
                }

                metadata.Resolver.EnqueueForResolve(result);

                GenericArgumentResolver resolver = new GenericArgumentResolver();
                resolver.PushTypeGenericArguments(typeSig.GenericArguments);

                for (int i = 0; i < result.Methods.Count; i++)
                {
                    MosaMethod method = metadata.Controller.CreateMethod(result.Methods[i]);

                    using (var mosaMethod = metadata.Controller.MutateMethod(method))
                    {
                        mosaMethod.DeclaringType    = result;
                        mosaMethod.UnderlyingObject = method.GetUnderlyingObject <UnitDesc <MethodDef, MethodSig> >();
                    }

                    resultType.Methods[i] = method;
                    metadata.Resolver.EnqueueForResolve(method);
                }

                for (int i = 0; i < result.Fields.Count; i++)
                {
                    MosaField field = metadata.Controller.CreateField(result.Fields[i]);

                    using (var mosaField = metadata.Controller.MutateField(field))
                    {
                        mosaField.DeclaringType    = result;
                        mosaField.UnderlyingObject = field.GetUnderlyingObject <UnitDesc <FieldDef, FieldSig> >();
                    }

                    resultType.Fields[i] = field;
                    metadata.Resolver.EnqueueForResolve(field);
                }

                for (int i = 0; i < result.Properties.Count; i++)
                {
                    MosaProperty property = metadata.Controller.CreateProperty(result.Properties[i]);

                    PropertySig newSig = property.GetPropertySig().Clone();
                    newSig.RetType = resolver.Resolve(newSig.RetType);
                    using (var mosaProperty = metadata.Controller.MutateProperty(property))
                    {
                        mosaProperty.DeclaringType    = result;
                        mosaProperty.UnderlyingObject = property.GetUnderlyingObject <UnitDesc <PropertyDef, PropertySig> >();
                    }

                    resultType.Properties[i] = property;
                    metadata.Resolver.EnqueueForResolve(property);
                }

                resultType.HasOpenGenericParams = typeSig.HasOpenGenericParameter();
            }

            metadata.Controller.AddType(result);

            return(result);
        }
Example #7
0
 public MosaProperty.Mutator MutateProperty(MosaProperty property)
 {
     return new MosaProperty.Mutator(property);
 }
Example #8
0
 public MosaProperty CreateProperty(MosaProperty source = null)
 {
     if (source == null)
     {
         return new MosaProperty()
         {
             ID = id++,
             TypeSystem = typeSystem
         };
     }
     else
     {
         MosaProperty result = source.Clone();
         result.ID = id++;
         return result;
     }
 }
Example #9
0
 public void AddProperty(MosaProperty property)
 {
     propertyLookup.Add(property.GetUnderlyingObject <UnitDesc <PropertyDef, PropertySig> >().Token, property);
 }
        private void ResolveProperty(MosaProperty property)
        {
            GenericArgumentResolver resolver = new GenericArgumentResolver();

            if (property.DeclaringType.GenericArguments.Count > 0)
                resolver.PushTypeGenericArguments(property.DeclaringType.GenericArguments.GetGenericArguments());

            using (var mosaProperty = metadata.Controller.MutateProperty(property))
            {
                mosaProperty.PropertyType = metadata.Loader.GetType(resolver.Resolve(property.GetPropertySig().RetType));

                var propertyDesc = property.GetUnderlyingObject<UnitDesc<PropertyDef, PropertySig>>();

                if (propertyDesc.Definition.GetMethod != null)
                {
                    var getterDesc = new UnitDesc<MethodDef, MethodSig>(propertyDesc.Definition.GetMethod.Module, propertyDesc.Definition.GetMethod, propertyDesc.Definition.GetMethod.MethodSig);
                    mosaProperty.GetterMethod = metadata.Cache.GetMethodByToken(getterDesc.Token);
                }

                if (propertyDesc.Definition.SetMethod != null)
                {
                    var setterDesc = new UnitDesc<MethodDef, MethodSig>(propertyDesc.Definition.SetMethod.Module, propertyDesc.Definition.SetMethod, propertyDesc.Definition.SetMethod.MethodSig);
                    mosaProperty.SetterMethod = metadata.Cache.GetMethodByToken(setterDesc.Token);
                }

                ResolveCustomAttributes(mosaProperty, property.GetUnderlyingObject<UnitDesc<PropertyDef, PropertySig>>().Definition);
            }
        }