예제 #1
0
        private static ITypeProperty CreateTypeProperty(PropertyInfo property, TypeReferenceForDynamicPropertyDelegate typeBuilderDelegate)
        {
            bool           hasGet        = (property.GetMethod != null) && (property.GetMethod.IsPublic);
            bool           hasSet        = (property.SetMethod != null) && (property.SetMethod.IsPublic);
            AccessType     access        = (hasGet ? AccessType.Read : 0) | (hasSet ? AccessType.Write : 0);
            ITypeReference typeReference = property.PropertyType == typeof(object) ? typeBuilderDelegate(property.Name) : Create(property.PropertyType);

            return(new TypeProperty(property.Name, typeReference, access));
        }
예제 #2
0
        internal DynamicCompiledTypeReference(Type type, TypeReferenceForDynamicPropertyDelegate typeBuilderDelegate, bool isResource = false)
        {
            if (type == null)
            {
                throw new Exception("DynamicCompiledTypeReference constructor requires a type. The type provided is null.");
            }

            this.type       = type;
            Id              = type.AssemblyQualifiedName;
            this.isResource = isResource;

            if (this.type != typeof(string) && !this.type.IsValueType)
            {
                properties = this.type.GetProperties(bindingAttr: System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public)
                             .Where(p => p.GetIndexParameters().Length == 0)
                             .Select(p => CreateTypeProperty(p, typeBuilderDelegate)).ToList();
            }
        }
예제 #3
0
 internal DynamicCompiledTypeReference(string assemblyQualifiedName, TypeReferenceForDynamicPropertyDelegate typeBuilderDelegate, bool isResource = false)
     : this(Type.GetType(assemblyQualifiedName), typeBuilderDelegate, isResource)
 {
 }