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); }
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); }
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); }
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); }
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)); }
public DelegateGen Delegate(System.Type returnType, string name) { return(Delegate(TypeMapper.MapType(returnType), name)); }
public TypeGen Class(string name, System.Type baseType, params Type[] interfaces) { return(Class(name, TypeMapper.MapType(baseType), interfaces)); }
public TypeGen Class(string name) { return(Class(name, TypeMapper.MapType(typeof(object)))); }
public FieldGen Attribute(System.Type attributeType) { return(Attribute(TypeMapper.MapType(attributeType))); }
public new ContextualOperand Is(System.Type type) { return(Is(TypeMapper.MapType(type))); }
public PropertyGen Index(System.Type type, string name) { return(Index(TypeMapper.MapType(type), name)); }
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))); }
public MethodGen Operator(Operator op, System.Type returnType, Type operandType, string operandName) { return(Operator(op, TypeMapper.MapType(returnType), operandType, operandName)); }
public MethodGen Operator(Operator op, System.Type returnType, System.Type operandType) { return(Operator(op, TypeMapper.MapType(returnType), TypeMapper.MapType(operandType))); }
public MethodGen ExplicitConversionTo(System.Type toType, string parameterName) { return(ExplicitConversionTo(TypeMapper.MapType(toType), parameterName)); }
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); }
public ParameterGen BeginIndex(System.Type type, string name) { return(BeginIndex(TypeMapper.MapType(type), name)); }
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)); }
public Operand Cast(System.Type type) { return(OperandExtensions.SetLeakedState(Cast(TypeMapper.MapType(type)), true)); }
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); }
public AttributeGen <FieldGen> BeginAttribute(System.Type attributeType) { return(BeginAttribute(TypeMapper.MapType(attributeType))); }
public MethodGen MethodImplementation(Type interfaceType, System.Type returnType, string name) { return(MethodImplementation(interfaceType, TypeMapper.MapType(returnType), name)); }
public FieldGen Attribute(System.Type attributeType, params object[] args) { return(Attribute(TypeMapper.MapType(attributeType), args)); }
public PropertyGen PropertyImplementation(System.Type interfaceType, System.Type type, string name) { return(PropertyImplementation(TypeMapper.MapType(interfaceType), TypeMapper.MapType(type), name)); }
public TypeGen Class(System.Type baseType, string name) { return(Class(name, TypeMapper.MapType(baseType))); }
public EventGen EventImplementation(System.Type interfaceType, System.Type eventHandlerType, string name) { return(EventImplementation(TypeMapper.MapType(interfaceType), TypeMapper.MapType(eventHandlerType), name)); }
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); }
public ContextualOperand Local(System.Type type, Operand init) { return(Local(TypeMapper.MapType(type), init)); }
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); } } } }
internal ContextualOperand LocalInitedFromStack(System.Type type) { return(LocalInitedFromStack(TypeMapper.MapType(type))); }