public CClass ReadSqlScriptClass(KDataStoreTestProject sqlTestKProject, KDataLayerProject dataLayerKProject)
        {
            var @class = new CClass("ReadSqlScript")
            {
                IsStatic  = true,
                Namespace = new CNamespace()
                {
                    NamespaceName =
                        $"{sqlTestKProject.ProjectFullName}.DataAccess"
                }
            };

            AddNamespaceRefs(sqlTestKProject, @class);

            @class.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Internal,
                IsStatic       = true,
                ReturnType     = "string",
                MethodName     = "FromEmbeddedResource",
                Parameter      = new List <CParameter>()
                {
                    new CParameter()
                    {
                        Type = "string", ParameterName = "scriptName"
                    }
                },
                CodeSnippet = $@"var sourceName = $""{dataLayerKProject.ProjectFullName}.EmbeddedSql.{{scriptName}}.esql"";
                                var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.Contains("".Data.SqlServer""));
                                var dataAssembly = assemblies.First();
                                return dataAssembly.ReadToEndEmbeddedResource(sourceName);"
            });

            return(@class);
        }
        public static void LoadBuiltins(CProgram program)
        {
            ImportType(program, SearchAssembliesForType(program, "System.Object"), BuiltIns.Variant);
            ImportType(program, SearchAssembliesForType(program, "System.String"), BuiltIns.String);

            CClass vtype = program.FindClass("System.ValueType");

            ImportType(program, SearchAssembliesForType(program, "System.Byte"), BuiltIns.Byte);
            BuiltIns.Byte.ForceSetBaseClass(vtype);
            ImportType(program, SearchAssembliesForType(program, "System.Int32"), BuiltIns.Int32);
            BuiltIns.Int32.ForceSetBaseClass(vtype);
            ImportType(program, SearchAssembliesForType(program, "System.Int64"), BuiltIns.Int64);
            BuiltIns.Int64.ForceSetBaseClass(vtype);
            ImportType(program, SearchAssembliesForType(program, "System.Char"), BuiltIns.Character);
            BuiltIns.Character.ForceSetBaseClass(vtype);
            ImportType(program, SearchAssembliesForType(program, "System.Boolean"), BuiltIns.Boolean);
            BuiltIns.Boolean.ForceSetBaseClass(vtype);
            ImportType(program, SearchAssembliesForType(program, "System.DateTime"), BuiltIns.Date);
            BuiltIns.Date.ForceSetBaseClass(vtype);
            ImportType(program, SearchAssembliesForType(program, "System.Double"), BuiltIns.Double);
            BuiltIns.Double.ForceSetBaseClass(vtype);

            BuiltIns.Variant.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(BuiltIns.Variant, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            BuiltIns.Object.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(BuiltIns.Object, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            BuiltIns.String.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(BuiltIns.String, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            BuiltIns.Byte.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(BuiltIns.Byte, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            BuiltIns.Int32.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(BuiltIns.Int32, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            BuiltIns.Int64.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(BuiltIns.Int64, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            BuiltIns.Character.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(BuiltIns.Character, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            BuiltIns.Boolean.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(BuiltIns.Boolean, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            BuiltIns.Date.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(BuiltIns.Date, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            BuiltIns.Double.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(BuiltIns.Double, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
        }
    public virtual void Method()
    {
        //Console.WriteLine ("sc class");
        CClass cc = new CClass();

        cc.Method();
    }
Exemple #4
0
        public CClass Convert(CTableType tableType)
        {
            if (string.IsNullOrEmpty(tableType.TableName))
            {
                throw new Exception("cannot create CClass without a class name");
            }

            var @class = new CClass(tableType.TableName);

            @class.Namespace = new CNamespace {
                NamespaceName = tableType.Schema.SchemaName
            };

            @class.NamespaceRef.Add(new CNamespaceRef("System"));

            if (!string.IsNullOrEmpty(tableType.TableName))
            {
                foreach (var column in tableType.Column)
                {
                    var prop = new CProperty();
                    prop.PropertyName = column.ColumnName;
                    prop.Type         = column.ColumnType.ToClrTypeName();
                    prop.MaxLength    = column.ColumnLength;

                    @class.Property.Add(prop);
                }
            }

            return(@class);
        }
Exemple #5
0
        private void AddNamespaceRefs(CClass classTestInitialize, CInterface dbProviderInterface)
        {
            var namespaces = new List <string>
            {
                "System",
                "System.Data",
                "System.Data.Common",
                "Microsoft.Extensions.Configuration",
                "Microsoft.Extensions.DependencyInjection",
                "Microsoft.VisualStudio.TestTools.UnitTesting",
                "Moq",
                //"StructureMap",
                "Company.Configuration.ConfigCenter",

                $"{classTestInitialize.Namespace.NamespaceName}.Startup",
                $"{dbProviderInterface.Namespace.NamespaceName}"
            };

            foreach (var ns in namespaces)
            {
                classTestInitialize.NamespaceRef.Add(new CNamespaceRef
                {
                    ReferenceTo = new CNamespace {
                        NamespaceName = ns
                    }
                });
            }
        }
Exemple #6
0
        private void AddNamespaceRefs(CClass @class, CInterface dbProviderInterface)
        {
            var namespaces = new List <string>
            {
                "System.Collections.Generic",
                "System.Threading.Tasks",
                "Microsoft.Extensions.DependencyInjection",
                "Microsoft.VisualStudio.TestTools.UnitTesting",
                "Company.Datastore",
                "Company.Datastore.Query",
                "Company.Datastore.Command",
                $"{dbProviderInterface.Namespace.NamespaceName}",
                $"{@class.Namespace.NamespaceName}.DataAccess"
            };

            foreach (var ns in namespaces)
            {
                @class.NamespaceRef.Add(new CNamespaceRef
                {
                    ReferenceTo = new CNamespace {
                        NamespaceName = ns
                    }
                });
            }
        }
Exemple #7
0
 public void GeneratePocos(CDBM db, CSharpProject p, CUsing NamespaceName, TextWriter mensajes)
 {
     foreach (CTableM t in db.lTable)
     {
         p.AddCSharpFile(PocoName(t.Name), NamespaceName);
         CClass c = p.AddClass(PocoName(t.Name));
         c.lUsing.Add(CSharpStandarUsing.System);
         CConstructor consVacio = new CConstructor(c, CSharpVisibility.cvPublic);
         CConstructor cons      = new CConstructor(c, CSharpVisibility.cvPublic);
         //Se añaden al final por estética de la clase generada
         foreach (CFieldM f in t.lFieldAll)
         {
             CType aux = CGenerator.SqlServerTD2CSharp(f.Td, f.IsNullable);
             if (aux.Equals(CSharpPrimitiveType.cDateTime))
             {
                 c.lUsing.Add(CSharpStandarUsing.System);
             }
             c.AddField(new CField(f.Name, aux, CSharpVisibility.cvPublic));
             cons.AddParam(SUtil.LowerFirst(f.Name), CGenerator.SqlServerTD2CSharp(f.Td, f.IsNullable));
             cons.AddSentence(new CTextualSentence($"this.{f.Name} = {SUtil.LowerFirst(f.Name)};"));
         }
         c.AddConstructor(consVacio);
         c.AddConstructor(cons);
     }
     mensajes.WriteLine("Pocos generados en: " + p.RootDirectory.ActualDirectory.FullName);
 }
Exemple #8
0
        static BuiltIns()
        {
            /* These aren't fully resolved; we need to use Cecil to load the appropriate .NET type defitinions in.
             * See ClrImporter.LoadBuiltins. */
            Variant   = new CClass("__Variant", null);
            Byte      = new CClass("Byte", false);
            String    = new CClass("String", true);
            Int32     = new CClass("Int32", true);
            Int64     = new CClass("Int64", true);
            Character = new CClass("Character", false);
            Boolean   = new CClass("Boolean", true);
            Date      = new CClass("Date", true);
            Double    = new CClass("Double", true);
            Object    = Variant;
            DbNull    = new CClass("DbNull", false);
            Nothing   = new CClass("Nothing", false);
            Nothing.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            Void = new CClass("__Void", false);
            FunctionPlaceHolder = new CClass("__FunctionPlaceHolder", false);
            FunctionPlaceHolder.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            SubPlaceHolder = new CClass("__SubPlaceHolder", false);
            SubPlaceHolder.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));

            SetupGlobalTypes();

            CArgumentList arrArgs = new CArgumentList();

            arrArgs.Add(new CArgument(CToken.Keyword(null, "byval"),
                                      CToken.Identifer(null, "arglist"),
                                      new CTypeRef(null, Variant)));
            Array = new CFunction(CToken.Identifer(null, "Array"), "Array", "array", TokenTypes.visPublic, FunctionType.Function,
                                  arrArgs, new CTypeRef(null, new CArrayType(new CTypeRef(null, Variant), 1)));
            Array.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));

            CArgumentList dicArgs = new CArgumentList();

            dicArgs.Add(new CArgument(CToken.Keyword(null, "byval"),
                                      CToken.Identifer(null, "arglist"),
                                      new CTypeRef(null, Variant)));
            Dictionary = new CFunction(CToken.Identifer(null, "Dictionary"), "Dictionary", "dictionary", TokenTypes.visPublic, FunctionType.Function,
                                       dicArgs, new CTypeRef(null, new CDictionaryType(new CTypeRef(null, Variant))));
            Dictionary.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));

            CArgumentList refArgs = new CArgumentList();

            refArgs.Add(new CArgument(CToken.Keyword(null, "byval"),
                                      CToken.Identifer(null, "func"),
                                      new CTypeRef(null, BuiltIns.String)));
            GetRef = new CFunction(CToken.Identifer(null, "GetRef"), "GetRef", "getref", TokenTypes.visPublic, FunctionType.Function, refArgs,
                                   new CTypeRef(null, BuiltIns.FunctionPlaceHolder));
            GetRef.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));

            // add string ienumerator interface
            CToken     ifaceName = CToken.Identifer(null, "System.Collections.Generic.IEnumerable`1<char>");
            CInterface iface     = new CInterface(ifaceName, ifaceName);

            iface.GenericParameters.Add(Character);
            String.AddInterface(new CTypeRef(null, iface));
        }
 public CClassConst(CClass declaringClass, CConst myConst)
     : base(myConst.Token, myConst.Name.Value, "const", 1, false)
 {
     this.declaringClass = declaringClass;
     this.myConst = myConst;
     Declared[0] = myConst;
     myConst.ClassConst = this;
 }
 protected internal virtual bool internalCanGenerate(CClass _class)
 {
     if (_class.Attributes.contains("ExecuteOnClient"))
     {
         return(false);
     }
     return(true);
 }
        public CClass BuildSqlScriptClass(KDataStoreTestProject sqlTestKProject)
        {
            var @class = new CClass("SqlScript")
            {
                Namespace = new CNamespace()
                {
                    NamespaceName =
                        $"{sqlTestKProject.ProjectFullName}.DataAccess"
                },
                Implements = new List <CInterface>()
                {
                    new CInterface()
                    {
                        InterfaceName = "ISqlScript"
                    }
                }
            };

            AddNamespaceRefs(@class);

            @class.Constructor.Add(new CConstructor()
            {
                AccessModifier  = CAccessModifier.Public,
                ConstructorName = "SqlScript",
                Parameter       = new List <CParameter>()
                {
                    new CParameter()
                    {
                        Type = "string", ParameterName = "name"
                    }, new CParameter()
                    {
                        Type = "object", ParameterName = "parameters", DefaultValue = "null"
                    }
                },
                CodeSnippet = @"Name = name;
                                Parameters = parameters; "
            });

            @class.Property.Add(new CProperty()
            {
                Type = "string", PropertyName = "Name"
            });
            @class.Property.Add(new CProperty()
            {
                Type = "object", PropertyName = "Parameters"
            });

            @class.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Public, ReturnType = "ICommand", MethodName = "ToCommand", UseExpressionDefinition = true, CodeSnippet = "new EmbeddedSqlCommand(Name, Parameters);"
            });
            @class.Method.Add(new CMethod()
            {
                AccessModifier = CAccessModifier.Public, ReturnType = "IQuery<IEnumerable<T>>", MethodName = "ToQuery<T>", UseExpressionDefinition = true, CodeSnippet = "new EmbeddedSqlQuery<T>(Name, Parameters);"
            });

            return(@class);
        }
        public bool canGenerate(CClass _class)
        {
            if (_class.Attributes.contains("ExecuteAtCompiler"))
            {
                return(false);
            }

            return(internalCanGenerate(_class));
        }
        public static LogMessage Create(string Mes, CClass cclass, ICClassObject obj, ConsoleDebug.ActionResult act, LogEnums.ResultCode rescode, Exception excp)
        {
            var res = LogResult.Gen(act, rescode, excp);

            return(new LogMessage()
            {
                Message = Mes, CClass = cclass, Object = obj, Time = DateTime.Now.ToString("hh:mm:ss"), Result = res
            });
        }
Exemple #14
0
            public static IClass <T> Create <T>()
            {
                IClass <T> x;

                x = new CClass <T>();
                x.Act(new TT <T>());

                return(x);
            }
Exemple #15
0
 public DResult(CDebugResult res, string mes, ActionResult action, CClass cClass, ICClassObject obj, ConsoleColor ccolor = ConsoleColor.Green)
 {
     Result  = res;
     Message = mes;
     Action  = action;
     CColor  = ccolor;
     CClass  = cClass;
     Object  = obj;
 }
 public void VisitClass(CClass cclas)
 {
     if (canGenerate(cclas))
     {
         classname = cclas.RawName;
         visitor.VisitClass(cclas);
         classname = "";
     }
 }
        public override List <Card> HandleMulligan(List <Card> Choices, CClass opponentClass, CClass ownClass)
        {
            List <Card>   CardsToKeep = new List <Card>();
            List <string> WhiteList   = new List <string>();
            List <string> BlackList   = new List <string>();
            int           MaxManaCost = 1;

            bool HasCoin = Choices.Any(x => x.Name == "GAME_005");

            bool HasOneDrop = Choices.Any(x => x.Cost == 1);
            bool HasTwoDrop = Choices.Any(x => x.Cost == 2);

            WhiteList.Add("EX1_029"); //Leper Gnome
            WhiteList.Add("CS2_146"); //Southsea Deckhand, ID: CS2_146
            WhiteList.Add("EX1_010"); //Worgen Infiltrator, ID: EX1_010
            WhiteList.Add("CS2_188"); //Abusive Sergeant
            WhiteList.Add("FP1_004"); //Mad Scientist
            WhiteList.Add("GVG_043"); //Glaivezooka

            if (HasOneDrop)
            {
                WhiteList.Add("NEW1_031");                //Animal Companion
            }
            if (opponentClass == CClass.WARRIOR)
            {
                WhiteList.Add("CS2_203");//Ironbeak Owl
            }
            if (HasCoin)
            {
                WhiteList.Add("FP1_002");  //Haunted Creeper
                WhiteList.Add("NEW1_019"); //Knife Juggler
            }

            BlackList.Add("CS2_084");            //Hunter's Mark

            foreach (Card c in Choices)
            {
                if (BlackList.Contains(c.Name))
                {
                    continue;
                }

                if (WhiteList.Contains(c.Name))
                {
                    CardsToKeep.Add(c);
                    continue;
                }

                if (MaxManaCost > c.Cost)
                {
                    CardsToKeep.Add(c);
                }
            }

            return(CardsToKeep);
        }
Exemple #18
0
        private CClass BuildBaseDataServiceClass(CInterface dbProviderInterface)
        {
            var dataService = new CClass($"BaseDataService")
            {
                IsAbstract = true
            };

            dataService.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System"
                }
            });

            dataService.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = dbProviderInterface.Namespace
            });

            dataService.Namespace = new CNamespace
            {
                NamespaceName =
                    $"{_dataLayerKProject.CompanyName}.{_dataLayerKProject.ProjectName}{_dataLayerKProject.NamespaceSuffix}.Data.DataServices.Base"
            };
            dataService.Field.Add(new CField
            {
                AccessModifier = CAccessModifier.Protected,
                FieldName      = "DbProvider",
                FieldType      = $"I{_dataLayerKProject.ProjectName}DbProvider",
                IsReadonly     = true
            });

            var staticConstructor = new CConstructor
            {
                IsStatic        = true,
                AccessModifier  = CAccessModifier.Private,
                ConstructorName = "BaseDataService"
            };

            dataService.Constructor.Add(staticConstructor);

            var constructor = new CConstructor
            {
                ConstructorName = dataService.ClassName,
                AccessModifier  = CAccessModifier.Protected
            };

            constructor.Parameter.Add(new CParameter
            {
                ParameterName = "dbProvider",
                Type          = $"I{_dataLayerKProject.ProjectName}DbProvider"
            });
            constructor.CodeSnippet = "DbProvider = dbProvider ?? throw new ArgumentException(nameof(dbProvider));";
            dataService.Constructor.Add(constructor);


            return(dataService);
        }
        public void Classification_Resolver_2_4()
        {
            var space = new CSpace();

            var senior = new CClass()
            {
                Name = "Старший разработчик"
            };
            var middle = new CClass()
            {
                Name = "Средний разработчик"
            };
            var junior = new CClass()
            {
                Name = "Младший разработчик"
            };

            space.Classes.Add(senior);
            space.Classes.Add(middle);
            space.Classes.Add(junior);

            space.Objects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 6, databasePoints = 5, experience = 21, education = 4 }, "codePoints", "databasePoints", "experience", "education"));

            space.Objects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 5, databasePoints = 3, experience = 20, education = 4 }, "codePoints", "databasePoints", "experience", "education"));

            space.Objects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 2, databasePoints = 1, experience = 9, education = 3 }, "codePoints", "databasePoints", "experience", "education"));

            List <CObject> unknownObjects = new List <CObject>();

            unknownObjects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 7, databasePoints = 5, experience = 120, education = 5 }, "codePoints", "databasePoints", "experience", "education"));
            unknownObjects.Add(CObjectFactory.GetFromProperties(senior, new { codePoints = 6, databasePoints = 4, experience = 25, education = 4 }, "codePoints", "databasePoints", "experience", "education"));


            unknownObjects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 4, databasePoints = 4, experience = 25, education = 4 }, "codePoints", "databasePoints", "experience", "education"));
            unknownObjects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 3, databasePoints = 3, experience = 19, education = 3 }, "codePoints", "databasePoints", "experience", "education"));
            unknownObjects.Add(CObjectFactory.GetFromProperties(middle, new { codePoints = 5, databasePoints = 3, experience = 19, education = 3 }, "codePoints", "databasePoints", "experience", "education"));

            unknownObjects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 4, databasePoints = 2, experience = 7, education = 4 }, "codePoints", "databasePoints", "experience", "education"));
            unknownObjects.Add(CObjectFactory.GetFromProperties(junior, new { codePoints = 2, databasePoints = 3, experience = 9, education = 3 }, "codePoints", "databasePoints", "experience", "education"));

            CResolver resolver = new CResolver(space);

            int verifiedCount = 0;

            foreach (var obj in unknownObjects)
            {
                var calcClass = resolver.Resolve(obj);
                if (calcClass != null && calcClass.Equals(obj.Class))
                {
                    verifiedCount++;
                }
            }

            Assert.IsTrue(verifiedCount * 1.0 / unknownObjects.Count > 0.5);
        }
        static BuiltIns()
        {
            /* These aren't fully resolved; we need to use Cecil to load the appropriate .NET type defitinions in.
               See ClrImporter.LoadBuiltins. */
            Variant = new CClass("__Variant", null);
            Byte = new CClass("Byte", false);
            String = new CClass("String", true);
            Int32 = new CClass("Int32", true);
            Int64 = new CClass("Int64", true);
            Character = new CClass("Character", false);
            Boolean = new CClass("Boolean", true);
            Date = new CClass("Date", true);
            Double = new CClass("Double", true);
            Object = Variant;
            DbNull = new CClass("DbNull", false);
            Nothing = new CClass("Nothing", false);
            Nothing.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            Void = new CClass("__Void", false);
            FunctionPlaceHolder = new CClass("__FunctionPlaceHolder", false);
            FunctionPlaceHolder.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));
            SubPlaceHolder = new CClass("__SubPlaceHolder", false);
            SubPlaceHolder.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));

            SetupGlobalTypes();

            CArgumentList arrArgs = new CArgumentList();
            arrArgs.Add(new CArgument(CToken.Keyword(null, "byval"),
                CToken.Identifer(null, "arglist"),
                new CTypeRef(null, Variant)));
            Array = new CFunction(CToken.Identifer(null, "Array"), "Array", "array", TokenTypes.visPublic, FunctionType.Function,
                arrArgs, new CTypeRef(null, new CArrayType(new CTypeRef(null, Variant), 1)));
            Array.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));

            CArgumentList dicArgs = new CArgumentList();
            dicArgs.Add(new CArgument(CToken.Keyword(null, "byval"),
                CToken.Identifer(null, "arglist"),
                new CTypeRef(null, Variant)));
            Dictionary = new CFunction(CToken.Identifer(null, "Dictionary"), "Dictionary", "dictionary", TokenTypes.visPublic, FunctionType.Function,
                dicArgs, new CTypeRef(null, new CDictionaryType(new CTypeRef(null, Variant))));
            Dictionary.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));

            CArgumentList refArgs = new CArgumentList();
            refArgs.Add(new CArgument(CToken.Keyword(null, "byval"),
                CToken.Identifer(null, "func"),
                new CTypeRef(null, BuiltIns.String)));
            GetRef = new CFunction(CToken.Identifer(null, "GetRef"), "GetRef", "getref", TokenTypes.visPublic, FunctionType.Function, refArgs,
                new CTypeRef(null, BuiltIns.FunctionPlaceHolder));
            GetRef.Attributes.Add(CToken.Identifer(null, "ExecuteAnywhere"), new CTypeRef(null, CToken.Identifer(null, "ExecuteAnywhereAttribute")));

            // add string ienumerator interface
            CToken ifaceName = CToken.Identifer(null, "System.Collections.Generic.IEnumerable`1<char>");
            CInterface iface = new CInterface(ifaceName, ifaceName);
            iface.GenericParameters.Add(Character);
            String.AddInterface(new CTypeRef(null, iface));
        }
Exemple #21
0
        public void HashCode_NullableStructNoValue_NoNullRefException()
        {
            // Arrange
            var obj1 = new CClass(3, null);

            // Act
            var hash1 = obj1.GetHashCode();

            // Assert
            Assert.NotEqual(0, hash1);
        }
Exemple #22
0
        public void AddToModelAsListMethods(CClass extensionsClass, CClass domainModelClass, CProtoFile protoFile, string protoNamespace)
        {
            var alias = "ProtoAlias";

            extensionsClass.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = new CNamespace {
                    NamespaceName = protoNamespace
                }
            });
            extensionsClass.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System.Collections.Generic"
                }
            });
            extensionsClass.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System.Linq"
                }
            });
            extensionsClass.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "Google.Protobuf.Collections"
                }
            });

            {
                if (!protoFile.ProtoMessage.Exists(m => m.MessageName == domainModelClass.ClassName))
                {
                    return;
                }

                var toModelMethod = new CMethod
                {
                    IsStatic          = true,
                    IsExtensionMethod = true,
                    ReturnType        = $"IEnumerable<{domainModelClass.Namespace.NamespaceName}.{domainModelClass.ClassName}>",
                    MethodName        = "ToModel"
                };

                //todo: create method for fully qualified name
                var parameterType = string.Empty;

                parameterType = $"RepeatedField<{alias}.{domainModelClass.ClassName}>";
                toModelMethod.Parameter.Add(new CParameter {
                    Type = parameterType, ParameterName = "source"
                });

                var codeWriter = new CodeWriter();
                codeWriter.WriteLine($"return source.Select(s => s.ToModel()).ToList();");
                toModelMethod.CodeSnippet = codeWriter.ToString();
                extensionsClass.Method.Add(toModelMethod);
            }
        }
Exemple #23
0
        private CClass BuildDbProviderClass(CInterface dbProviderInterface)
        {
            var dbProvider = new CClass($"{_dataLayerKProject.ProjectName}DbProvider");

            dbProvider.Implements.Add(dbProviderInterface);
            dbProvider.Namespace = new CNamespace
            {
                NamespaceName =
                    $"{_dataLayerKProject.CompanyName}.{_dataLayerKProject.ProjectName}{_dataLayerKProject.NamespaceSuffix}.Data.Providers"
            };
            return(dbProvider);
        }
        public CClass BuildAssemblyExtensionsClass(KDataStoreTestProject sqlTestKProject)
        {
            var @class = new CClass("AssemblyExtensions")
            {
                AccessModifier = CAccessModifier.Internal,
                IsStatic       = true,
                Namespace      = new CNamespace()
                {
                    NamespaceName =
                        $"{sqlTestKProject.ProjectFullName}.Extensions"
                }
            };

            AddNamespaceRefs(@class);

            @class.Method.Add(new CMethod()
            {
                AccessModifier    = CAccessModifier.Internal,
                IsStatic          = true,
                IsExtensionMethod = true,
                ReturnType        = "string",
                MethodName        = "ReadToEndEmbeddedResource",
                Parameter         = new List <CParameter>()
                {
                    new CParameter()
                    {
                        Type = "Assembly", ParameterName = "assembly"
                    },
                    new CParameter()
                    {
                        Type = "string", ParameterName = "resourceName"
                    }
                },
                CodeSnippet = $@"if (assembly == null)
                                {{
                                    throw new ArgumentNullException(nameof(assembly));
                                }}

                                var stream = assembly.GetManifestResourceStream(resourceName);
                                if (stream == null)
                                {{
                                    throw new InvalidOperationException($""Embedded resource {{resourceName}} was not found in assembly <{{assembly.FullName}}>"");
                                }}

                                using (stream)
                                using (var reader = new StreamReader(stream))
                                {{
                                    return reader.ReadToEnd();
                                }}"
            });

            return(@class);
        }
        public void Classification_Resolver_2_3()
        {
            var space = new CSpace();
            var cl1   = new CClass()
            {
                Name = "Plus"
            };
            var cl2 = new CClass()
            {
                Name = "Minus"
            };
            var cl3 = new CClass()
            {
                Name = "AbsMinus"
            };

            space.Classes.Add(cl1);
            space.Classes.Add(cl2);
            space.Classes.Add(cl3);

            // 1 четверть
            space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 1, y = 1 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 1, y = 2 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 2, y = 1 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 2, y = 2 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl1, new { x = 3, y = 3 }, "x", "y"));

            // 2 четверть
            space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -1, y = 1 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -1, y = 2 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -2, y = 1 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -2, y = 2 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl2, new { x = -3, y = 3 }, "x", "y"));

            // 3 четверть
            space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -1, y = -1 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -1, y = -2 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -2, y = -1 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -2, y = -2 }, "x", "y"));
            space.Objects.Add(CObjectFactory.GetFromProperties(cl3, new { x = -3, y = -3 }, "x", "y"));

            var resolver = new CResolver(space);
            var objCl1   = resolver.Resolve(CObjectFactory.GetFromProperties(new { x = 4, y = 4 }, "x", "y"));
            var objCl2   = resolver.Resolve(CObjectFactory.GetFromProperties(new { x = -4, y = -4 }, "x", "y"));
            var objCl3   = resolver.Resolve(CObjectFactory.GetFromProperties(new { x = -4, y = 4 }, "x", "y"));

            Assert.IsNotNull(objCl1);
            Assert.IsNotNull(objCl2);
            Assert.IsNotNull(objCl3);
            Assert.AreEqual("Plus", objCl1.Name);
            Assert.AreEqual("AbsMinus", objCl2.Name);
            Assert.AreEqual("Minus", objCl3.Name);
        }
        public void Write(CClass value, ICodeWriter codeWriter)
        {
            var rootPath = @"c:\temp\";

            var fileWriter = new FileWriter(rootPath);

            var visitor = _visualStudioVisitorBase;


            visitor.VisitCClass(value);

            var code = codeWriter.ToString();
        }
Exemple #27
0
        public void MakeTypedReference()
        {
            var o = new CClass()
            {
                a = new AStruct()
                {
                    b = "5"
                }
            };
            TypedReference r = TypedReference.MakeTypedReference(o, new FieldInfo[] { typeof(CClass).GetField("a"), typeof(AStruct).GetField("b") });

            Assert.AreEqual("5", TypedReference.ToObject(r));
        }
Exemple #28
0
        public override List<Card> HandleMulligan(List<Card> Choices, CClass opponentClass, CClass ownClass)
        {
            List<Card> CardsToKeep = new List<Card>();
            List<string> WhiteList = new List<string>();
            List<string> BlackList = new List<string>();
            int MaxManaCost = 1;

            bool HasCoin = Choices.Any(x => x.Name == "GAME_005");

            bool HasOneDrop = Choices.Any(x => x.Cost == 1);
            bool HasTwoDrop = Choices.Any(x => x.Cost == 2);

            WhiteList.Add("EX1_029");//Leper Gnome
            WhiteList.Add("CS2_146");//Southsea Deckhand, ID: CS2_146
            WhiteList.Add("EX1_010");//Worgen Infiltrator, ID: EX1_010
            WhiteList.Add("CS2_188");//Abusive Sergeant
            WhiteList.Add("FP1_004");//Mad Scientist
            WhiteList.Add("GVG_043");//Glaivezooka

            if (HasOneDrop)
                WhiteList.Add("NEW1_031");//Animal Companion

            if (opponentClass == CClass.WARRIOR)
                WhiteList.Add("CS2_203");//Ironbeak Owl

            if (HasCoin)
            {
                WhiteList.Add("FP1_002"); //Haunted Creeper
                WhiteList.Add("NEW1_019");//Knife Juggler
            }

            BlackList.Add("CS2_084");//Hunter's Mark

            foreach(Card c in Choices)
            {
                if(BlackList.Contains(c.Name))
                    continue;

                if(WhiteList.Contains(c.Name))
                {
                    CardsToKeep.Add(c);
                    continue;
                }

                if(MaxManaCost > c.Cost)
                    CardsToKeep.Add(c);
            }

            return CardsToKeep;
        }
Exemple #29
0
        private CClass BuildTestClass()
        {
            var testClass = new CClass($"DbTests")
            {
                Namespace = new CNamespace
                {
                    NamespaceName =
                        $"{_grpcServiceIntegrationTestDbProject.CompanyName}.{_grpcServiceIntegrationTestDbProject.ProjectName}{_grpcServiceIntegrationTestDbProject.NamespaceSuffix}.{_grpcServiceIntegrationTestDbProject.ProjectSuffix}"
                }
            };

            testClass.ClassAttribute.Add(new CClassAttribute {
                AttributeName = "TestClass"
            });

            testClass.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "System.Threading.Tasks"
                }
            });
            testClass.NamespaceRef.Add(new CNamespaceRef {
                ReferenceTo = new CNamespace {
                    NamespaceName = "Moq"
                }
            });
            testClass.NamespaceRef.Add(new CNamespaceRef
            {
                ReferenceTo = new CNamespace {
                    NamespaceName = "Microsoft.VisualStudio.TestTools.IntegrationTesting"
                }
            });

            //@testClass.NamespaceRef.Add(new SNamespaceRef { ReferenceTo = new SNamespace { NamespaceName = $"{protoService.ProtoFile.CSharpNamespace}" } });


            testClass.Method.Add(BuildSetupMethod());
            testClass.Method.Add(BuildDisposeMethod());

            /*
             * foreach (var rpc in protoService.Rpc)
             * {
             *  var method = GetTestMethod(rpc);
             *  @testClass.Method.Add(method);
             *
             *
             * }*/
            return(testClass);
        }
Exemple #30
0
        public static void Test()
        {
            CClass c1 = new CClass(".NET Programming I", 205, false);
            CClass c2 = new CClass("Database Programming I", 140, true);
            CClass c3 = new CClass("Objected Oriented Programming I", 204, true);

            CMod mod12 = new CMod("Mod 12");

            mod12.AddClass(c1);
            mod12.AddClass(c2);
            mod12.AddClass(c3);

            mod12.Debug();
            return;
        }
Exemple #31
0
        public static void Test()
        {
            CClass c1 = new CClass(".NET Programming I", 205, false);
            CClass c2 = new CClass("Database Programming I", 140, true);
            CClass c3 = new CClass("Objected Oriented Programming I", 204, true);

            CMod mod12 = new CMod("Mod 12");

            mod12.AddClass(c1);
            mod12.AddClass(c2);
            mod12.AddClass(c3);

            mod12.Debug();
            return;
        }
Exemple #32
0
        public CClass BuildExtensionsClass(KGrpcProject grpcKProject, CClass domainModelClass, CProtoFile protoFile,
                                           string protoNamespace)
        {
            var extensionClass = new CClass($"{domainModelClass.ClassName}Extensions")
            {
                IsStatic  = true,
                Namespace = new CNamespace
                {
                    NamespaceName =
                        $"{grpcKProject.CompanyName}.{grpcKProject.ProjectName}{grpcKProject.NamespaceSuffix}.{grpcKProject.ProjectSuffix}.Extensions"
                }
            };


            return(extensionClass);
        }
Exemple #33
0
        private void AddNamespaceRefs(CClass @class)
        {
            var namespaces = new List <string>
            {
                "Company.Datastore.Provider"
            };

            foreach (var ns in namespaces)
            {
                @class.NamespaceRef.Add(new CNamespaceRef
                {
                    ReferenceTo = new CNamespace {
                        NamespaceName = ns
                    }
                });
            }
        }
Exemple #34
0
        //Este exemplo tem namespaces com os identificadores A, B, C, D, E e F.
        //Os Namespaces B e C estão aninhados dentro dos Namespaces namespace A.
        //Os namespaces D, E e F estão todos no nível superior da unidade de compilação.
        //Na classe Program, observe como o ponto de entrada Main usa os tipos CClass, DClass e Fclass.
        //Como as diretivas using A.B.C e using D estão presentes no namespace E , o método Main
        //pode usar esses tipos diretamente.
        //Com FClass, o namespace deve ser especificado explicitamente porque F não está incluído dentro
        //de E com uma directiva using.
        static void Main(string[] args)
        {
            // Pode acessar o tipo CClass diretamente a partir de A.B.C.
            CClass var1 = new CClass();

            // Pode acessar o tipo DClass a partir de D
            DClass var2 = new DClass();

            // Precisa especificar explicitamente o namespace F
            F.FClass var3 = new F.FClass();

            // saida
            Console.WriteLine(var1);
            Console.WriteLine(var2);
            Console.WriteLine(var3);
            Console.ReadKey();
        }
        private static void ImportType(CProgram program, TypeDefinition typed, CClass type)
        {
            if (type.CecilType != null)
                return;
            type.CecilType = typed;

            if (typed.GenericParameters.Count > 0 || !IsClsCompliant(typed.CustomAttributes))
                return;

            if (typed.IsEnum)
            {
                type.IsObject = false;
                type.IsNumeric = true;
            }

            type.IsObject = !typed.IsValueType;

            type.SetSemanticallyComplete();
        }
 public CMemberOverload(CToken tok, CClass owner, string name)
     : base(tok, name, "override", 0, false)
 {
     this.owner = owner;
 }
 public CTypeRef(CNode owner, CClass type)
     : this(owner)
 {
     InternalLoad(type);
 }
 public virtual void Method()
 {
     CClass
     cc
     =
     new
     CClass
     ();
     cc.Method
     ();
 }
Exemple #39
0
 public void incAccessCount(CClass currentclass, CFunction currentfunction)
 {
     accesses++;
 }
Exemple #40
0
	public static int Main ()
	{
		SCMethod ();

		try {
			CMethod ();
			error ("static critical method called");
		} catch (MethodAccessException) {
		}

		SCClass sc = new SCClass ();
		sc.Method ();

		try {
			CClass c = new CClass (); // Illegal
			error ("critical object instantiated");
			c.Method ();	// Illegal
			error ("critical method called");
		} catch (MethodAccessException) {
		}

		try {
			doSCDev ();
			error ("security-critical-derived class error");
		} catch (TypeLoadException) {
		}

		try {
			doCMethodDev ();
		} catch (TypeLoadException) {
		}

		try {
			getpid ();
			error ("pinvoke called");
		} catch (MethodAccessException) {
		}

		try {
			MethodDelegate md = new MethodDelegate (CClass.StaticMethod);
			md ();
			error ("critical method called via delegate");
		} catch (MethodAccessException) {
		}

		try {
			CriticalClass.NestedClassInsideCritical.Method ();
		} catch (MethodAccessException) {
		}

		try {
			doSCInterfaceDev ();
		} catch (TypeLoadException) {
		}

		/*
		try {
			unsafeMethod ();
		} catch (VerificationException) {
		}
		*/

		try {
			Type type = Type.GetType ("Test");
			MethodInfo method = type.GetMethod ("TransparentReflectionCMethod");

			method.Invoke(null, null);
		} catch (MethodAccessException) {
			error ("transparent method not called via reflection");
		}

		try {
			Type type = Type.GetType ("Test");
			MethodInfo method = type.GetMethod ("ReflectionCMethod");

			method.Invoke(null, null);
		} catch (MethodAccessException) {
		}

		try {
			Type type = Type.GetType ("Test");
			MethodInfo method = type.GetMethod ("TransparentReflectionCMethod");
			InvokeDelegate id = new InvokeDelegate (method.Invoke);

			id (null, null);
		} catch (MethodAccessException) {
			error ("transparent method not called via reflection delegate");
		}

		try {
			Type type = Type.GetType ("Test");
			MethodInfo method = type.GetMethod ("ReflectionCMethod");
			InvokeDelegate id = new InvokeDelegate (method.Invoke);

			id (null, null);
		} catch (MethodAccessException) {
		}


		// wrapper 7
		try {
			CallStringTest ();
		} catch (MethodAccessException) {
			error ("string test failed");
		}

		try {
			doBadTransparentOverrideClass ();
			error ("BadTransparentOverrideClass error");
		} catch (TypeLoadException) {
		}

		try {
			doBadSafeCriticalOverrideClass ();
			error ("BadSafeCriticalOverrideClass error");
		} catch (TypeLoadException) {
		}

		try {
			doBadCriticalOverrideClass ();
			error ("BadCriticalOverrideClass error");
		} catch (TypeLoadException) {
		}

		new TransparentClassWithSafeCriticalDefaultConstructor ();
		try {
			new TransparentInheritFromSafeCriticalDefaultConstructor ();
		} catch (TypeLoadException) {
		}
		new SafeInheritFromSafeCriticalDefaultConstructor ();

		// arrays creation tests
		ArraysCreatedByTransparentCaller ();
		ArraysCreatedBySafeCriticalCaller ();
		// the above also calls ArraysCreatedBySafeCriticalCaller since (Transparent) Main cannot call it directly

		if (haveError)
			return 1;

//		Console.WriteLine ("ok");
		return 0;
	}
 protected override bool canUnionConvert(CClass klass)
 {
     foreach (CTypeRef tref in types)
     {
         if (tref.ActualType == null || !tref.ActualType.canConvertTo(klass))
             return false;
     }
     return true;
 }
Exemple #42
0
 public void add(CClass type)
 {
     add(type.Name, type);
 }
        public override void ConvertToArray(CClass type, int count)
        {
            base.ConvertToArray(type, count);

            EnsureDiminsionInitializerIsValid();
        }
    public static int Main()
    {
        SCMethod ();

        try {
            CMethod ();
            error ("static critical method called");
        } catch (MethodAccessException) {
        }

        SCClass sc = new SCClass ();
        sc.Method ();

        try {
            CClass c = new CClass (); // Illegal
            error ("critical object instantiated");
            c.Method ();	// Illegal
            error ("critical method called");
        } catch (MethodAccessException) {
        }

        try {
            doSCDev ();
            error ("security-critical-derived class error");
        } catch (TypeLoadException) {
        }

        try {
            doCMethodDev ();
        } catch (TypeLoadException) {
        }

        try {
            getpid ();
            error ("pinvoke called");
        } catch (MethodAccessException) {
        }

        try {
            MethodDelegate md = new MethodDelegate (CClass.StaticMethod);
            md ();
            error ("critical method called via delegate");
        } catch (MethodAccessException) {
        }

        try {
            CriticalClass.NestedClassInsideCritical.Method ();
        } catch (MethodAccessException) {
        }

        try {
            doSCInterfaceDev ();
        } catch (TypeLoadException) {
        }

        /*
        try {
            unsafeMethod ();
        } catch (VerificationException) {
        }
        */

        try {
            Type type = Type.GetType ("Test");
            MethodInfo method = type.GetMethod ("TransparentReflectionCMethod");

            method.Invoke(null, null);
        } catch (MethodAccessException) {
            error ("transparent method not called via reflection");
        }

        try {
            Type type = Type.GetType ("Test");
            MethodInfo method = type.GetMethod ("ReflectionCMethod");

            method.Invoke(null, null);
        } catch (MethodAccessException) {
        }

        try {
            Type type = Type.GetType ("Test");
            MethodInfo method = type.GetMethod ("TransparentReflectionCMethod");
            InvokeDelegate id = new InvokeDelegate (method.Invoke);

            id (null, null);
        } catch (MethodAccessException) {
            error ("transparent method not called via reflection delegate");
        }

        try {
            Type type = Type.GetType ("Test");
            MethodInfo method = type.GetMethod ("ReflectionCMethod");
            InvokeDelegate id = new InvokeDelegate (method.Invoke);

            id (null, null);
        } catch (MethodAccessException) {
        }

        //Console.WriteLine ("ok");

        if (haveError)
            return 1;

        return 0;
    }
 public virtual void Method()
 {
     //Console.WriteLine ("sc class");
     CClass cc = new CClass ();
     cc.Method ();
 }
Exemple #46
0
 public bool canAssign(CClass currentclass, CFunction currentfunction)
 {
     return false;
 }
Exemple #47
0
		public void MakeTypedReference ()
		{
			var o = new CClass () { a = new AStruct () { b = "5" }};
			TypedReference r = TypedReference.MakeTypedReference (o, new FieldInfo[] { typeof (CClass).GetField ("a"), typeof (AStruct).GetField ("b") });
			Assert.AreEqual ("5", TypedReference.ToObject (r));
		}
        public override bool canConvertTo(CClass klass)
        {
            CFunctionType target = klass as CFunctionType;
            if (target == null) return base.canConvertTo(klass);

            UpdateName();
            target.UpdateName();

            return Name == target.Name;
        }
Exemple #49
0
 public virtual void LoadType(CClass type)
 {
     this.type.InternalLoad(type);
 }
 public void VisitClass(CClass cclas)
 {
     if (canGenerate(cclas))
     {
         classname = cclas.RawName;
         visitor.VisitClass(cclas);
         classname = "";
     }
 }
        public override void LoadType(CClass type)
        {
            base.LoadType(type);

            EnsureDiminsionInitializerIsValid();
        }
 protected internal virtual bool internalCanGenerate(CClass _class)
 {
     if (_class.Attributes.contains("ExecuteOnClient"))
         return false;
     return true;
 }
 public CTypeRef(CNode owner)
 {
     this.owner = owner;
     name = null;
     type = null;
 }
        public bool canGenerate(CClass _class)
        {
            if (_class.Attributes.contains("ExecuteAtCompiler"))
                return false;

            return internalCanGenerate(_class);
        }
 internal void InternalLoad(CClass type)
 {
     ActualType = type;
 }
	public void TestCopyTo() {
		{
			bool errorThrown = false;
			try {
				Char[] c1 = new Char[2];
				c1.CopyTo(null, 2);
			} catch (ArgumentNullException) {
				errorThrown = true;
			}
			Assert("#E61", errorThrown);
		}
		{
			bool errorThrown = false;
			try {
				Char[] c1 = new Char[2];
				Char[,] c2 = new Char[2,2];
				c1.CopyTo(c2, 2);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("#E62", errorThrown);
		}
		{
			bool errorThrown = false;
			try {
				Char[,] c1 = new Char[2,2];
				Char[] c2 = new Char[2];
				c1.CopyTo(c2, -1);
			} catch (RankException) {
				errorThrown = true;
			}
			Assert("#E63", errorThrown);
		}
		{
			bool errorThrown = false;
			try {
				Char[,] c1 = new Char[2,2];
				Char[] c2 = new Char[2];
				c1.CopyTo(c2, 2);
			} catch (RankException) {
				errorThrown = true;
			}
			Assert("#E64", errorThrown);
		}
		{
			bool errorThrown = false;
			try {
				Char[] c1 = new Char[2];
				Char[] c2 = new Char[2];
				c1.CopyTo(c2, -1);
			} catch (ArgumentOutOfRangeException) {
				errorThrown = true;
			}
			Assert("#E65", errorThrown);
		}
		{
			bool errorThrown = false;
			try {
				Char[] c1 = new Char[2];
				Char[] c2 = new Char[2];
				c1.CopyTo(c2, 3);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("#E66", errorThrown);
		}
		{
			bool errorThrown = false;
			try {
				Char[] c1 = new Char[2];
				Char[] c2 = new Char[2];
				c1.CopyTo(c2, 1);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("#E67", errorThrown);
		}

		{
			bool errorThrown = false;
			try {
				String[] c1 = new String[2];
				// TODO: this crashes mono if there are null
				// values in the array.
				c1[1] = "hey";
				c1[0] = "you";
				Char[] c2 = new Char[2];
				c2[1] = 'a';
				c2[0] = 'z';
				c1.CopyTo(c2, 0);
			} catch (ArrayTypeMismatchException) {
				errorThrown = true;
			}
			Assert("#E68", errorThrown);
		}

		Char[] orig = {'a', 'b', 'c', 'd'};
		Char[] copy = new Char[10];
		Array.Clear(copy, 0, copy.Length);
		orig.CopyTo(copy, 3);
		AssertEquals("#E69", (char)0, copy[0]);
		AssertEquals("#E70", (char)0, copy[1]);
		AssertEquals("#E71", (char)0, copy[2]);
		AssertEquals("#E72", orig[0], copy[3]);
		AssertEquals("#E73", orig[1], copy[4]);
		AssertEquals("#E74", orig[2], copy[5]);
		AssertEquals("#E75", orig[3], copy[6]);
		AssertEquals("#E76", (char)0, copy[7]);
		AssertEquals("#E77", (char)0, copy[8]);
		AssertEquals("#E78", (char)0, copy[9]);

		{
			// The following is valid and must not throw an exception.
			bool errorThrown = false;
			try {
				int[] src = new int [0];
				int[] dest = new int [0];
				src.CopyTo (dest, 0);
			} catch (ArgumentException) {
				errorThrown = true;
			}
			Assert("#E79", !errorThrown);
		}

		{
			// bug #38812
			bool errorThrown = false;
			try {
				CClass[] src = new CClass [] { new CClass () };
				BClass[] dest = new BClass [1];

				src.CopyTo (dest, 0);

			} catch (ArrayTypeMismatchException) {
				errorThrown = true;
			}
			Assert("#E80", errorThrown);
		}
	}
 public virtual void Add(CClass type)
 {
     Add(new CTypeRef(this, type));
 }
 public CMemberOverload(CMemberOverload field, bool isUnionMember)
     : base(field.Token, field.Name, "override", 0, isUnionMember)
 {
     this.owner = field.DeclaringClass;
 }
Exemple #59
0
 public void incAssignmentCount(CClass currentclass, CFunction currentfunction)
 {
     throw new Exception("Const variable is readonly");
 }
Exemple #60
0
	static void ArraysCreatedByCriticalCaller ()
	{
		// Critical creating an array of a Critical type
		CClass[] c_array = new CClass [0];
		// Critical creating an array of a SafeCritical type
		SCClass[] sc_array = new SCClass [0];

		// Critical creating a multidimentional array of a Critical type
		CClass[,] c_multi = new CClass [0,0];
		// Critical creating a multidimentional array of a SafeCritical type
		SCClass[,] sc_multi = new SCClass [0,0];

		// Critical creating a jagged array of a Critical type
		CClass[][] c_jagged = new CClass [0][];
		// Critical creating a jagged array of a Critical type
		SCClass[][] sc_jagged = new SCClass [0][];
	}