コード例 #1
0
        public void TestParameterizedConstructor()
        {
            IObjectBuilder creator = new TypeCreator();
            TestType       actual  = creator.BuildUp <TestType>(new object[] { "hello" });

            Assert.IsInstanceOfType(actual, typeof(TestType));
            Assert.AreEqual <string>("hello", actual.Data);
        }
コード例 #2
0
        public object CreateInstance(string assemblyName, string typeName, params object[] args)
        {
            Assembly a = Assembly.Load(assemblyName);

            Type type = a.GetType(typeName);

            return(TypeCreator.CreateInstance(type, args));
        }
コード例 #3
0
        public SyntaxNode TestGenerate(Compilation compilation)
        {
            var types          = compilation.GetTypesFromSyntaxTrees(filter: symbols => true).ToArray();
            var addScopeMethod = compilation
                                 .GetTypeByMetadataName(ServiceCollectionExtensinsName)
                                 .GetMembers()
                                 .OfType <IMethodSymbol>()
                                 .Where(x => x.Name.Equals(nameof(ServiceCollectionServiceExtensions.AddScoped)))
                                 .FirstOrDefault();

            var serviceCollectionSymbols = compilation
                                           .GetTypeByMetadataName(IServiceCollectionName);

            var argument = CodeCreator.CreateMethodArgumentThis("services", serviceCollectionSymbols);
            var invokes  = new List <ExpressionSyntax>(types.Length);

            foreach (var item in types)
            {
                foreach (var abstractName in item.Interfaces)
                {
                    var arguments = new[]
                    {
                        CodeCreator.TypeOf(abstractName),
                        CodeCreator.TypeOf(item)
                    };
                    var invoke = CodeCreator.Invoke(IdentifierName(argument.Identifier), addScopeMethod, arguments);
                    invokes.Add(invoke);
                }
            }

            var myMethod = TypeCreator.CreateMethod
                           (
                methodName: "Registy",
                modificators: CodeCreator.Modificators(SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword),
                returnType: CodeCreator.Void(),
                arguments: new[] { argument },
                body: invokes.ToArray()
                           );

            var myClass = TypeCreator.CreateClass(
                name: "Registor",
                modificators: CodeCreator.Modificators(SyntaxKind.PublicKeyword, SyntaxKind.StaticKeyword),
                members: new[] { myMethod }
                );

            var myUnit = TypeCreator.CreateUnit(
                usings: new[] { compilation.GetNameSpace(addScopeMethod) },
                members: new[] { myClass }
                );

            return(myUnit);


            //var u1 = UsingStatement(Token( SyntaxKind.UsingKeyword));
            //var xxx = dymanicType.NormalizeWhitespace(elasticTrivia: true).ToFullString();
            //Microsoft.Extensions.DependencyInjection
            //context.AddSource("x1", SourceText.From(xxx, encoding: System.Text.Encoding.UTF8));
        }
コード例 #4
0
        public static IModifyResult GetModifyResultByType(string type)
        {
            Type resultType = null;

            ExceptionHelper.FalseThrow(typeDict.TryGetValue(type, out resultType),
                                       "Can not find ModifyResult type: {0}", type);

            return((IModifyResult)TypeCreator.CreateInstance(resultType));
        }
コード例 #5
0
ファイル: BaseQmlTests.cs プロジェクト: joachim-egger/Qml.Net
        protected BaseQmlMvvmTestsWithInstance()
        {
            InteropBehaviors.ClearQmlInteropBehaviors();
            InteropBehaviors.RegisterQmlInteropBehavior(new MvvmQmlInteropBehavior());

            RegisterType <T>();
            Instance = new T();
            TypeCreator.SetInstance(typeof(T), Instance);
        }
コード例 #6
0
        protected IDictionary CreateDictionaryFromMapping(DictionaryMapping mapping)
        {
            if (MappingRegistry.TypeMapper.TypeAnalyzer.IsGenericDictionary(mapping.Type))
            {
                return(TypeCreator.CreateDictionary(mapping.KeyType, mapping.ValueType));
            }

            return((IDictionary)TypeCreator.Instantiate(mapping.Type));
        }
コード例 #7
0
 public IStateManager GetObject()
 {
     if (this._Obj == null)
     {
         this._Obj = (IStateManager)TypeCreator.CreateInstance(this._StateType);
         this._Obj.LoadViewState(this._State);
     }
     return(this._Obj);
 }
コード例 #8
0
        public void TestParameterizedConstructorByTypeName()
        {
            IObjectBuilder creator       = new TypeCreator();
            string         quanlifedName = typeof(TestType).AssemblyQualifiedName;
            ITestType      actual        = creator.BuildUp <ITestType>(quanlifedName, new object[] { "hello" });

            Assert.IsInstanceOfType(actual, typeof(ITestType));
            Assert.AreEqual <string>("hello", actual.Data);
        }
コード例 #9
0
        public override void Boost
        (
            TypeCreator typeCreator,
            Expression expression,
            JProperty property,
            IDictionary <string, IFieldExpression> fields
        )
        {
            var parameter = GetParameter(fields, expression);
            var lastField = fields.LastOrDefault();

            //if (lastField.Value != null && (parameter.Type.FullName.Contains("IQueryable") || parameter.Type.FullName.Contains("IEnumerable") || parameter.Type.FullName.Contains("ICollection")))
            //{
            //    var fieldValue = CallMethod
            //    (
            //        typeCreator,
            //        parameter,
            //        (JArray)property.Value,
            //        SelectManyMethod,
            //        createAnonymousProjection: false
            //    );

            //    fields.Add(property.Name, fieldValue);
            //}
            //else
            //{
            if (lastField.Value == null)
            {
                var queryType          = typeof(IQueryable <>).MakeGenericType(parameter.Type);
                var queryTypeParameter = Expression.Parameter(queryType);

                var selectProjection = typeCreator.BuildProjection(parameter, (JArray)property.Value, false);
                var selectLambda     = selectProjection.GetLambdaExpression();
                var returnType       = selectProjection.Expression.Type.GetGenericArguments().Single();

                var selectCall = Expression.Call(typeof(Queryable), nameof(Queryable.SelectMany), new Type[] { parameter.Type, returnType }, queryTypeParameter, Expression.Quote(selectLambda));

                var fieldValue = new FieldExpression(selectCall, queryTypeParameter);
                fields.Add(property.Name, fieldValue);
            }
            else
            {
                var selectProjection = typeCreator.BuildProjection(parameter, (JArray)property.Value, false);
                var selectLambda     = selectProjection.GetLambdaExpression();
                var returnType       = selectProjection.Expression.Type.GetGenericArguments().Single();

                var groupByCall = lastField.Value.Expression;
                var selectCall  = Expression.Call(typeof(Queryable), nameof(Queryable.SelectMany), new Type[] { parameter.Type, returnType }, groupByCall, Expression.Quote(selectLambda));

                var fieldValue = new FieldExpression(selectCall, parameter);

                fieldValue.Parameter = lastField.Value.Parameter;
                fields.Remove(lastField.Key);
                fields.Add(property.Name, fieldValue);
            }
            //}
        }
コード例 #10
0
        private void AddDeviceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddForm addForm = new AddForm(new DeviceProperty());

            addForm.ShowDialog();
            if (addForm.ConfigObject != null)
            {
                TreeNode tn = this.treeView1.SelectedNode;
                if (tn != null)
                {
                    DeviceProperty property = (DeviceProperty)addForm.ConfigObject;
                    Config.Device  device   = new Config.Device
                    {
                        Caption         = property.Caption,
                        DeviceID        = property.DeviceID,
                        AssemblyFile    = property.AssemblyFile,
                        CommunicateType = property.CommunicateType,
                        DeviceType      = property.DeviceType,
                        Instance        = property.Instance,
                        Remarks         = property.Remarks
                    };

                    try
                    {
                        IObjectBuilder builder = new TypeCreator();
                        IRunDevice     runDev  = builder.BuildUp <IRunDevice>(property.AssemblyFile, property.Instance);

                        runDev.DeviceParameter.DeviceID = property.DeviceID;
                        runDev.DeviceDynamic.DeviceID   = property.DeviceID;
                        runDev.CommunicateType          = property.CommunicateType;
                        if (runDev.CommunicateType == CommunicateType.COM)
                        {
                            runDev.DeviceParameter.COM.Port = ComUtils.PortToInt(property.IoParameter1);
                            runDev.DeviceParameter.COM.Baud = property.IoParameter2;
                        }
                        else if (runDev.CommunicateType == CommunicateType.NET)
                        {
                            runDev.DeviceParameter.NET.RemoteIP   = property.IoParameter1;
                            runDev.DeviceParameter.NET.RemotePort = property.IoParameter2;
                        }
                        runDev.DeviceParameter.DeviceCode   = property.DeviceCode;
                        runDev.DeviceParameter.DeviceAddr   = property.DeviceAddr;
                        runDev.DeviceParameter.DeviceName   = property.DeviceName;
                        runDev.DeviceParameter.NET.WorkMode = property.WorkMode;
                        runDev.Initialize(runDev.DeviceParameter.DeviceID);

                        TreeNode parentNode = GetRootNode(tn);
                        AddDevice(parentNode.Tag.ToString(), device);
                    }
                    catch (Exception ex)
                    {
                        WriteLog(ex.Message);
                    }
                }
            }
        }
コード例 #11
0
ファイル: SumBooster.cs プロジェクト: fabiohvp/WorQLess.Net
        public override void Boost
        (
            TypeCreator typeCreator,
            Expression expression,
            JProperty property,
            IDictionary <string, IFieldExpression> fields
        )
        {
            var parameter = GetParameter(fields, expression);

            if (parameter.Type.FullName.Contains("IGrouping"))
            {
                var lastField       = fields.LastOrDefault();
                var entityType      = parameter.Type.GetGenericArguments().Last();
                var entityParameter = Expression.Parameter(entityType);

                var sumProjection = typeCreator.BuildProjection(entityParameter, (JArray)property.Value, false);
                var sumLamda      = sumProjection.GetLambdaExpression();

                var method = SumMethod1.MakeGenericMethod(entityType);

                if (lastField.Value == null)
                {
                    var sumCall = Expression.Call(method, parameter, sumLamda);

                    var fieldValue = new FieldExpression(sumCall, parameter);
                    fields.Add(property.Name, fieldValue);
                }
                else
                {
                    var groupByCall = lastField.Value.Expression;
                    var sumCall     = Expression.Call(method, parameter, sumLamda);

                    var selectLambda = Expression.Lambda(sumCall, parameter as ParameterExpression);
                    var selectCall   = Expression.Call(typeof(Queryable), "Select", new Type[] { parameter.Type, selectLambda.Body.Type }, groupByCall, Expression.Quote(selectLambda));

                    var fieldValue = new FieldExpression(selectCall, lastField.Value.Parameter);
                    fields.Remove(lastField.Key);
                    fields.Add(property.Name, fieldValue);
                }
            }
            else
            {
                var fieldValue = CallMethod
                                 (
                    typeCreator,
                    parameter,
                    (JArray)property.Value,
                    SumMethod2,
                    createAnonymousProjection: false
                                 );

                fields.Add(property.Name, fieldValue);
            }
        }
コード例 #12
0
ファイル: Meta.cs プロジェクト: micromiss/behaviac
        public static IInstanceMember CreateInstanceConst(string typeName, string valueStr)
        {
            if (_Creators.ContainsKey(typeName))
            {
                TypeCreator creator = _Creators[typeName];
                return(creator.CreateInstanceConst(typeName, valueStr));
            }

            Debug.Check(false);
            return(null);
        }
コード例 #13
0
        public static IInstanceMember CreateInstanceProperty(string typeName, string instance, IInstanceMember indexMember, uint varId)
        {
            if (_Creators.ContainsKey(typeName))
            {
                TypeCreator creator = _Creators[typeName];
                return(creator.CreateInstanceProperty(instance, indexMember, varId));
            }

            Debug.Check(false);
            return(null);
        }
コード例 #14
0
        public override void Boost
        (
            TypeCreator typeCreator,
            Expression expression,
            JProperty property,
            IDictionary <string, IFieldExpression> fields
        )
        {
            var parameter = GetParameter(fields, expression);
            var lastField = fields.LastOrDefault();

            if (lastField.Value == null)
            {
                var entityType      = parameter.Type;
                var entityParameter = parameter;
                var asQueryableCall = parameter;

                if (parameter.Type.FullName.Contains("IQueryable") || parameter.Type.FullName.Contains("IEnumerable") || parameter.Type.FullName.Contains("ICollection"))
                {
                    entityType      = parameter.Type.GetGenericArguments().Last();
                    entityParameter = Expression.Parameter(entityType);
                    asQueryableCall = AsQueryable(parameter);
                }
                else
                {
                    var queryType = typeof(IQueryable <>).MakeGenericType(parameter.Type);
                    parameter       = Expression.Parameter(queryType);
                    asQueryableCall = parameter;
                }

                var selectProjection = typeCreator.BuildProjection(entityParameter, (JArray)property.Value, false);
                var selectLambda     = selectProjection.GetLambdaExpression();

                var selectCall       = Expression.Call(typeof(Queryable), nameof(Queryable.Select), new Type[] { entityType, selectLambda.Body.Type }, asQueryableCall, Expression.Quote(selectLambda));
                var asEnumerableCall = Expression.Call(typeof(Enumerable), nameof(Enumerable.AsEnumerable), new Type[] { selectLambda.Body.Type }, selectCall);

                var fieldValue = new FieldExpression(asEnumerableCall, parameter);
                fields.Add(property.Name, fieldValue);
            }
            else
            {
                var selectProjection = typeCreator.BuildProjection(parameter, (JArray)property.Value, false);
                var selectLambda     = selectProjection.GetLambdaExpression();

                var groupByCall = lastField.Value.Expression;
                var selectCall  = Expression.Call(typeof(Queryable), nameof(Queryable.Select), new Type[] { parameter.Type, selectLambda.Body.Type }, groupByCall, Expression.Quote(selectLambda));

                var fieldValue = new FieldExpression(selectCall, parameter);

                fieldValue.Parameter = lastField.Value.Parameter;
                fields.Remove(lastField.Key);
                fields.Add(property.Name, fieldValue);
            }
        }
コード例 #15
0
        /// <summary>
        /// 反序列化
        /// </summary>
        /// <param name="dictionary"></param>
        /// <param name="type"></param>
        /// <param name="serializer"></param>
        /// <returns></returns>
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            ProcessProgress progress = (ProcessProgress)TypeCreator.CreateInstance(typeof(ProcessProgress));

            progress.MinStep     = dictionary.GetValue("MinStep", progress.MinStep);
            progress.MaxStep     = dictionary.GetValue("MaxStep", progress.MaxStep);
            progress.CurrentStep = dictionary.GetValue("CurrentStep", progress.CurrentStep);
            progress.StatusText  = dictionary.GetValue("StatusText", progress.StatusText);

            return(progress);
        }
コード例 #16
0
        public static ICustomizedProperty CreateCustomizedArrayItemProperty(string typeName, uint id, string name)
        {
            if (_Creators.ContainsKey(typeName))
            {
                TypeCreator creator = _Creators[typeName];
                return(creator.CreateCustomizedArrayItemProperty(id, name));
            }

            Debug.Check(false);
            return(null);
        }
コード例 #17
0
ファイル: WhereBooster.cs プロジェクト: fabiohvp/WorQLess.Net
        public override void Boost
        (
            TypeCreator typeCreator,
            Expression expression,
            JProperty property,
            IDictionary <string, IFieldExpression> fields
        )
        {
            var jArray    = (JArray)property.Value;
            var parameter = GetParameter(fields, expression);

            foreach (var item in jArray)
            {
                EvalItem(typeCreator, parameter, (JObject)item);
            }

            //domain.Models.DWControleSocial.FT_ReceitaMunicipio
            //if (fields.Any())
            //{
            //    var lastField = fields.Last();
            //    var returnType = lastField.Value.ReturnType.GetGenericArguments().LastOrDefault();
            //    var _expression = Boost2(typeCreator, returnType, (JArray)property.Value, expression, parameter)
            //        .Expression;
            //    var method = WhereMethod
            //        .MakeGenericMethod(returnType);
            //    var whereExpression = Expression.Call
            //    (
            //        method,
            //        lastField.Value.Expression,
            //        _expression
            //    );

            //    fields.Remove(lastField.Key);
            //    var fieldValue = new FieldExpression(whereExpression, lastField.Value.Parameter);
            //    fields.Add(property.Name, fieldValue);
            //}
            //else
            //{
            //    var returnType = expression.Type.GetGenericArguments().LastOrDefault();
            //    var _expression = Boost2(typeCreator, returnType, (JArray)property.Value, expression, parameter)
            //        .Expression;
            //    var method = WhereMethod
            //        .MakeGenericMethod(returnType);
            //    var whereExpression = Expression.Call
            //    (
            //        method,
            //        expression,
            //        _expression
            //    );

            //    var fieldValue = new FieldExpression(whereExpression, parameter);
            //    fields.Add(property.Name, fieldValue);
            //}
        }
コード例 #18
0
        public static ICustomizedProperty CreateProperty(string typeName, uint propId, string propName, string valueStr)
        {
            if (_Creators.ContainsKey(typeName))
            {
                TypeCreator creator = _Creators[typeName];
                return(creator.CreateProperty(propId, propName, valueStr));
            }

            Debug.Check(false);
            return(null);
        }
コード例 #19
0
        private string GetResResource(string originalPath)
        {
            string resPath = originalPath.Substring("res://".Length);

            string[] parts = resPath.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            ExceptionHelper.FalseThrow(parts.Length >= 2, Resources.DeluxeWebResource.E_InvalidContentLogoImagePath, originalPath);

            System.Type type = TypeCreator.GetTypeInfo(parts[0].Trim());

            return(GetPageHandler().ClientScript.GetWebResourceUrl(type, parts[1].Trim()));
        }
コード例 #20
0
ファイル: WhereBooster.cs プロジェクト: fabiohvp/WorQLess.Net
        private static Expression GetRule(TypeCreator typeCreator, Dictionary <string, JToken> props, Type returnType, IFieldExpression fieldExpression)
        {
            var rule = (IWorQLessRuleBooster)Reflection.CreateRule(returnType, props["name"].ToObject <string>(), new Type[] { returnType }, null);

            rule.FieldExpression = fieldExpression;
            rule.Value           = props["value"].ToObject <object>();

            return((Expression)rule
                   .GetType()
                   .GetProperty(nameof(IProjection <object, object> .Predicate))
                   .GetValue(rule));
        }
コード例 #21
0
ファイル: Emitter.cs プロジェクト: rasiths/visual-profiler
 public DynamicLoader(ISourceLocationProvider/*?*/ sourceLocationProvider, ILocalScopeProvider/*?*/ localScopeProvider)
 {
     this.sourceLocationProvider = sourceLocationProvider;
       this.localScopeProvider = localScopeProvider;
       this.emitter = new Emitter(this, sourceLocationProvider, localScopeProvider);
       this.initializingTraverser = new MetadataTraverser() { PostorderVisitor = this.emitter, TraverseIntoMethodBodies = true };
       this.typeBuilderAllocator = new TypeBuilderAllocater(this);
       this.typeCreator = new TypeCreator(this);
       this.memberBuilderAllocator = new MemberBuilderAllocator(this);
       this.mapper = new ReflectionMapper();
       this.builderMap = new Dictionary<object, object>();
 }
コード例 #22
0
        protected override void NotifyBeginType()
        {
            var creator = new TypeCreator(this);

            if (_pendingByRef > 0)
            {
                _pendingByRef--;
                creator.ByRef();
            }

            _creators.Push(creator);
        }
コード例 #23
0
        public static ICustomizedProperty CreateCustomizedProperty(string typeName, uint id, string name, string valueStr)
        {
            typeName = GetTypeName(typeName);
            if (_Creators.ContainsKey(typeName))
            {
                TypeCreator creator = _Creators[typeName];
                return(creator.CreateCustomizedProperty(id, name, valueStr));
            }

            Debug.Check(false);
            return(null);
        }
コード例 #24
0
        public static ICustomizedProperty CreateArrayItemProperty(string typeName, uint parentId, string parentName)
        {
            typeName = GetTypeName(typeName);
            if (_Creators.ContainsKey(typeName))
            {
                TypeCreator creator = _Creators[typeName];
                return(creator.CreateArrayItemProperty(parentId, parentName));
            }

            Debug.Check(false);
            return(null);
        }
コード例 #25
0
        /// <summary>
        /// 得到System.Type信息
        /// </summary>
        /// <returns></returns>
        public Type GetTypeInfo()
        {
            if (this.typeInfo == null)
            {
                if (this.Type.IsNotEmpty())
                {
                    this.typeInfo = TypeCreator.GetTypeInfo(this.Type);
                }
            }

            return(this.typeInfo);
        }
コード例 #26
0
        private System.Type GetActualType(DataType originalType)
        {
            System.Type actualType = typeof(System.String);

            DataTypeDescriptionAttribute typeDesp = AttributeHelper.GetCustomAttribute <DataTypeDescriptionAttribute>(originalType.GetType().GetField(originalType.ToString()));

            if (typeDesp != null && typeDesp.TypeDescription.IsNotEmpty())
            {
                actualType = TypeCreator.GetTypeInfo(typeDesp.TypeDescription);
            }

            return(actualType);
        }
コード例 #27
0
        private static JavaScriptConverter[] CreateGlobalCacheConverters()
        {
            List <JavaScriptConverter> converters = new List <JavaScriptConverter>();

            foreach (Type t in S_GlobalConverterTypesCache.Values)
            {
                converters.Add((JavaScriptConverter)TypeCreator.CreateInstance(t));
            }

            //converters.Add(InternalDateTimeConverter.Instance);

            return(converters.ToArray());
        }
コード例 #28
0
 private static object GetPropertyValue(SchemaObjectBase obj, SchemaPropertyDefine pd)
 {
     try
     {
         object defaultValue = TypeCreator.GetTypeDefaultValue(pd.DataType.ToRealType());
         return(obj.Properties.GetValue(pd.Name, defaultValue));
     }
     catch (System.Exception ex)
     {
         throw new SystemSupportException(string.Format("生成Snapshot或全文检索时,{0}属性值获取错误: {1}", pd.Name, ex.Message),
                                          ex);
     }
 }
コード例 #29
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        internal Dictionary <string, IPageModule> Create()
        {
            PageModuleElementCollection      configModules = PageModules;
            Dictionary <string, IPageModule> modules       = new Dictionary <string, IPageModule>(configModules.Count);

            foreach (PageModuleElement element in configModules)
            {
                IPageModule module = (IPageModule)TypeCreator.CreateInstance(element.Type);
                modules.Add(element.Name, module);
            }

            return(modules);
        }
コード例 #30
0
        /// <summary>
        /// 从XmlReader中读取
        /// </summary>
        /// <param name="reader">Xml阅读器对象</param>
        /// <param name="type">对象类型</param>
        public void ReadFromXml(XmlReader reader, System.Type type)
        {
            ExceptionHelper.FalseThrow <ArgumentNullException>(reader != null, "reader");
            ExceptionHelper.FalseThrow <ArgumentNullException>(type != null, "type");

            this.Clear();
            Dictionary <string, MemberInfo> miDict = GetMemberInfoDict(type);

            while (reader.EOF == false)
            {
                reader.Read();

                if (reader.IsStartElement("ORMapping"))
                {
                    this.tableName      = XmlHelper.GetAttributeValue(reader, "tableName", string.Empty);
                    this.QueryTableName = XmlHelper.GetAttributeValue(reader, "queryTableName", string.Empty);

                    reader.ReadToDescendant("Item");
                }

                if (reader.IsStartElement("Item"))
                {
                    string propName                = reader.GetAttribute("propertyName");
                    string subClassPropertyName    = reader.GetAttribute("subClassPropertyName");
                    string subClassTypeDescription = reader.GetAttribute("subClassTypeDescription");

                    MemberInfo mi = null;

                    if (miDict.TryGetValue(propName, out mi))
                    {
                        if (string.IsNullOrEmpty(subClassPropertyName) == false)
                        {
                            if (string.IsNullOrEmpty(subClassTypeDescription) == false)
                            {
                                mi = ORMapping.GetSubClassMemberInfoByName(subClassPropertyName,
                                                                           TypeCreator.GetTypeInfo(subClassTypeDescription));
                            }
                            else
                            {
                                mi = ORMapping.GetSubClassMemberInfoByName(subClassPropertyName, mi);
                            }
                        }

                        if (mi != null)
                        {
                            ReadItemFromXml(reader, type, mi);
                        }
                    }
                }
            }
        }
コード例 #31
0
        protected IList CreateCollectionFromMapping(CollectionMapping mapping, int count)
        {
            if (mapping.IsArray)
            {
                return(TypeCreator.CreateFixedCollection(mapping.Type, count));
            }

            if (MappingRegistry.TypeMapper.TypeAnalyzer.IsGenericCollection(mapping.Type))
            {
                return(TypeCreator.CreateList(mapping.CollectionType));
            }

            return((IList)TypeCreator.Instantiate(mapping.Type));
        }
コード例 #32
0
ファイル: EmitAssembly.cs プロジェクト: hlizard/boo
		void EmitAttributes(INodeWithAttributes node, CustomAttributeSetter setCustomAttribute, TypeCreator knownTypes)
		{
			foreach (Attribute attribute in node.Attributes)
				knownTypes.CreateAttributeTypes(attribute);
			foreach (Attribute attribute in node.Attributes)
				setCustomAttribute(GetCustomAttributeBuilder(attribute));
		}
コード例 #33
0
        public void Can_Create_Types_In_A_Non_Xaf_Context()
        {
            new PersistentClassInfo(Session.DefaultSession){Name = "Test"}.Save();
            var typeCreator =
                new TypeCreator(
                    new TypesInfo(new List<Type> {
                                                     typeof (PersistentClassInfo),
                                                     typeof (ExtendedCollectionMemberInfo),
                                                     typeof (ExtendedReferenceMemberInfo),
                                                     typeof (ExtendedCoreTypeMemberInfo),
                                                     typeof (InterfaceInfo)
                                                 }), new UnitOfWork(Session.DefaultSession.DataLayer));

            Type dynamicModule = typeCreator.GetDynamicModule();

            Assert.IsNotNull(dynamicModule);
            Assert.IsNotNull(dynamicModule.Assembly.GetTypes().Where(type => type.Name=="Test").FirstOrDefault());
        }
コード例 #34
0
        protected override void NotifyBeginType()
        {
            var creator = new TypeCreator(this);

            if (_pendingByRef > 0)
            {
                _pendingByRef--;
                creator.ByRef();
            }

            _creators.Push(creator);
        }
コード例 #35
0
ファイル: EmitAssembly.cs プロジェクト: hlizard/boo
		void EmitEventAttributes(Event node, TypeCreator knownTypes)
		{
			EventBuilder builder = (EventBuilder)GetBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
コード例 #36
0
ファイル: EmitAssembly.cs プロジェクト: hlizard/boo
		void EmitParameterAttributes(ParameterDeclaration node, TypeCreator knownTypes)
		{
			ParameterBuilder builder = (ParameterBuilder)GetBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
コード例 #37
0
ファイル: EmitAssembly.cs プロジェクト: hlizard/boo
		void EmitMethodAttributes(Method node, TypeCreator knownTypes)
		{
			MethodBuilder builder = GetMethodBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
コード例 #38
0
ファイル: EmitAssembly.cs プロジェクト: hlizard/boo
		void EmitConstructorAttributes(Constructor node, TypeCreator knownTypes)
		{
			ConstructorBuilder builder = (ConstructorBuilder)GetBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
コード例 #39
0
ファイル: EmitAssembly.cs プロジェクト: hlizard/boo
		void EmitTypeAttributes(TypeDefinition node, TypeCreator knownTypes)
		{
			TypeBuilder builder = GetTypeBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
コード例 #40
0
        protected void BindImplementationToServices(Container container, Type implementationType)
        {
            if (this.ServiceTypes.Count > 1)
            {
                var firstGenericType = this.ServiceTypes.FirstOrDefault(x => x.Type.IsGenericTypeDefinition);

                if (firstGenericType != null)
                    throw new StyletIoCRegistrationException(String.Format("Cannot create a multiple-service binding with an unbound generic type {0}", firstGenericType.Type.GetDescription()));

                var creator = new TypeCreator(implementationType, container);
                var registration = this.CreateRegistration(container, creator);

                foreach (var serviceType in this.ServiceTypes)
                {
                    container.AddRegistration(new TypeKey(serviceType.Type.TypeHandle, serviceType.Key ?? creator.AttributeKey), registration);
                }
            }
            else
            {
                this.BindImplementationToSpecificService(container, implementationType, this.ServiceTypes[0].Type, this.ServiceTypes[0].Key);
            }
        }
コード例 #41
0
        // Convenience...
        protected void BindImplementationToSpecificService(Container container, Type implementationType, Type serviceType, string key)
        {
            if (serviceType.IsGenericTypeDefinition)
            {
                var unboundGeneric = new UnboundGeneric(serviceType, implementationType, container, this.RegistrationFactory);
                container.AddUnboundGeneric(new TypeKey(serviceType.TypeHandle, key), unboundGeneric);
            }
            else
            {
                var creator = new TypeCreator(implementationType, container);
                var registration = this.CreateRegistration(container, creator);

                container.AddRegistration(new TypeKey(serviceType.TypeHandle, key ?? creator.AttributeKey), registration);
            }
        }
コード例 #42
0
ファイル: EmitAssembly.cs プロジェクト: hlizard/boo
		void EmitAttributes(TypeCreator knownTypes)
		{
			AttributeEmitVisitor visitor = new AttributeEmitVisitor(this, knownTypes);
			foreach (Module module in CompileUnit.Modules)
				module.Accept(visitor);
		}
コード例 #43
0
ファイル: EmitAssembly.cs プロジェクト: hlizard/boo
		void EmitFieldAttributes(TypeMember node, TypeCreator knownTypes)
		{
			FieldBuilder builder = GetFieldBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
コード例 #44
0
ファイル: EmitAssembly.cs プロジェクト: hlizard/boo
		void DefineTypes()
		{
			if (CompileUnit.Modules.Count == 0)
				return;

			var types = CollectTypes();
			foreach (var type in types)
				DefineType(type);

			foreach (var type in types)
			{
				DefineGenericParameters(type);
				DefineTypeMembers(type);
			}

			foreach (var module in CompileUnit.Modules)
				OnModule(module);

			var typeCreator = new TypeCreator(this, types);
			// TODO: we might need to create enumerations that appear in attributes before emitting the attributes.
			EmitAttributes(typeCreator);
			typeCreator.Run();
		}
コード例 #45
0
ファイル: EmitAssembly.cs プロジェクト: hlizard/boo
		void EmitPropertyAttributes(Property node, TypeCreator knownTypes)
		{
			PropertyBuilder builder = GetPropertyBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
コード例 #46
0
ファイル: EmitAssembly.cs プロジェクト: hlizard/boo
			public AttributeEmitVisitor(EmitAssembly emitter, TypeCreator knownTypes)
			{
				this._emitter = emitter;
				this._knownTypes = knownTypes;
			}
コード例 #47
0
ファイル: CreateCommand.cs プロジェクト: plkumar/jish
        public CreateCommand(TypeCreator typeCreator)
        {
            Trace.Assert(typeCreator != null);

              this.typeCreator = typeCreator;
        }