public void InitializeTypeMapper(ITypeMapper typeMapper)
        {
            var thisAssembly = Assembly.GetAssembly(GetType());

            foreach (var type in thisAssembly.GetTypes())
            {
                if (!type.IsConcrete())
                    continue;

                var interfaceName = "I" + type.Name;

                var interface_ = type.GetInterface(interfaceName);

                if (interface_ == null)
                    continue;

                // This was tricky to figure out, just getting the interface will get
                // you the generic type w/o generic parameters, not the generic type
                // definition.
                var mappedInterface = (interface_.IsGenericType)
                                          ? interface_.GetGenericTypeDefinition()
                                          : interface_;

                var mappedType = (type.IsGenericType)
                                     ? type.GetGenericTypeDefinition()
                                     : type;

                typeMapper.Map(mappedInterface, mappedType);
            }
        }
示例#2
0
		public NewDelegate(Type delegateType, Operand target, string methodName, ITypeMapper typeMapper)
		{
			_delegateType = delegateType;
			_target = target;
		    _typeMapper = typeMapper;
		    Initialize(target.GetReturnType(typeMapper), methodName);
		}
示例#3
0
 public DataSourceRootNode(ITypeMapper typeMapper, IPomonaDataSource dataSource)
     : base(typeMapper, null, "/")
 {
     if (dataSource == null)
         throw new ArgumentNullException("dataSource");
     this.dataSource = dataSource;
 }
示例#4
0
        public string GetDeleteSql(ITypeMapper mapper, string whereSql)
        {
            if (string.IsNullOrEmpty(whereSql))
                return string.Format("Delete From {0}", DecorateName(mapper.TableName));

            return string.Format("Delete From {0} Where {1}", DecorateName(mapper.TableName), whereSql);
        }
        public void InitializeTypeMapper(ITypeMapper typeMapper)
        {
            typeMapper.Map<IList, ArrayList>();
            typeMapper.Map<IDictionary, Hashtable>();

            typeMapper.Map(typeof(IList<>), typeof(List<>));
            typeMapper.Map(typeof(IDictionary<,>), typeof(Dictionary<,>));
        }
 public PomonaHttpQueryTransformer(ITypeMapper typeMapper, QueryExpressionParser parser)
 {
     if (typeMapper == null)
         throw new ArgumentNullException("typeMapper");
     if (parser == null)
         throw new ArgumentNullException("parser");
     this.typeMapper = typeMapper;
     this.parser = parser;
 }
示例#7
0
 public UriResolver(ITypeMapper typeMapper, IBaseUriProvider baseUriProvider)
 {
     if (typeMapper == null)
         throw new ArgumentNullException("typeMapper");
     if (baseUriProvider == null)
         throw new ArgumentNullException("baseUriProvider");
     this.typeMapper = typeMapper;
     this.baseUriProvider = baseUriProvider;
 }
示例#8
0
文件: Delta.cs 项目: BeeWarloc/Pomona
 protected Delta(object original, TypeSpec type, ITypeMapper typeMapper, Delta parent = null)
 {
     if (original == null) throw new ArgumentNullException("original");
     if (type == null) throw new ArgumentNullException("type");
     if (typeMapper == null) throw new ArgumentNullException("typeMapper");
     Original = original;
     Type = type;
     TypeMapper = typeMapper;
     this.parent = parent;
 }
示例#9
0
 public InsertDataCommand(ICommandPerformer<string> exec, ICache cache, ITypeMapper mapper, EntityData value)
 {
     this.value = value;
     this.cache = cache;
     this.executor = exec;
     this.schema = cache.Pick<Document>();
     this.nameSpace = schema.Settings[Keys.Namespace];
     this.mapper = mapper;
     this.properties = schema.Entities.Single(x => x.Name == value.EntityName).Properties;
 }
示例#10
0
 protected PathNode(ITypeMapper typeMapper, PathNode parent, string name)
 {
     if (typeMapper == null)
         throw new ArgumentNullException("typeMapper");
     if (name == null)
         throw new ArgumentNullException("name");
     this.typeMapper = typeMapper;
     this.parent = parent;
     this.name = name;
 }
示例#11
0
        public static ITypeMapper Creator()
        {
            if (instance == null)
            {
                string typeName = ConfigManager.SettingsSection.AppSettings["typeMapper"].Value;
                instance = (ITypeMapper)Activator.CreateInstance(Type.GetType(typeName));
            }

            return instance;
        }
示例#12
0
        void Initialize(ITypeMapper typeMapper)
        {
            if (_initialized) return;
            _initialized = true;

            // TODO: proper checking as in specification
            if (_ifTrue.GetReturnType(typeMapper) != _ifFalse.GetReturnType(typeMapper))
                throw new ArgumentException(Properties.Messages.ErrInvalidConditionalVariants);

            if (_cond.GetReturnType(typeMapper) != typeMapper.MapType(typeof(bool))) _cond = _cond.IsTrue();
        }
示例#13
0
        public void CreateContext()
        {
            _typeMapper = new Moq.Mock<ITypeMapper>().Object;
            _random = new Moq.Mock<IRandom>().Object;
            _idGenerator = new Moq.Mock<IIdGenerator>().Object;

            var context = Create();

            Assert.That(context.TypeMapper, Is.Not.Null);
            Assert.That(context.Random, Is.Not.Null);
            Assert.That(context.IdGenerator, Is.Not.Null);
        }
示例#14
0
 public ResourceResolver(ITypeMapper typeMapper, NancyContext context, IRouteResolver routeResolver)
 {
     if (typeMapper == null)
         throw new ArgumentNullException("typeMapper");
     if (context == null)
         throw new ArgumentNullException("context");
     if (routeResolver == null)
         throw new ArgumentNullException("routeResolver");
     //if (routeResolver == null) throw new ArgumentNullException("routeResolver");
     this.typeMapper = typeMapper;
     this.context = context;
     this.routeResolver = routeResolver;
 }
        public IEnumerable<IGeneratedType> GenerateTypes(IEnumerable<ITypeDescription> typeDescriptions, ITypeMapper typeMapper)
        {
            if (typeDescriptions == null)
            {
                throw new ArgumentNullException("typeDescriptions");
            }

            if (typeMapper == null)
            {
                throw new ArgumentNullException("typeMapper");
            }

            Validate(typeDescriptions);

            var name = "PocoAssembly";
            var assemblyName = new AssemblyName(name);
            var appDomain = Thread.GetDomain();

            AssemblyBuilder assemblyBuilder;
            ModuleBuilder moduleBuilder;

            if (this.getTypeFromDiskAssembly)
            {
                assemblyBuilder = appDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave);
                moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName.Name, this.assemblyName);
            }
            else
            {
                assemblyBuilder = appDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
                moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName.Name);
            }

            var generatedTypes = new List<IGeneratedType>();
            foreach (var typeDescription in typeDescriptions)
            {
                var result = GenerateType(moduleBuilder, typeDescription, typeMapper);
                typeMapper.RegisterNewType(typeDescription, result);
                generatedTypes.Add(result);
            }

            if (this.getTypeFromDiskAssembly)
            {
                var generatedConvertedTypes = this.LoadFromDisk(assemblyBuilder, generatedTypes);

                return generatedConvertedTypes;
            }
            else
            {
                return generatedTypes;
            }
        }
示例#16
0
 /// <summary>
 /// Import framework options from an existing type
 /// </summary>
 public void SetFrameworkOptions(Type from, ITypeMapper mapper)
 {
     if (@from == null) throw new ArgumentNullException(nameof(@from));
     AttributeMap[] attribs = AttributeMap.Create(mapper, @from.Assembly);
     foreach (AttributeMap attrib in attribs)
     {
         if (attrib.AttributeType.FullName == "System.Runtime.Versioning.TargetFrameworkAttribute")
         {
             object tmp;
             if (attrib.TryGet("FrameworkName", out tmp)) TargetFrameworkName = (string)tmp;
             if (attrib.TryGet("FrameworkDisplayName", out tmp)) TargetFrameworkDisplayName = (string)tmp;
             break;
         }
     }
 }
示例#17
0
        /// <summary>
        /// Initialize a new object.
        /// </summary>
        /// <param name="nativeDbType">Native database type as used in stored procedures.</param>
        /// <param name="typeMapper">Mapps native to target data types and renders code items associated with data type.</param>
        /// <param name="precision">Native DB type precision - if applicable.</param>
        /// <param name="scale">Native DB type scale - if applicable.</param>
        public TypeInfo(string nativeDbType, ITypeMapper typeMapper, int precision, int scale)
        {
            this.typeMapper = typeMapper;
            this.precision = precision;
            this.scale = scale;

            this.NativeDbType = typeMapper.NativeDbType(nativeDbType);
            this.IsVariableLengthNativeType = typeMapper.IsVariableLengthNativeType(nativeDbType);
            this.Type = typeMapper.Type(nativeDbType, precision, scale);
            this.DefaultValue = typeMapper.DefaultValue(nativeDbType, precision, scale);
            this.IsValueType = typeMapper.IsValueType(nativeDbType);
            this.DbType = typeMapper.DbType(nativeDbType);
            this.NullableType = typeMapper.NullableType(nativeDbType, precision, scale);
            this.NullValue = typeMapper.NullValue(nativeDbType, precision, scale);
            this.DataType = typeMapper.GetType(nativeDbType, precision, scale);
        }
示例#18
0
        public CodeGenerator() {
            varTable = new Stack<Dictionary<string, ZOperand>>();
            typeTable = new Dictionary<string, Type>();
            typeStack = new Stack<TypeGen>();
            funcStack = new Stack<CodeGen>();

            name = "ZodiacConsole";
            var exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            if (exeDir == null) return;
            var exeFilePath = Path.Combine(exeDir, name + ".exe");
            Directory.CreateDirectory(exeDir);
            ag = new AssemblyGen(name, new CompilerOptions() { OutputPath = exeFilePath });
            st = ag.StaticFactory;
            exp = ag.ExpressionFactory;
            tm = ag.TypeMapper;
        }
示例#19
0
 public ResourceNode(ITypeMapper typeMapper,
     PathNode parent,
     string name,
     Func<object> valueFetcher,
     ResourceType expectedType)
     : base(typeMapper, parent, name)
 {
     this.value = new System.Lazy<object>(valueFetcher);
     this.expectedType = expectedType;
     this.type = new System.Lazy<ResourceType>(() =>
     {
         var localValue = Value;
         if (Value == null)
             return expectedType;
         return (ResourceType)typeMapper.GetClassMapping(localValue.GetType());
     });
 }
示例#20
0
 /// <summary>
 /// Adds a type mapper to the chain with given priority. If mapper privided as an external MBean, the
 /// <paramref name="objectName"/> arguments is the name of this MBean; otherwise it is null.
 /// </summary>
 /// <param name="mapper">The mapper instance. In case of external mapper this is a reference to proxy of the MBean.</param>
 /// <param name="objectName">In case of external mapper, this is its <see cref="ObjectName"/>.</param>
 /// <param name="priority">The priority of a mapper. Must be unique.</param>
 /// <exception cref="NonUniquePriorityException">Another mapper with privided priority is already registered.</exception>
 public void AddTypeMapper(ITypeMapper mapper, ObjectName objectName, int priority)
 {
     TypeMapperInfo newMapperInfo = new TypeMapperInfo(priority, objectName == null ? mapper.GetType().AssemblyQualifiedName : null, objectName);
      if (_mappers.ContainsKey(priority))
      {
     TypeMapperInfo exisingMapperInfo = _mapperInfos.Find(delegate(TypeMapperInfo info)
                                                             {
                                                                return info.Priority == priority;
                                                             });
     throw new NonUniquePriorityException(
        newMapperInfo.ObjectName != null ? newMapperInfo.ObjectName.ToString() : newMapperInfo.TypeName,
        exisingMapperInfo.ObjectName != null ? exisingMapperInfo.ObjectName.ToString() : exisingMapperInfo.TypeName,
        priority
        );
      }
      _mappers.Add(priority, mapper);
      _mapperInfos.Add(newMapperInfo);
 }
示例#21
0
        public Generator(IPocoGenertor pocoGenerator, ITypeMapper typeMapper)
        {
            if (pocoGenerator == null)
            {
                throw new ArgumentNullException("pocoGenerator");
            }

            this.typeCache = new Dictionary<Type, IGeneratedType>();
            this.typeDescritpionCache = new Dictionary<ITypeDescription, IGeneratedType>();
            this.methodCache = new Dictionary<MethodInfo, IGeneratedType>();
            this.typeMapper = typeMapper;
            this.pocoGenerator = pocoGenerator;

            if (this.typeMapper == null)
            {
                this.typeMapper = new DefaultTypeMapper(this.typeDescritpionCache);
            }
        }
示例#22
0
        public SharedType(Type mappedTypeInstance, ITypeMapper typeMapper)
        {
            if (mappedTypeInstance == null)
                throw new ArgumentNullException("mappedTypeInstance");
            if (typeMapper == null)
                throw new ArgumentNullException("typeMapper");

            this.mappedTypeInstance = mappedTypeInstance;
            mappedType = mappedTypeInstance.IsGenericType
                             ? mappedTypeInstance.GetGenericTypeDefinition()
                             : mappedTypeInstance;
            this.typeMapper = typeMapper;

            var dictMetadataToken = typeof (IDictionary<,>).UniqueToken();
            isDictionary = mappedTypeInstance.UniqueToken() == dictMetadataToken ||
                           mappedTypeInstance.GetInterfaces().Any(x => x.UniqueToken() == dictMetadataToken);

            if (!isDictionary)
            {
                if (mappedType != typeof (string))
                {
                    var collectionMetadataToken = typeof (IEnumerable<>).UniqueToken();
                    isCollection =
                        mappedTypeInstance.UniqueToken() == collectionMetadataToken ||
                        mappedTypeInstance.GetInterfaces().Any(x => x.UniqueToken() == collectionMetadataToken);
                }
            }

            if (isDictionary)
                SerializationMode = TypeSerializationMode.Dictionary;
            else if (isCollection)
                SerializationMode = TypeSerializationMode.Array;
            else
                SerializationMode = TypeSerializationMode.Value;

            GenericArguments = new List<TypeSpec>();

            if (mappedTypeInstance.IsEnum)
                JsonConverter = stringEnumConverter.Value;

            InitializeGenericArguments();
        }
示例#23
0
        /// <summary>Initializes a new instance of TableField class.</summary>
        /// <param name="table">Table or view to which this column belongs to.</param>
        /// <param name="columnName">Column name.</param>
        /// <param name="nameTemplate">Class item naming convention.</param>
        /// <param name="nativeDbType">Native DB type.</param>
        /// <param name="typeTemplate">Type metadata.</param>
        /// <param name="precision">Precision if numeric type.</param>
        /// <param name="scale">Scale if numeric type.</param>
        /// <param name="isNullable">Specifies whether the values of this column are nullable.</param>
        /// <param name="indexInParentTable">Index in parent table <see cref="FistCore.Generator.Table.Fields"/> array.</param>
        /// <param name="autoIncrement">Specifies whether the values of this column are automatically incremented.</param>
        /// <param name="dbDefaultValue">Optional textual representaion of default values configured in database.</param>
        /// <param name="maxLength">Maximum length of textual or byte array column.</param>
        /// <param name="isPrimaryKeyPart">Indicates whether the column is a part of the primary key.</param>
        /// <param name="isForeignKeyPart">Indicates whether the column is a part of a foreign key.</param>
        /// <param name="isUniqueConstraintPart">Indicates whether the column is a part of a unique constraint.</param>
        /// <param name="isAutoGenerated">Indicates whether the value of the field is automatically generated by database (eg. timestamp in SQL Server).</param>
        /// <param name="sequenceName">Optional sequence that increments value for this field. <b>Null</b> if the field is not auto-incremented or sequence does not exist.</param>
        public TableField(Table table, string columnName, IClassItemNamingConvention nameTemplate, string nativeDbType, ITypeMapper typeTemplate, int precision, int scale,
            bool isNullable, int indexInParentTable, bool autoIncrement, string dbDefaultValue, int maxLength, bool isPrimaryKeyPart, bool isForeignKeyPart, bool isUniqueConstraintPart,
            bool isAutoGenerated, string sequenceName)
        {
            this.Table = table;
            this.ColumnName = columnName;
            this.Precision = precision;
            this.Scale = scale;
            this.Names = new ClassItemNames(this.ColumnName, nameTemplate);
            if (nativeDbType != null && typeTemplate != null)
                this.Types = new TypeInfo(nativeDbType, typeTemplate, precision, scale);

            this.IsNullable = isNullable;
            this.Index = indexInParentTable;
            this.AutoIncrement = autoIncrement;
            this.DbDefaultValue = dbDefaultValue;
            this.Length = length;
            this.IsPrimaryKeyPart = isPrimaryKeyPart;
            this.IsForeignKeyPart = isForeignKeyPart;
            this.IsUniqueConstraintPart = isUniqueConstraintPart;
            this.IsAutoGenerated = isAutoGenerated;
            this.SequenceName = sequenceName;
            this.ExtendedProperties = null;
        }
示例#24
0
 public new ContextualOperand InvokeEquals(Operand right, ITypeMapper typeMapper)
 {
     return(base.InvokeEquals(right, TypeMapper));
 }
示例#25
0
 public override Type GetReturnType(ITypeMapper typeMapper) => _target.GetReturnType(typeMapper);
        // example based on the MSDN Explicit Interface Implementation Sample (explicit.cs)
        public static void GenExplicit2(AssemblyGen ag)
        {
            var st  = ag.StaticFactory;
            var exp = ag.ExpressionFactory;

            ITypeMapper m = ag.TypeMapper;
            // Declare the English units interface:
            TypeGen IEnglishDimensions = ag.Interface("IEnglishDimensions");
            {
                IEnglishDimensions.Method(typeof(float), "Length");
                IEnglishDimensions.Method(typeof(float), "Width");
            }

            // Declare the metric units interface:
            TypeGen IMetricDimensions = ag.Interface("IMetricDimensions");
            {
                IMetricDimensions.Method(typeof(float), "Length");
                IMetricDimensions.Method(typeof(float), "Width");
            }

            // Declare the "Box" class that implements the two interfaces:
            // IEnglishDimensions and IMetricDimensions:
            TypeGen Box = ag.Class("Box", typeof(object), IEnglishDimensions, IMetricDimensions);
            {
                FieldGen lengthInches = Box.Field(typeof(float), "lengthInches");
                FieldGen widthInches  = Box.Field(typeof(float), "widthInches");

                CodeGen g = Box.Public.Constructor()
                            .Parameter(typeof(float), "length")
                            .Parameter(typeof(float), "width")
                ;
                {
                    g.Assign(lengthInches, g.Arg("length"));
                    g.Assign(widthInches, g.Arg("width"));
                }
                // Explicitly implement the members of IEnglishDimensions:
                g = Box.MethodImplementation(IEnglishDimensions, typeof(float), "Length");
                {
                    g.Return(lengthInches);
                }
                g = Box.MethodImplementation(IEnglishDimensions, typeof(float), "Width");
                {
                    g.Return(widthInches);
                }
                // Explicitly implement the members of IMetricDimensions:
                g = Box.MethodImplementation(IMetricDimensions, typeof(float), "Length");
                {
                    g.Return(lengthInches * 2.54f);
                }
                g = Box.MethodImplementation(IMetricDimensions, typeof(float), "Width");
                {
                    g.Return(widthInches * 2.54f);
                }
                g = Box.Public.Static.Method(typeof(void), "Main");
                {
                    // Declare a class instance "myBox":
                    var myBox = g.Local(exp.New(Box, 30.0f, 20.0f));
                    // Declare an instance of the English units interface:
                    var eDimensions = g.Local(myBox.Cast(IEnglishDimensions));
                    // Declare an instance of the metric units interface:
                    var mDimensions = g.Local(myBox.Cast(IMetricDimensions));
                    // Print dimensions in English units:
                    g.WriteLine("Length(in): {0}", eDimensions.Invoke("Length"));
                    g.WriteLine("Width (in): {0}", eDimensions.Invoke("Width"));
                    // Print dimensions in metric units:
                    g.WriteLine("Length(cm): {0}", mDimensions.Invoke("Length"));
                    g.WriteLine("Width (cm): {0}", mDimensions.Invoke("Width"));
                }
            }
        }
示例#27
0
        // example based on the MSDN User-Defined Conversions Sample (structconversion.cs)
        public static void GenStructConversion(AssemblyGen ag)
        {
            var st  = ag.StaticFactory;
            var exp = ag.ExpressionFactory;

            TypeGen BinaryNumeral = ag.Struct("BinaryNumeral");
            {
                FieldGen value = BinaryNumeral.Private.Field(typeof(int), "value");

                CodeGen g = BinaryNumeral.Public.Constructor().Parameter(typeof(int), "value");
                {
                    g.Assign(value, g.Arg("value"));
                }

                g = BinaryNumeral.Public.ImplicitConversionFrom(typeof(int));
                {
                    g.Return(exp.New(BinaryNumeral, g.Arg("value")));
                }

                g = BinaryNumeral.Public.ImplicitConversionTo(typeof(string));
                {
                    g.Return("Conversion not yet implemented");
                }

                g = BinaryNumeral.Public.ExplicitConversionTo(typeof(int), "binary");
                {
                    ITypeMapper typeMapper = ag.TypeMapper;
                    g.Return(g.Arg("binary").Field("value"));
                }
            }

            TypeGen RomanNumeral = ag.Struct("RomanNumeral");
            {
                FieldGen value = RomanNumeral.Private.Field(typeof(int), "value");

                CodeGen g = RomanNumeral.Public.Constructor().Parameter(typeof(int), "value");
                {
                    g.Assign(value, g.Arg("value"));
                }

                g = RomanNumeral.Public.ImplicitConversionFrom(typeof(int));
                {
                    g.Return(exp.New(RomanNumeral, g.Arg("value")));
                }

                g = RomanNumeral.Public.ImplicitConversionFrom(BinaryNumeral, "binary");
                {
                    g.Return(exp.New(RomanNumeral, g.Arg("binary").Cast(typeof(int))));
                }

                g = RomanNumeral.Public.ExplicitConversionTo(typeof(int), "roman");
                {
                    ITypeMapper typeMapper = ag.TypeMapper;
                    g.Return(g.Arg("roman").Field("value"));
                }

                g = RomanNumeral.Public.ImplicitConversionTo(typeof(string));
                {
                    g.Return("Conversion not yet implemented");
                }
            }

            TypeGen Test = ag.Class("Test");
            {
                CodeGen g = Test.Public.Static.Method(typeof(void), "Main");
                {
                    var roman = g.Local(RomanNumeral);
                    g.Assign(roman, 10);
                    var binary = g.Local(BinaryNumeral);
                    // Perform a conversion from a RomanNumeral to a
                    // BinaryNumeral:
                    g.Assign(binary, roman.Cast(typeof(int)).Cast(BinaryNumeral));
                    // Performs a conversion from a BinaryNumeral to a RomanNumeral.
                    // No cast is required:
                    g.Assign(roman, binary);
                    g.WriteLine(binary.Cast(typeof(int)));
                    g.WriteLine(binary);
                }
            }
        }
 public GenericCommandGenerator(IDialect dialect, IColumnGenerator columnGenerator, ITypeMapper typeMapper)
 {
     this.Dialect         = dialect;
     this.ColumnGenerator = columnGenerator;
     this.TypeMapper      = typeMapper;
 }
示例#29
0
 public new ContextualOperand Property(string name, ITypeMapper typeMapper)
 {
     return(Property(name));
 }
示例#30
0
 public new Operand InvokeGetHashCode(ITypeMapper typeMapper)
 {
     return(InvokeGetHashCode());
 }
示例#31
0
 public void MapProperty <TSourceProp, TProp>(Expression <Func <TClass, TSourceProp, TProp> > poperty, ITypeMapper <TSourceProp, TProp> mapper)
 {
     Mapping.Add(new KeyValuePair <Expression, ITypeMapper>(poperty, mapper));
 }
示例#32
0
 public new ContextualOperand Invoke(string name, ITypeMapper typeMapper)
 {
     return(Invoke(name));
 }
示例#33
0
 public static void AddMapper <TS, TT>(ITypeMapper <TS, TT> o)
 {
     Mappers.Add(typeof(ITypeMapper <TS, TT>), o);
 }
示例#34
0
 public new ContextualOperand InvokeDelegate(ITypeMapper typeMapper)
 {
     return(InvokeDelegate());
 }
示例#35
0
        // example based on the MSDN User-Defined Conversions Sample (conversion.cs)
        public static void GenConversion(AssemblyGen ag)
        {
            var st  = ag.StaticFactory;
            var exp = ag.ExpressionFactory;

            TypeGen RomanNumeral = ag.Struct("RomanNumeral");
            {
                FieldGen value = RomanNumeral.Private.Field(typeof(int), "value");

                CodeGen g = RomanNumeral.Public.Constructor().Parameter(typeof(int), "value");
                {
                    g.Assign(value, g.Arg("value"));
                }

                // Declare a conversion from an int to a RomanNumeral. Note the
                // the use of the operator keyword. This is a conversion
                // operator named RomanNumeral:
                g = RomanNumeral.Public.ImplicitConversionFrom(typeof(int));
                {
                    // Note that because RomanNumeral is declared as a struct,
                    // calling new on the struct merely calls the constructor
                    // rather than allocating an object on the heap:
                    g.Return(exp.New(RomanNumeral, g.Arg("value")));
                }

                // Declare an explicit conversion from a RomanNumeral to an int:
                g = RomanNumeral.Public.ExplicitConversionTo(typeof(int), "roman");
                {
                    ITypeMapper typeMapper = ag.TypeMapper;
                    g.Return(g.Arg("roman").Field("value"));
                }

                // Declare an implicit conversion from a RomanNumeral to
                // a string:
                g = RomanNumeral.Public.ImplicitConversionTo(typeof(string));
                {
                    g.Return("Conversion not yet implemented");
                }
            }

            TypeGen Test = ag.Class("Test");
            {
                CodeGen g = Test.Public.Static.Method(typeof(void), "Main");
                {
                    var numeral = g.Local(RomanNumeral);

                    g.Assign(numeral, 10);

                    // Call the explicit conversion from numeral to int. Because it is
                    // an explicit conversion, a cast must be used:
                    g.WriteLine(numeral.Cast(typeof(int)));

                    // Call the implicit conversion to string. Because there is no
                    // cast, the implicit conversion to string is the only
                    // conversion that is considered:
                    g.WriteLine(numeral);

                    // Call the explicit conversion from numeral to int and
                    // then the explicit conversion from int to short:
                    var s = g.Local(numeral.Cast(typeof(short)));

                    g.WriteLine(s);
                }
            }
        }
示例#36
0
 public new Operand this[ITypeMapper typeMapper, params Operand[] indexes] => this[indexes];
示例#37
0
 public override Type GetReturnType(ITypeMapper typeMapper) => typeMapper.MapType(_value.GetType());
 private static void CreateFields(IClassItemNamingConvention classItemTemplate, ITypeMapper typeTemplate, Table table, DataTable fieldsData)
 {
     table.Fields = new TableField[fieldsData.Rows.Count];
     for (int i = 0; i < table.Fields.Length; i++)
     {
         DataRow row = fieldsData.Rows[i];
         table.Fields[i] = CreateTableFieldFromFieldDataRow(table, classItemTemplate, typeTemplate, row, i);
         if (table.Fields[i].IsPrimaryKeyPart)
             table.NumberOfPrimaryKeyFields++;
     }
 }
示例#39
0
 public KeyValueStoreMapper(IKeyValueStore <TK1, TV1> underlyingStore, ITypeMapper <TK, TK1> keyMapper, ITypeMapper <TV, TV1> valueMapper)
 {
     this.underlyingStore = Preconditions.CheckNotNull(underlyingStore, nameof(underlyingStore));
     this.keyMapper       = Preconditions.CheckNotNull(keyMapper, nameof(keyMapper));
     this.valueMapper     = Preconditions.CheckNotNull(valueMapper, nameof(valueMapper));
 }
示例#40
0
	    public override Type GetReturnType(ITypeMapper typeMapper) => _indexes.Length == 1 ? _t.MakeArrayType() : _t.MakeArrayType(_indexes.Length);
示例#41
0
 public new Operand InvokeToString(ITypeMapper typeMapper)
 {
     return(InvokeToString());
 }
示例#42
0
	    public override Type GetReturnType(ITypeMapper typeMapper) => _delegateType;
示例#43
0
 public new ContextualOperand Field(string name, ITypeMapper typeMapper)
 {
     return(Field(name));
 }
        protected ObservableCollectionMapper(ObservableCollection <TOut> mapTo, INotifyCollectionChanged mapFrom, ITypeMapper <TIn, TOut> mapper)
        {
            _mapper = mapper;
            _mapTo  = mapTo;
            foreach (object item in (mapFrom as IList))
            {
                if (item is TIn itemOut)
                {
                    mapTo.Add(mapper.MapType(itemOut));
                }
            }

            mapFrom.CollectionChanged += Collection_CollectionChanged;
        }
示例#45
0
 public new ContextualOperand Property(string name, ITypeMapper typeMapper, params Operand[] indexes)
 {
     return(Property(name, indexes));
 }
 public MapperConfiguration Add(ITypeMapper typeMapper)
 {
     TypeMappers.Add(typeMapper);
     return(this);
 }
示例#47
0
 public new ContextualOperand Invoke(string name, ITypeMapper typeMapper, params Operand[] args)
 {
     return(Invoke(name, args));
 }
 public MapperConfiguration AddFirst(ITypeMapper typeMapper)
 {
     TypeMappers.Insert(0, typeMapper);
     return(this);
 }
示例#49
0
 public new ContextualOperand InvokeDelegate(ITypeMapper typeMapper, params Operand[] args)
 {
     return(InvokeDelegate(args));
 }
示例#50
0
            public DynamicMethodGen Method(Type returnType, ITypeMapper typeMapper = null)
            {
                ITypeMapper mapper = typeMapper ?? new TypeMapper();

                return(new DynamicMethodGen(this, returnType, new Context(mapper, new StaticFactory(mapper), new ExpressionFactory(mapper))));
            }
示例#51
0
 public override Type GetReturnType(ITypeMapper typeMapper)
 {
     OperandExtensions.SetLeakedState(this, false);
     return(_operand.GetReturnType(typeMapper));
 }
示例#52
0
 public Context(ITypeMapper typeMapper, StaticFactory staticFactory, ExpressionFactory expressionFactory)
 {
     TypeMapper        = typeMapper;
     StaticFactory     = staticFactory;
     ExpressionFactory = expressionFactory;
 }
        private static TableField CreateTableFieldFromFieldDataRow(Table table, IClassItemNamingConvention classItemTemplate, ITypeMapper typeTemplate, DataRow col, int indexInParentTable)
        {
            string columnName = col["COLUMN_NAME"].ToString();
            string nativeDbType = col["DATA_TYPE"].ToString();
            int precision = (col["NUMERIC_PRECISION"] != DBNull.Value) ? Convert.ToInt32(col["NUMERIC_PRECISION"]) : 0;
            int scale = (col["NUMERIC_SCALE"] != DBNull.Value) ? Convert.ToInt32(col["NUMERIC_SCALE"]) : 0;
            bool isNullable = (col["IS_NULLABLE"].ToString().ToLowerInvariant() == "yes");
            int maxLength;
            bool isTextualOrBinary = (col["CHARACTER_MAXIMUM_LENGTH"] != DBNull.Value);
            if (isTextualOrBinary)
            {
                int maxCharsOrBytes = Convert.ToInt32(col["CHARACTER_MAXIMUM_LENGTH"]);
                maxLength = maxCharsOrBytes;
            }
            else
            {
                // Numeric types.
                maxLength = (col["ColumnLength"] != DBNull.Value) ? Convert.ToInt32(col["ColumnLength"]) : 0;
            }

            bool autoIncrement = (col["IsIdentity"] != DBNull.Value) && (Convert.ToInt32(col["IsIdentity"]) >= 1);
            string dbDefaultValue = col["COLUMN_DEFAULT"].ToString();
            bool isPrimaryKeyPart = (Convert.ToInt32(col["IsPrimaryKey"]) == 1);
            // IsForeignKeyPart isn't working for some reason. It will be processed later when fetching relations.
            bool isForeignKeyPart = (Convert.ToInt32(col["IsForeignKey"]) == 1);
            bool isUniqueConstraintPart = (Convert.ToInt32(col["HasUniqueConstraint"]) == 1);
            // Auto-generated flag. Fields that are auto-generated may not be inserted or updated.
            bool isComputed = (Convert.ToInt32(col["IsComputed"]) == 1);
            bool isRowVersion = (nativeDbType == "timestamp") || (nativeDbType == "rowversion");
            bool isAutoGenerated = (isComputed || isRowVersion);
            string sequenceName = (col["SequenceName"] != DBNull.Value) ? (string)col["SequenceName"] : null;

            TableField field = new TableField(table, columnName, classItemTemplate, nativeDbType, typeTemplate, precision, scale,
                isNullable, indexInParentTable, autoIncrement, dbDefaultValue, maxLength, isPrimaryKeyPart, isForeignKeyPart, isUniqueConstraintPart,
                isAutoGenerated, sequenceName);

            //int colSizeInBytes = Convert.ToInt32(row["ColumnLength"]);
            //table.Fields[i].Ordinal = Convert.ToInt32(row["ORDINAL_POSITION"]);
            return field;
        }
 public MssqlQueryBuilder(ITypeMapper typeMapper)
 {
     _parameters = new List <QueryParameter>();
     _typeMapper = typeMapper;
 }
示例#55
0
 public MapperDefinition(ITypeMapper mapper, TypeMapperMetadata metadata)
 {
     Mapper = mapper;
     Metadata = metadata;
 }
示例#56
0
 public override Type GetReturnType(ITypeMapper typeMapper) => _type;
示例#57
0
        public NewDelegate(Type delegateType, Type targetType, string methodName, ITypeMapper typeMapper)
        {
			_delegateType = delegateType;
		    _typeMapper = typeMapper;
		    Initialize(targetType, methodName);
		}
示例#58
0
 public EventStore(ITypeMapper typeMapper, IEventSerializer eventSerializer, DbContextOptions <EventStore> options) : base(options)
 {
     _typeMapper      = typeMapper ?? throw new ArgumentNullException(nameof(typeMapper));
     _eventSerializer = eventSerializer ?? throw new ArgumentNullException(nameof(eventSerializer));
 }
示例#59
0
 public JsonMessageSerializer(ITypeMapper typeMapper)
 {
     this.typeMapper = typeMapper;
 }
 public override Type GetReturnType(ITypeMapper typeMapper)
 {
     return(_operand.GetReturnType(typeMapper));
 }