/// <summary>
        /// Get the return type of the constructor (never null).
        /// </summary>
        public static TypeRefBase GetReturnType(TypeRefBase thisRef, object reference)
        {
            // The 'return type' of a constructor is its declaring type, along with any type parameters
            TypeRefBase typeRefBase;

            if (reference is ConstructorDecl)
            {
                ConstructorDecl constructorDecl = (ConstructorDecl)reference;
                CodeObject      parent          = constructorDecl.Parent;
                if (parent == null)
                {
                    // If we don't have a parent, assume we're a generated constructor for
                    // a delegate (used for the obsolete explicit delegate creation syntax), and
                    // use the type of the parameter as our type.
                    // Clone the type so we can evaluate any type arguments it has later without consequences.
                    typeRefBase = constructorDecl.Parameters[0].Type.SkipPrefixes() as TypeRefBase;
                    typeRefBase = (typeRefBase != null ? (TypeRefBase)typeRefBase.Clone() : TypeRef.VoidRef);
                }
                else
                {
                    typeRefBase = (TypeRef)parent.CreateRef();
                }
            }
            else //if (reference is ConstructorInfo)
            {
                typeRefBase = TypeRef.Create(((ConstructorInfo)reference).DeclaringType);
            }

            return(typeRefBase);
        }
Esempio n. 2
0
        public void SetupMetadata()
        {
            metadata            = new MetaDataDefinition("TipoLancamento", "Sigfaz.Autorizador.Models.Financeiro", @"C:\Temp", "FIN_TIPOLANC");
            metadata.PortalPath = @"C:\Temp";
            var propriedades = new List <PropertyMetadaDefinition>();

            Nullable <long> nullableLong = new long?(999);
            var             typeRef      = TypeRef.Create(nullableLong.GetType(), true);

            var intType = TypeFactory.Create(typeRef, isReferenceType: false);

            var item1 = new PropertyMetadaDefinition("HandleProp1", true, intType);
            var item2 = new PropertyMetadaDefinition("Prop1", false, intType);
            var item3 = new PropertyMetadaDefinition("Prop3", false, intType);
            var item4 = new PropertyMetadaDefinition("HandleProp4", true, intType);
            var item5 = new PropertyMetadaDefinition("HandleProp1", false, intType);
            var item6 = new PropertyMetadaDefinition("HandleProp2", true, intType);

            propriedades.Add(item1);
            propriedades.Add(item2);
            propriedades.Add(item3);
            propriedades.Add(item4);
            propriedades.Add(item5);
            propriedades.Add(item6);
            metadata.SetProperties(propriedades);
            LookupVerifier.CheckForeignKeyReferences(propriedades);
        }
        public void Setup()
        {
            metadata = new MetaDataDefinition(className: ENTITY_NAME,
                                              nameSpace: "Sigfaz.Autorizador.Models.Financeiro",
                                              projectPath: @"C:\Temp",
                                              tableName: "FIN_TIPOLANC");
            metadata.PortalBusinessPath = @"C:\Temp\PortalBusiness";
            metadata.PortalPath         = @"C:\Temp\Portal";
            var propriedades = new List <PropertyMetadaDefinition>();

            var nullableLong = new long?(999);
            var typeRef      = TypeRef.Create(nullableLong.GetType(), true);

            var intType = TypeFactory.Create(typeRef, isReferenceType: false);

            var item1 = new PropertyMetadaDefinition("HandleProp1", true, intType);
            var item2 = new PropertyMetadaDefinition("Prop1", false, intType);
            var item3 = new PropertyMetadaDefinition("Prop3", true, intType);
            var item4 = new PropertyMetadaDefinition("HandleProp4", true, intType);
            var item5 = new PropertyMetadaDefinition("Prop4", false, intType);
            var item6 = new PropertyMetadaDefinition("Prop5", true, intType);

            propriedades.Add(item1);
            propriedades.Add(item2);
            propriedades.Add(item3);
            propriedades.Add(item4);
            propriedades.Add(item5);
            propriedades.Add(item6);
            metadata.SetProperties(propriedades);
        }
Esempio n. 4
0
 /// <summary>
 /// Get the type of the specified property object.
 /// </summary>
 public static TypeRefBase GetPropertyType(object reference)
 {
     if (reference is PropertyDeclBase)
     {
         Expression type = ((PropertyDeclBase)reference).Type;
         return(type != null ? type.SkipPrefixes() as TypeRefBase : null);
     }
     return(TypeRef.Create(((PropertyInfo)reference).PropertyType));
 }
Esempio n. 5
0
        /// <summary>
        /// Get the type of the parameter in the collection with the specified index, using the specified parent expression to evaluate any type argument types.
        /// </summary>
        public static TypeRefBase GetParameterType(ICollection parameters, int index, Expression parentExpression)
        {
            TypeRefBase parameterTypeRef;

            if (parameters is List <ParameterDecl> )
            {
                parameterTypeRef = ((List <ParameterDecl>)parameters)[index].Type.SkipPrefixes() as TypeRefBase;
            }
            else //if (parameters is ParameterInfo[])
            {
                parameterTypeRef = TypeRef.Create(((ParameterInfo[])parameters)[index].ParameterType);
            }
            return(parameterTypeRef);
        }
Esempio n. 6
0
        /// <summary>
        /// Get the declaring type of the specified property object.
        /// </summary>
        /// <param name="propertyObj">The property object (a <see cref="PropertyDeclBase"/> or <see cref="PropertyInfo"/>).</param>
        /// <returns>The <see cref="TypeRef"/> of the declaring type, or null if it can't be determined.</returns>
        public static TypeRefBase GetDeclaringType(object propertyObj)
        {
            TypeRefBase declaringTypeRef = null;

            if (propertyObj is PropertyDeclBase)
            {
                TypeDecl declaringTypeDecl = ((PropertyDeclBase)propertyObj).DeclaringType;
                declaringTypeRef = (declaringTypeDecl != null ? declaringTypeDecl.CreateRef() : null);
            }
            else if (propertyObj is PropertyInfo)
            {
                declaringTypeRef = TypeRef.Create(((PropertyInfo)propertyObj).DeclaringType);
            }
            return(declaringTypeRef);
        }
        /// <summary>
        /// Get the declaring type of the specified enum member object.
        /// </summary>
        /// <param name="enumMemberObj">The enum member object (a <see cref="EnumMemberDecl"/> or <see cref="FieldInfo"/>).</param>
        /// <returns>The <see cref="TypeRef"/> of the declaring type, or null if it can't be determined.</returns>
        public static TypeRefBase GetDeclaringType(object enumMemberObj)
        {
            TypeRefBase declaringTypeRef = null;

            if (enumMemberObj is EnumMemberDecl)
            {
                TypeDecl declaringTypeDecl = ((EnumMemberDecl)enumMemberObj).ParentEnumDecl;
                declaringTypeRef = (declaringTypeDecl != null ? declaringTypeDecl.CreateRef() : null);
            }
            else if (enumMemberObj is FieldInfo)
            {
                declaringTypeRef = TypeRef.Create(((FieldInfo)enumMemberObj).DeclaringType);
            }
            return(declaringTypeRef);
        }
        /// <summary>
        /// Get the declaring type of the specified event object.
        /// </summary>
        /// <param name="eventObj">The event object (an <see cref="EventDecl"/> or <see cref="EventInfo"/>).</param>
        /// <returns>The <see cref="TypeRef"/> of the declaring type, or null if it can't be determined.</returns>
        public static TypeRefBase GetDeclaringType(object eventObj)
        {
            TypeRefBase declaringTypeRef;

            if (eventObj is EventDecl)
            {
                TypeDecl declaringTypeDecl = ((EventDecl)eventObj).DeclaringType;
                declaringTypeRef = (declaringTypeDecl != null ? declaringTypeDecl.CreateRef() : null);
            }
            else //if (eventObj is EventInfo)
            {
                declaringTypeRef = TypeRef.Create(((EventInfo)eventObj).DeclaringType);
            }
            return(declaringTypeRef);
        }
        /// <summary>
        /// Get the declaring type of the specified field object.
        /// </summary>
        /// <param name="fieldObj">The field object (a <see cref="FieldDecl"/> or <see cref="FieldInfo"/>).</param>
        /// <returns>The <see cref="TypeRef"/> of the declaring type, or null if it can't be determined.</returns>
        public static TypeRefBase GetDeclaringType(object fieldObj)
        {
            TypeRefBase declaringTypeRef;

            if (fieldObj is FieldDecl)
            {
                TypeDecl declaringTypeDecl = ((FieldDecl)fieldObj).DeclaringType;
                declaringTypeRef = (declaringTypeDecl != null ? declaringTypeDecl.CreateRef() : null);
            }
            else //if (fieldObj is FieldInfo)
            {
                declaringTypeRef = TypeRef.Create(((FieldInfo)fieldObj).DeclaringType);
            }
            return(declaringTypeRef);
        }
        /// <summary>
        /// Create a collection of type parameter constraints for the specified type parameter.
        /// </summary>
        public static List <TypeParameterConstraint> Create(Type typeParameter)
        {
            List <TypeParameterConstraint> typeParameterConstraints = new List <TypeParameterConstraint>();

            foreach (Type typeConstraint in typeParameter.GetGenericParameterConstraints())
            {
                typeParameterConstraints.Add(new TypeConstraint(TypeRef.Create(typeConstraint)));
            }
            GenericParameterAttributes attributes = typeParameter.GenericParameterAttributes;

            if (attributes.HasFlag(GenericParameterAttributes.ReferenceTypeConstraint))  // class constraint
            {
                typeParameterConstraints.Add(new ClassConstraint());
            }
            if (attributes.HasFlag(GenericParameterAttributes.NotNullableValueTypeConstraint))  // struct constraint
            {
                typeParameterConstraints.Add(new StructConstraint());
            }
            if (attributes.HasFlag(GenericParameterAttributes.DefaultConstructorConstraint))
            {
                typeParameterConstraints.Add(new NewConstraint());
            }
            return(typeParameterConstraints);
        }
 /// <summary>
 /// Create a <see cref="DelegateDecl"/> with the specified name, return type, modifiers, and parameters.
 /// </summary>
 public DelegateDecl(string name, Type returnType, Modifiers modifiers, params ParameterDecl[] parameters)
     : this(name, TypeRef.Create(returnType), modifiers, parameters)
 {
 }
 /// <summary>
 /// Create a <see cref="DelegateDecl"/> with the specified name and return type.
 /// </summary>
 public DelegateDecl(string name, Type returnType)
     : this(name, TypeRef.Create(returnType), Modifiers.None)
 {
 }