MapType() public method

Translate a System.Type into the universe's type representation
public MapType ( System type, bool demand ) : Type
type System
demand bool
return IKVM.Reflection.Type
Ejemplo n.º 1
0
        internal void Register(MethodGen method)
        {
#if !SILVERLIGHT
            if (_owner.AssemblyBuilder.EntryPoint == null && method.Name == "Main" && method.IsStatic &&
                (
                    method.ParameterCount == 0 ||
                    (method.ParameterCount == 1 &&
                     method.ParameterTypes[0] == TypeMapper.MapType(typeof(string[])))))
            {
                _owner.AssemblyBuilder.SetEntryPoint(method.GetMethodBuilder());
            }
#endif
            // match explicit interface implementations
            if (method.ImplementedInterface != null)
            {
                foreach (IMemberInfo mi in _typeMapper.TypeInfo.Filter(_typeMapper.TypeInfo.GetMethods(method.ImplementedInterface), method.Name, false, false, true))
                {
                    if (ArrayUtils.Equals(mi.ParameterTypes, method.ParameterTypes))
                    {
                        DefineMethodOverride(method, (MethodInfo)mi.Member);
                        return;
                    }
                }

                throw new MissingMethodException(Properties.Messages.ErrMissingMethod);
            }

            _methods.Add(method);
        }
Ejemplo n.º 2
0
        public void Complete()
        {
            if (_type != null)
            {
                return;
            }

            if (_owner != null && TypeBuilder.IsValueType)
            {
                if (_fields.Count == 0 && _properties.Count == 0)
                {
                    // otherwise  "Value class has neither fields nor size parameter."
                    Private.ReadOnly.Field(_typeMapper.MapType(typeof(int)), "_____");
                }
            }

            foreach (TypeGen nested in _nestedTypes)
            {
                nested.Complete();
            }

            if (_owner != null)
            {
                // ensure creation of default constructor
                EnsureDefaultConstructor();
            }

            FlushDefinitionQueue();
            FlushCompletionQueue();

            // implement all interfaces
            foreach (InterfaceImplEntry iie in _implementations)
            {
                if (!iie.IsBound)
                {
                    throw new NotImplementedException(string.Format(null, Properties.Messages.ErrInterfaceNotImplemented,
                                                                    iie.InterfaceType, iie.InterfaceMethod.Member));
                }

                TypeBuilder.DefineMethodOverride(iie.BoundMethod.GetMethodBuilder(), (MethodInfo)iie.InterfaceMethod.Member);
            }

            // set indexer name
            if (_indexerName != null)
            {
                CustomAttributeBuilder cab = new CustomAttributeBuilder(
                    TypeMapper.MapType(typeof(DefaultMemberAttribute)).GetConstructor(new Type[] { TypeMapper.MapType(typeof(string)) }),
                    new object[] { _indexerName });
                TypeBuilder.SetCustomAttribute(cab);
            }

            AttributeGen.ApplyList(ref _customAttributes, TypeBuilder.SetCustomAttribute);

            _type = TypeBuilder.CreateType();

            _typeMapper.TypeInfo.UnregisterProvider(TypeBuilder);
        }
Ejemplo n.º 3
0
        public void Complete()
        {
            if (_type != null)
            {
                return;
            }

            foreach (TypeGen nested in _nestedTypes)
            {
                nested.Complete();
            }

            // ensure creation of default constructor
            EnsureDefaultConstructor();

            FlushDefinitionQueue();
            FlushCompletionQueue();

            // implement all interfaces
            foreach (InterfaceImplEntry iie in _implementations)
            {
                if (!iie.IsBound)
                {
                    throw new NotImplementedException(string.Format(null, Messages.ErrInterfaceNotImplemented,
                                                                    iie.InterfaceType, iie.InterfaceMethod.Member));
                }

                TypeBuilder.DefineMethodOverride(iie.BoundMethod.GetMethodBuilder(), (MethodInfo)iie.InterfaceMethod.Member);
            }

            // set indexer name
            if (_indexerName != null)
            {
                CustomAttributeBuilder cab = new CustomAttributeBuilder(
                    TypeMapper.MapType(typeof(DefaultMemberAttribute)).GetConstructor(new Type[] { TypeMapper.MapType(typeof(string)) }),
                    new object[] { _indexerName });
                TypeBuilder.SetCustomAttribute(cab);
            }

            AttributeGen.ApplyList(ref _customAttributes, TypeBuilder.SetCustomAttribute);

            _type = TypeBuilder.CreateType();

            _typeMapper.TypeInfo.UnregisterProvider(TypeBuilder);
        }
Ejemplo n.º 4
0
        public MethodGen CommonConstructor()
        {
            if (TypeBuilder.IsValueType)
            {
                throw new InvalidOperationException(Properties.Messages.ErrStructNoDefaultCtor);
            }
            if (TypeBuilder.IsInterface)
            {
                throw new InvalidOperationException(Properties.Messages.ErrInterfaceNoCtor);
            }

            if (_commonCtor == null)
            {
                _commonCtor = new MethodGen(this, "$$ctor", 0, TypeMapper.MapType(typeof(void)), 0).LockSignature();
            }

            return(_commonCtor);
        }
Ejemplo n.º 5
0
        public override AttributeGen <TypeGen> BeginAttribute(AttributeType type, params object[] args)
        {
            AttributeTargets target = AttributeTargets.Class;

            if (BaseType == null)
            {
                target = AttributeTargets.Interface;
            }
            else if (BaseType == TypeMapper.MapType(typeof(ValueType)))
            {
                target = AttributeTargets.Struct;
            }
            else
            {
                target = AttributeTargets.Class;
            }

            return(AttributeGen <TypeGen> .CreateAndAdd(this, ref _customAttributes, target, type, args, TypeMapper));
        }
Ejemplo n.º 6
0
 public DelegateGen Delegate(System.Type returnType, string name)
 {
     return(Delegate(TypeMapper.MapType(returnType), name));
 }
Ejemplo n.º 7
0
 public TypeGen Class(string name, System.Type baseType, params Type[] interfaces)
 {
     return(Class(name, TypeMapper.MapType(baseType), interfaces));
 }
Ejemplo n.º 8
0
 public TypeGen Class(string name)
 {
     return(Class(name, TypeMapper.MapType(typeof(object))));
 }
Ejemplo n.º 9
0
 public FieldGen Attribute(System.Type attributeType)
 {
     return(Attribute(TypeMapper.MapType(attributeType)));
 }
Ejemplo n.º 10
0
 public new ContextualOperand Is(System.Type type)
 {
     return(Is(TypeMapper.MapType(type)));
 }
Ejemplo n.º 11
0
 public PropertyGen Index(System.Type type, string name)
 {
     return(Index(TypeMapper.MapType(type), name));
 }
Ejemplo n.º 12
0
 public MethodGen Operator(Operator op, System.Type returnType, System.Type leftType, System.Type rightType)
 {
     return(Operator(op, TypeMapper.MapType(returnType), TypeMapper.MapType(leftType), TypeMapper.MapType(rightType)));
 }
Ejemplo n.º 13
0
 public MethodGen Operator(Operator op, System.Type returnType, Type operandType, string operandName)
 {
     return(Operator(op, TypeMapper.MapType(returnType), operandType, operandName));
 }
Ejemplo n.º 14
0
 public MethodGen Operator(Operator op, System.Type returnType, System.Type operandType)
 {
     return(Operator(op, TypeMapper.MapType(returnType), TypeMapper.MapType(operandType)));
 }
Ejemplo n.º 15
0
 public MethodGen ExplicitConversionTo(System.Type toType, string parameterName)
 {
     return(ExplicitConversionTo(TypeMapper.MapType(toType), parameterName));
 }
Ejemplo n.º 16
0
        public MethodGen Setter()
        {
            if (_setter == null)
            {
                LockSignature();
                _setter = new MethodGen(_owner, "set_" + Name, _attrs | MethodAttributes.SpecialName, TypeMapper.MapType(typeof(void)), 0);
                _setter.ImplementedInterface = ImplementedInterface;
                _setter.CopyParameters(_indexParameters);
                _setter.UncheckedParameter(_type, "value");
                _pb.SetSetMethod(_setter.GetMethodBuilder());
            }

            return(_setter);
        }
Ejemplo n.º 17
0
 public ParameterGen BeginIndex(System.Type type, string name)
 {
     return(BeginIndex(TypeMapper.MapType(type), name));
 }
Ejemplo n.º 18
0
 public MethodGen Operator(Operator op, System.Type returnType, System.Type leftType, string leftName, System.Type rightType, string rightName)
 {
     return(Operator(op, TypeMapper.MapType(returnType), TypeMapper.MapType(leftType), leftName, TypeMapper.MapType(rightType), rightName));
 }
Ejemplo n.º 19
0
 public Operand Cast(System.Type type)
 {
     return(OperandExtensions.SetLeakedState(Cast(TypeMapper.MapType(type)), true));
 }
Ejemplo n.º 20
0
        public TypeGen Struct(string name, params Type[] interfaces)
        {
            if (TypeBuilder.IsInterface)
            {
                throw new InvalidOperationException(Properties.Messages.ErrInterfaceNoNested);
            }

            if (_typeVis == 0)
            {
                _typeVis |= TypeAttributes.NestedPrivate;
            }

            TypeGen tg = new TypeGen(this, name, (_typeVis | _typeVirt | _typeFlags | TypeAttributes.Sealed | TypeAttributes.SequentialLayout) ^ TypeAttributes.BeforeFieldInit, TypeMapper.MapType(typeof(ValueType)), interfaces, _typeMapper);

            ResetAttrs();
            return(tg);
        }
Ejemplo n.º 21
0
 public AttributeGen <FieldGen> BeginAttribute(System.Type attributeType)
 {
     return(BeginAttribute(TypeMapper.MapType(attributeType)));
 }
Ejemplo n.º 22
0
 public MethodGen MethodImplementation(Type interfaceType, System.Type returnType, string name)
 {
     return(MethodImplementation(interfaceType, TypeMapper.MapType(returnType), name));
 }
Ejemplo n.º 23
0
 public FieldGen Attribute(System.Type attributeType, params object[] args)
 {
     return(Attribute(TypeMapper.MapType(attributeType), args));
 }
Ejemplo n.º 24
0
 public PropertyGen PropertyImplementation(System.Type interfaceType, System.Type type, string name)
 {
     return(PropertyImplementation(TypeMapper.MapType(interfaceType), TypeMapper.MapType(type), name));
 }
Ejemplo n.º 25
0
 public TypeGen Class(System.Type baseType, string name)
 {
     return(Class(name, TypeMapper.MapType(baseType)));
 }
Ejemplo n.º 26
0
 public EventGen EventImplementation(System.Type interfaceType, System.Type eventHandlerType, string name)
 {
     return(EventImplementation(TypeMapper.MapType(interfaceType), TypeMapper.MapType(eventHandlerType), name));
 }
Ejemplo n.º 27
0
        public TypeGen Struct(string name, params Type[] interfaces)
        {
            TypeGen tg = new TypeGen(this, Qualify(name), (_attrs | TypeAttributes.Sealed | TypeAttributes.SequentialLayout) ^ TypeAttributes.BeforeFieldInit, TypeMapper.MapType(typeof(ValueType)), interfaces, TypeMapper);

            _attrs = 0;
            return(tg);
        }
Ejemplo n.º 28
0
 public ContextualOperand Local(System.Type type, Operand init)
 {
     return(Local(TypeMapper.MapType(type), init));
 }
Ejemplo n.º 29
0
        private void WriteAssemblyAttributes(CompilerOptions options, string assemblyName, AssemblyBuilder asm)
        {
            if (!Helpers.IsNullOrEmpty(options.TargetFrameworkName))
            {
                // get [TargetFramework] from mscorlib/equivalent and burn into the new assembly
                Type versionAttribType = null;
                try
                { // this is best-endeavours only
                    versionAttribType = TypeMapper.GetType("System.Runtime.Versioning.TargetFrameworkAttribute", TypeMapper.MapType(typeof(string)).Assembly);
                }
                catch { /* don't stress */ }
                if (versionAttribType != null)
                {
                    PropertyInfo[] props;
                    object[]       propValues;
                    if (Helpers.IsNullOrEmpty(options.TargetFrameworkDisplayName))
                    {
                        props      = new PropertyInfo[0];
                        propValues = new object[0];
                    }
                    else
                    {
                        props = new PropertyInfo[1] {
                            versionAttribType.GetProperty("FrameworkDisplayName")
                        };
                        propValues = new object[1] {
                            options.TargetFrameworkDisplayName
                        };
                    }
                    CustomAttributeBuilder builder = new CustomAttributeBuilder(
                        versionAttribType.GetConstructor(new Type[] { TypeMapper.MapType(typeof(string)) }),
                        new object[] { options.TargetFrameworkName },
                        props,
                        propValues);
                    asm.SetCustomAttribute(builder);
                }
            }

            // copy assembly:InternalsVisibleTo
            Type internalsVisibleToAttribType = null;

#if !FX11
            try
            {
                internalsVisibleToAttribType = TypeMapper.MapType(typeof(System.Runtime.CompilerServices.InternalsVisibleToAttribute));
            }
            catch { /* best endeavors only */ }
#endif
            if (internalsVisibleToAttribType != null)
            {
                List <string>   internalAssemblies   = new List <string>();
                List <Assembly> consideredAssemblies = new List <Assembly>();
                foreach (Type type in _types)
                {
                    Assembly assembly = type.Assembly;
                    if (consideredAssemblies.IndexOf(assembly) >= 0)
                    {
                        continue;
                    }
                    consideredAssemblies.Add(assembly);

                    AttributeMap[] assemblyAttribsMap = AttributeMap.Create(TypeMapper, assembly);
                    for (int i = 0; i < assemblyAttribsMap.Length; i++)
                    {
                        if (assemblyAttribsMap[i].AttributeType != internalsVisibleToAttribType)
                        {
                            continue;
                        }

                        object privelegedAssemblyObj;
                        assemblyAttribsMap[i].TryGet("AssemblyName", out privelegedAssemblyObj);
                        string privelegedAssemblyName = (string)privelegedAssemblyObj;
                        if (privelegedAssemblyName == assemblyName || Helpers.IsNullOrEmpty(privelegedAssemblyName))
                        {
                            continue;                                                                                          // ignore
                        }
                        if (internalAssemblies.IndexOf(privelegedAssemblyName) >= 0)
                        {
                            continue;                                                          // seen it before
                        }
                        internalAssemblies.Add(privelegedAssemblyName);

                        CustomAttributeBuilder builder = new CustomAttributeBuilder(
                            internalsVisibleToAttribType.GetConstructor(new Type[] { TypeMapper.MapType(typeof(string)) }),
                            new object[] { privelegedAssemblyName });
                        asm.SetCustomAttribute(builder);
                    }
                }
            }
        }
Ejemplo n.º 30
0
 internal ContextualOperand LocalInitedFromStack(System.Type type)
 {
     return(LocalInitedFromStack(TypeMapper.MapType(type)));
 }