Ejemplo n.º 1
0
        public static CodeDefaultProperty Property <T, T2, T3>(CodeTypeReference propertyType, MemberAttributes ma,
                                                               Expression <Func <T, T2, T3, string> > paramsAndName, bool indexer,
                                                               CodeStatement[] getStatements, params CodeStatement[] setStatements)
        {
            var c = new CodeMemberProperty
            {
                Attributes = ma,
                Type       = propertyType,
                HasGet     = true,
                HasSet     = true
            };

            if (getStatements != null)
            {
                c.GetStatements.AddRange(getStatements);
            }

            if (setStatements != null)
            {
                c.SetStatements.AddRange(setStatements);
            }

            CodeParameterDeclarationExpressionCollection parameters = new CodeParameterDeclarationExpressionCollection();

            c.Name = CodeDom.GetMethodName <string>(paramsAndName, parameters);

            return(new CodeDefaultProperty(c, parameters, indexer));
        }
Ejemplo n.º 2
0
        //public static CodeAssignStatement assign<TResult, T>(Expression<Func<TResult, LinqToCodedom.Generator.CodeDom.NilClass>> name,
        //    Expression<Func<TResult, T>> stmt)
        //{
        //    return new CodeAssignStatement(
        //        new CodeExpressionVisitor(new VisitorContext()).Visit(name),
        //        new CodeExpressionVisitor(new VisitorContext()).Visit(stmt));
        //}

        public static CodeAssignStatement assignDelegate(string varName, Base target, string methodName)
        {
            return(new CodeAssignStatement(
                       new CodeVariableReferenceExpression(varName),
                       new CodeMethodReferenceExpression(CodeDom.GetTargetObject(target), methodName)
                       ));
        }
Ejemplo n.º 3
0
 public static CodeMemberProperty Property(string propertyType, MemberAttributes ma, string name,
                                           string fieldName)
 {
     return(Property(propertyType, ma, name,
                     CodeDom.CombineStmts(Emit.@return(() => [email protected] <object>(fieldName))),
                     Emit.assignField(fieldName, (SetValueRef <object> value) => value)));
 }
Ejemplo n.º 4
0
 public static CodeRemoveEventStatement detachDelegate(Base owner, string eventName,
                                                       string staticMethodName)
 {
     return(new CodeRemoveEventStatement(
                CodeDom.GetTargetObject(owner), eventName,
                new CodeMethodReferenceExpression(null, staticMethodName)
                ));
 }
Ejemplo n.º 5
0
 public static CodeAttachEventStatement attachDelegate(Base owner, string eventName,
                                                       Base target, string methodName)
 {
     return(new CodeAttachEventStatement(
                CodeDom.GetTargetObject(owner), eventName,
                new CodeMethodReferenceExpression(CodeDom.GetTargetObject(target), methodName)
                ));
 }
Ejemplo n.º 6
0
        public static CodeConstructor Ctor <T, T2>(Expression <Func <T, T2, MemberAttributes> > paramsAndAccessLevel,
                                                   params CodeStatement[] statements)
        {
            var c = new CodeConstructor();

            c.Attributes = CodeDom.GetMethodName <MemberAttributes>(paramsAndAccessLevel, c.Parameters);
            c.Statements.AddRange(statements);

            return(c);
        }
Ejemplo n.º 7
0
        public static CodeTypeDelegate Delegate <T>(MemberAttributes ma,
                                                    Expression <Func <T, string> > paramsAndName)
        {
            var c = new CodeTypeDelegate()
            {
                Attributes = ma
            };

            c.Name = CodeDom.GetMethodName <string>(paramsAndName, c.Parameters);

            return(c);
        }
Ejemplo n.º 8
0
        private static void InitAttributeArgs(Expression anonymType, CodeAttributeDeclaration c)
        {
            object o = CodeDom.Eval <object>(anonymType);

            foreach (System.Reflection.PropertyInfo pi in
                     o.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance))
            {
                c.Arguments.Add(new CodeAttributeArgument(pi.Name,
                                                          LinqToCodedom.Visitors.CodeExpressionVisitor.GetFromPrimitive(pi.GetValue(o, null))
                                                          ));
            }
        }
Ejemplo n.º 9
0
        public static CodeMemberMethod Method <T, T2>(MemberAttributes ma,
                                                      Expression <Func <T, T2, string> > paramsAndName, params CodeStatement[] statements)
        {
            CodeMemberMethod method = new CodeMemberMethod()
            {
                Attributes = ma
            };

            method.Name = CodeDom.GetMethodName <string>(paramsAndName, method.Parameters);
            method.Statements.AddRange(statements);

            return(method);
        }
Ejemplo n.º 10
0
        public static CodeTypeDelegate Delegate(Type returnType, MemberAttributes ma,
                                                Expression <Func <string> > paramsAndName)
        {
            var c = new CodeTypeDelegate()
            {
                Attributes = ma,
                ReturnType = new CodeTypeReference(returnType),
            };

            c.Name = CodeDom.GetMethodName <string>(paramsAndName, c.Parameters);

            return(c);
        }
Ejemplo n.º 11
0
        public static CodeMemberOperatorOverride Operator <T>(
            CodeTypeReference returnType,
            Expression <Func <T, OperatorType> > paramsAndType,
            params CodeStatement[] statements)
        {
            CodeParameterDeclarationExpressionCollection pars = new CodeParameterDeclarationExpressionCollection();

            var c = new CodeMemberOperatorOverride(
                CodeDom.GetMethodName <OperatorType>(paramsAndType, pars),
                pars.ToArray(), returnType, statements);

            return(c);
        }
Ejemplo n.º 12
0
        public static CodeMemberMethod Method <T>(MemberAttributes ma, string returnType,
                                                  Expression <Func <T, string> > paramsAndName, params CodeStatement[] statements)
        {
            CodeMemberMethod method = new CodeMemberMethod()
            {
                ReturnType = returnType == null ? null : new CodeTypeReference(returnType),
                Attributes = ma
            };

            method.Name = CodeDom.GetMethodName <string>(paramsAndName, method.Parameters);
            method.Statements.AddRange(statements);

            return(method);
        }
Ejemplo n.º 13
0
 public static CodeVariableDeclarationStatement declare(Type type, string varName)
 {
     return(new CodeVariableDeclarationStatement(type, varName, CodeDom.@default(type)));
 }