예제 #1
0
 public static void AddRandomCategories(this ITypeContext typeContext, Authentication authentication, int tryCount)
 {
     for (var i = 0; i < tryCount; i++)
     {
         typeContext.AddRandomCategory(authentication);
     }
 }
예제 #2
0
        public System.Type Compile(AssemblyGen assembly, ITypeContext context)
        {
            System.Type baseType;
            if (BaseType != null)
            {
                baseType = BaseType.ResolveType(context);
            }
            else
            {
                baseType = typeof(FSObject);
            }
            var generator = assembly.DefineType(Name, baseType, System.Reflection.TypeAttributes.Public, context);

            System.Type[] types = null;
            if (Implements != null)
            {
                types = Implements.Map(impl => impl.ResolveType(context)).AddLast(typeof(IFSObject));
            }
            else
            {
                types = new System.Type[1] {
                    typeof(IFSObject)
                };
            }
            generator.SetInterfaces(types);
            generator.Source = Source;
            generator.SetCustomAttribute(typeof(Runtime.RegisterAttribute), Utils.ReflectionHelpers.Register_Attr_Ctor, new object[] { Name });
            foreach (var member in Members)
            {
                member.CreateMember(generator);
            }
            return(generator.CreateType());
        }
예제 #3
0
 /// <summary>
 /// Initializes new instance of <see cref="MethodBodyGenerator"/>
 /// </summary>
 public MethodBodyGenerator(IMethodBase method, System.Reflection.Emit.ILGenerator generator, bool emitInfo = false) : base(generator, emitInfo)
 {
     Method     = method;
     ReturnType = method.ReturnType;
     Context    = method.Context;
     SyntaxTree = method.SyntaxBody;
 }
예제 #4
0
 public NewTypeViewModel(Authentication authentication, ITypeCategory category, ITypeTemplate template)
     : base(authentication, template, true)
 {
     this.category    = category;
     this.typeContext = category.GetService(typeof(ITypeContext)) as ITypeContext;
     this.DisplayName = Resources.Title_NewType;
 }
예제 #5
0
 public static void Generate(this ITypeContext context, Authentication authentication, int tryCount)
 {
     for (var i = 0; i < tryCount; i++)
     {
         context.Generate(authentication);
     }
 }
예제 #6
0
        public static async Task GenerateStandardAsync(this ITypeContext typeContext, Authentication authentication)
        {
            if (typeContext.GetService(typeof(ITypeCategoryCollection)) is ITypeCategoryCollection typeCategoryCollection)
            {
                var root = typeCategoryCollection.Root;
                {
                    await root.GenerateStandardTypeAsync(authentication);

                    await root.GenerateStandardFlagsAsync(authentication);
                }
                var category = await root.AddNewCategoryAsync(authentication);

                {
                    await category.GenerateStandardTypeAsync(authentication);

                    await category.GenerateStandardFlagsAsync(authentication);
                }
                var subCategory = await category.AddNewCategoryAsync(authentication);

                {
                    await subCategory.GenerateStandardTypeAsync(authentication);

                    await subCategory.GenerateStandardFlagsAsync(authentication);
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
예제 #7
0
        public void ExitContext(ITypeContext context)
        {
            ThrowHelper.Check(ReferenceEquals(_current, context), "Cannot exit non-current type context");
            ThrowHelper.Check(!ReferenceEquals(_root, context), "Cannot exit root type context");

            _current = ((TypeContext)context).Parent;
        }
예제 #8
0
        public ITypeContext EnterContext()
        {
            var ctx = new TypeContext(this, _current);

            _current = ctx;
            return(ctx);
        }
예제 #9
0
 public static void AddRandomTypes(this ITypeContext typeContext, Authentication authentication, int tryCount)
 {
     for (var i = 0; i < tryCount; i++)
     {
         AddRandomType(typeContext, authentication);
     }
 }
예제 #10
0
 public ParameterInfo GetParameterInfo(ITypeContext provider)
 {
     if (Type == null)
     {
         return(new ParameterInfo(Name, Index, TypeProvider.AnyType, IsVarArgs));
     }
     return(new ParameterInfo(Name, Index, Type.ResolveType(provider), IsVarArgs));
 }
예제 #11
0
 public static Task <IType> GetTypeAsync(this ITypeContext typeContext, string typeName)
 {
     if (typeContext.GetService(typeof(ITypeCollection)) is ITypeCollection typeCollection)
     {
         return(typeCollection.GetTypeAsync(typeName));
     }
     throw new NotImplementedException();
 }
예제 #12
0
 public static Task <ITypeCategory> GetTypeCategoryAsync(this ITypeContext typeContext, string categoryPath)
 {
     if (typeContext.GetService(typeof(ITypeCategoryCollection)) is ITypeCategoryCollection typeCategoryCollection)
     {
         return(typeCategoryCollection.GetCategoryAsync(categoryPath));
     }
     throw new NotImplementedException();
 }
예제 #13
0
 public static Task <ITypeCategory[]> GetTypeCategoriesAsync(this ITypeContext typeContext)
 {
     if (typeContext.GetService(typeof(ITypeCategoryCollection)) is ITypeCategoryCollection typeCategoryCollection)
     {
         return(typeCategoryCollection.GetCategoriesAsync());
     }
     throw new NotImplementedException();
 }
예제 #14
0
 public TypeGenerator(TypeBuilder builder, AssemblyGen assemblyGen, ITypeContext context)
 {
     this.assemblyGen = assemblyGen;
     Name             = builder.Name;
     _builder         = builder;
     BaseType         = _builder.BaseType;
     Context          = context;
 }
예제 #15
0
        public static async Task <IType> AddRandomTypeAsync(this ITypeContext typeContext, Authentication authentication)
        {
            if (typeContext.GetService(typeof(ITypeCategoryCollection)) is ITypeCategoryCollection typeCategoryCollection)
            {
                var category = await typeCategoryCollection.GetRandomTypeCategoryAsync();

                return(await AddRandomTypeAsync(category, authentication));
            }
            throw new NotImplementedException();
        }
예제 #16
0
 public CommonConversions(Document document, SemanticModel semanticModel,
                          TypeConversionAnalyzer typeConversionAnalyzer, SyntaxGenerator csSyntaxGenerator,
                          CSharpCompilation csCompilation, ITypeContext typeContext)
 {
     TypeConversionAnalyzer = typeConversionAnalyzer;
     Document          = document;
     _semanticModel    = semanticModel;
     CsSyntaxGenerator = csSyntaxGenerator;
     _csCompilation    = csCompilation;
     _typeContext      = typeContext;
 }
예제 #17
0
 public static void Generate(this ITypeContext context, Authentication authentication)
 {
     if (RandomUtility.Within(25) == true)
     {
         context.AddRandomCategory(authentication);
     }
     else
     {
         context.AddRandomType(authentication);
     }
 }
예제 #18
0
        public static void SetProperties <T>(this ITypeContext context, T typeToSetProperties) where T : class
        {
            foreach (var property in typeToSetProperties.GetType().GetProperties())
            {
                var instance = context.GetInstance(property.PropertyType);

                if (instance != null)
                {
                    typeToSetProperties.GetType().GetProperty(property.Name).SetValue(typeToSetProperties, instance);
                }
            }
        }
예제 #19
0
        public static async Task AddRandomTypesAsync(this ITypeContext typeContext, Authentication authentication, DataBaseSettings settings)
        {
            var minCount       = settings.TypeContext.MinTypeCount;
            var maxCount       = settings.TypeContext.MaxTypeCount;
            var count          = RandomUtility.Next(minCount, maxCount);
            var typeCollection = typeContext.GetService(typeof(ITypeCollection)) as ITypeCollection;

            while (typeCollection.Count < count)
            {
                await AddRandomTypeAsync(typeContext, authentication);
            }
        }
예제 #20
0
 public ObjectAssembler(WiringContext wiringContext, ObjectAssemblerSettings settings = null)
 {
     this.wiringContext = wiringContext;
     typeConverterProvider = wiringContext.ConverterProvider;
     xamlTypeRepository = wiringContext.TypeContext;
     typeRepository = wiringContext.TypeContext;
     typeOperations = new TypeOperations(typeRepository.TypeFactory);
     startMemberWriter = new StartMemberWriter(this);
     getObjectWriter = new GetObjectWriter(this);
     startObjectWriter = new StartObjectWriter(this, settings?.RootInstance);
     valueWriter = new ValueWriter(this);
 }
예제 #21
0
 public CommonConversions(Document document, SemanticModel semanticModel,
                          TypeConversionAnalyzer typeConversionAnalyzer, SyntaxGenerator csSyntaxGenerator,
                          CSharpCompilation csCompilation, ITypeContext typeContext, VisualBasicEqualityComparison visualBasicEqualityComparison)
 {
     TypeConversionAnalyzer = typeConversionAnalyzer;
     Document                      = document;
     _semanticModel                = semanticModel;
     CsSyntaxGenerator             = csSyntaxGenerator;
     _csCompilation                = csCompilation;
     _typeContext                  = typeContext;
     VisualBasicEqualityComparison = visualBasicEqualityComparison;
     WinformsConversions           = new WinformsConversions(typeContext);
 }
예제 #22
0
        public async Task TestInitializeAsync()
        {
            var dataBaseFilter = new DataBaseFilter(DataBaseFlags.Loaded | DataBaseFlags.Public | DataBaseFlags.NotLocked)
            {
                Settings = DataBaseSettings.Default
            };

            await this.TestContext.InitializeAsync(app);

            dataBase = await dataBaseFilter.GetDataBaseAsync(app);

            typeContext = dataBase.GetService(typeof(ITypeContext)) as ITypeContext;
        }
        public CSharpToJScriptConverter(ITypeContext context)
        {
            _context = context;

            // extract assembly references from the container ...
            var assemblies = _context as IAssemblyContainer;
            if(null != assemblies)
            {
                foreach(var assembly in assemblies.Assemblies)
                {
                    AddAssembly(assembly);
                }
            }
        }
예제 #24
0
        public static async Task <ITypeCategory> AddRandomCategoryAsync(this ITypeContext typeContext, Authentication authentication)
        {
            if (typeContext.GetService(typeof(ITypeCategoryCollection)) is ITypeCategoryCollection typeCategoryCollection)
            {
                var category = RandomUtility.Within(33) == true ? typeCategoryCollection.Root : await typeCategoryCollection.GetRandomTypeCategoryAsync();

                if (GetLevel(category, (i) => i.Parent) > 4)
                {
                    return(null);
                }
                return(await category.AddRandomCategoryAsync(authentication));
            }
            throw new NotImplementedException();
        }
예제 #25
0
 public static void ClassInit(TestContext context)
 {
     app = new CremaBootstrapper();
     app.Initialize(context, nameof(ITypeContext_DispatcherTest));
     cremaHost = app.GetService(typeof(ICremaHost)) as ICremaHost;
     cremaHost.Dispatcher.Invoke(() =>
     {
         authentication = cremaHost.Start();
         dataBase       = cremaHost.DataBases.Random();
         dataBase.Load(authentication);
         dataBase.Enter(authentication);
         dataBase.TypeContext.AddRandomItems(authentication);
         typeContext = dataBase.TypeContext;
     });
 }
예제 #26
0
 public static ITypeCategory AddRandomCategory(this ITypeContext typeContext, Authentication authentication)
 {
     if (RandomUtility.Within(33) == true)
     {
         return(typeContext.Root.AddRandomCategory(authentication));
     }
     else
     {
         var category = typeContext.Categories.Random();
         if (GetLevel(category, (i) => i.Parent) > 4)
         {
             return(null);
         }
         return(category.AddRandomCategory(authentication));
     }
 }
예제 #27
0
 public static async Task <ITypeItem> GenerateAsync(this ITypeContext typeContext, Authentication authentication)
 {
     if (RandomUtility.Within(25) == true)
     {
         if (typeContext.GetService(typeof(ITypeCategoryCollection)) is ITypeCategoryCollection typeCategoryCollection)
         {
             return((await typeCategoryCollection.GenerateCategoryAsync(authentication)) as ITypeItem);
         }
     }
     else
     {
         if (typeContext.GetService(typeof(ITypeCollection)) is ITypeCollection typeCollection)
         {
             return((await typeCollection.GenerateTypeAsync(authentication)) as ITypeItem);
         }
     }
     throw new NotImplementedException();
 }
예제 #28
0
        public static void GenerateStandard(this ITypeContext context, Authentication authentication)
        {
            var root = context.Root;
            {
                root.GenerateStandardType(authentication);
                root.GenerateStandardFlags(authentication);
            }

            var category = root.AddNewCategory(authentication);
            {
                category.GenerateStandardType(authentication);
                category.GenerateStandardFlags(authentication);
            }

            var subCategory = category.AddNewCategory(authentication);
            {
                subCategory.GenerateStandardType(authentication);
                subCategory.GenerateStandardFlags(authentication);
            }
        }
예제 #29
0
 public override System.Type ResolveType(ITypeContext provider)
 {
     if (Type == null)
     {
         if (GenericPrameters == null)
         {
             Type = provider.GetType(Name);
         }
         else
         {
             Type = provider.GetType(string.Concat(Name, '`', GenericPrameters.Count));
             if (Type == null)
             {
                 Type = TypeProvider.AnyType;
             }
             Type = Type.MakeGenericType(GenericPrameters.Map(p => p.ResolveType(provider)));
         }
     }
     return(Type);
 }
예제 #30
0
        internal static void Register(ITypeContext context, string lib, INodeList <TypeImport> imports)
        {
#if NETCOREAPP
            // todo not supported getTypes for netcoreapp
            var assemblyImport = Assembly.Load(lib);
#else
            var assemblyImport = Assembly.ReflectionOnlyLoad(lib);
#endif
            foreach (var import in imports)
            {
                TypeName typeName = import.TypeName;
                Type     type;
                if (typeName.Namespace == null)
                {
                    Type[] types = assemblyImport.GetExportedTypes();
                    type = types.FirstOrDefault(t => t.Name == typeName.Name);
                }
                else
                {
                    type = assemblyImport.GetType(typeName.FullName);
                }
                context.Register(import.Name, type);
            }
        }
예제 #31
0
 public EndMemberCommand(ObjectAssembler assembler, ITopDownValueContext topDownValueContext)
     : base(assembler)
 {
     this.topDownValueContext = topDownValueContext;
     typeContext = Assembler.WiringContext.TypeContext;
 }
예제 #32
0
 public override System.Type ResolveType(ITypeContext provider)
 {
     return(ElementType.ResolveType(provider).MakeArrayType(Rank));
 }
예제 #33
0
 public static Task AddItemsCreatedEventHandlerAsync(this ITypeContext typeContext, ItemsCreatedEventHandler <ITypeItem> handler)
 {
     return(typeContext.Dispatcher.InvokeAsync(() => typeContext.ItemsCreated += handler));
 }
 public XamlTypeConverterContext(ITypeContext typeContext)
 {
     TypeContext = typeContext;
 }
예제 #35
0
 public override void Compile(ITypeContext context)
 {
     foreach(var cc in context)
         this.Compile(cc);
 }
예제 #36
0
 public WiringContext(ITypeContext typeContext, ITypeFeatureProvider typeFeatureProvider)
 {
     FeatureProvider = typeFeatureProvider;
     TypeContext = typeContext;
 }
예제 #37
0
 public WiringContext(ITypeContext typeContext, IContentPropertyProvider contentPropertyProvider, ITypeConverterProvider converterProvider)
 {
     TypeContext = typeContext;
     ContentPropertyProvider = contentPropertyProvider;
     ConverterProvider = converterProvider;
 }
예제 #38
0
 public ProtoParser(ITypeContext typingCore)
 {
     this.typingCore = typingCore;
     stack = new Context();
 }