Exemplo n.º 1
0
        private void DefineStructuralType(ModuleBuilder module, DynamicStructuralType typeInfo)
        {
            var typeAttributes = TypeAttributes.Class | GetTypeAccess(typeInfo.TypeAccess);

            if (typeInfo.IsAbstract)
            {
                typeAttributes |= TypeAttributes.Abstract;
            }
            if (typeInfo.IsSealed)
            {
                typeAttributes |= TypeAttributes.Sealed;
            }

            Type baseClass = null;

            if (typeInfo.BaseClass is Type)
            {
                baseClass = typeInfo.BaseClass as Type;
            }
            else if (typeInfo.BaseClass is DynamicStructuralType)
            {
                baseClass = _typeBuilders[((DynamicStructuralType)typeInfo.BaseClass).Name].Item1;
            }

            var typeBuilder = module.DefineType(typeInfo.Name, typeAttributes, baseClass);

            foreach (var a in typeInfo.Attributes)
            {
                typeBuilder.SetCustomAttribute(AnnotationAttributeBuilder.Create(a));
            }

            // Define the Ctor
            var constructorBuilder = typeInfo.CtorAccess == MemberAccess.None
                                         ? null
                                         : typeBuilder.DefineDefaultConstructor(GetMethodAttributes(false, typeInfo.CtorAccess));

            _typeBuilders.Add(typeInfo.Name, Tuple.Create(typeBuilder, constructorBuilder));
        }
Exemplo n.º 2
0
 public DynamicField HasType(DynamicStructuralType propertyType)
 {
     FieldType = propertyType;
     return(this);
 }
Exemplo n.º 3
0
 public DynamicProperty HasCollectionType(Type collectionType, DynamicStructuralType referenceType)
 {
     CollectionType = collectionType;
     ReferenceType  = referenceType;
     return(this);
 }
Exemplo n.º 4
0
 public DynamicProperty HasReferenceType(DynamicStructuralType referenceType)
 {
     ReferenceType = referenceType;
     return(this);
 }