示例#1
0
 private static Type CreateType(IDictionary <ITypeDescription, Type> typeBuildMap,
                                ModuleBuilder modBuilder, ITypeDescription typeInfo)
 {
     return(typeInfo.TryResolveType(t => GetOrCreateType(typeBuildMap, modBuilder, t))
            .Convert(t => AddNativeType(typeInfo, t, typeBuildMap))
            .GetValue(() => AddNoNativeType(typeInfo, typeBuildMap, modBuilder)));
 }
示例#2
0
 public ITypeData CreateTypeData(ITypeDescription description)
 {
     return(new TypeData()
     {
         AssemblyName = description.AssemblyName, Name = description.Name, Namespace = description.Namespace
     });
 }
示例#3
0
 private static Type FindType(ITypeDescription typeInfo, Assembly candidateAssembly)
 {
     return(typeInfo.TryResolveType(n => FindType(n, candidateAssembly))
            .Convert(t => t)
            .GetValue(
                () => FindTypeOrArray(typeInfo, candidateAssembly)));
 }
示例#4
0
 internal static bool IsBusinessType(ITypeDescription description)
 {
     var name = description.TypeName.FullName;
     return !description.IsArray &&
            !name.StartsWith("System.")
            && !name.StartsWith("Db4objects.");
 }
示例#5
0
        internal static IEnumerable <ITypeDescription> CreateSingleFieldClass(ITypeDescription fieldType)
        {
            var type = SimpleClassDescription.Create(SingleFieldType(),
                                                     f => CreateField(fieldType));

            return(new[] { type, StringType });
        }
示例#6
0
        private static Type BuildMetaInfoType(ModuleBuilder moduleBuilder, ITypeDescription type)
        {
            var typeBuilder = moduleBuilder.DefineType(MetaDataNameSpace + "." + CodeGenerationUtils.ClassName(type.TypeName), CodeGenerationUtils.PublicClass());

            AddNameProperty(typeBuilder, type);
            return(typeBuilder.CreateType());
        }
示例#7
0
 public static IEnumerable<ITypeDescription> CreateClassListGenericOf(ITypeDescription typeOfLists)
 {
     var listType = KnownType.Create(typeof (List<>), new[]{typeOfLists});
     var type = SimpleClassDescription.Create(SingleFieldType(),
                                                      f => CreateField(listType));
     return new[] { type, listType, typeOfLists };
 }
示例#8
0
 private SimpleFieldDescription(string fieldName,
                                ITypeDescription type, IndexingState indexState)
 {
     this.Name      = fieldName;
     this.Type      = type;
     IsBackingField = IsNameBackingField(fieldName);
     IndexingState  = indexState;
 }
示例#9
0
        internal static bool IsBusinessType(ITypeDescription description)
        {
            var name = description.TypeName.FullName;

            return(!description.IsArray &&
                   !name.StartsWith("System.") &&
                   !name.StartsWith("Db4objects."));
        }
 private SimpleFieldDescription(string fieldName, 
     ITypeDescription type,IndexingState indexState)
 {
     this.Name = fieldName;
     this.Type = type;
     IsBackingField = IsNameBackingField(fieldName);
     IndexingState = indexState;
 }
示例#11
0
        public static IEnumerable <ITypeDescription> CreateClassListGenericOf(ITypeDescription typeOfLists)
        {
            var listType = KnownType.Create(typeof(List <>), new[] { typeOfLists });
            var type     = SimpleClassDescription.Create(SingleFieldType(),
                                                         f => CreateField(listType));

            return(new[] { type, listType, typeOfLists });
        }
        public DefaultFallbackCreator(ModuleBuilder moduleBuilder, ITypeDescription description)
        {
            _moduleBuilder = moduleBuilder;
            _description   = description;

            var compiler = new FallbackCompiler(moduleBuilder, description);

            _factoryMethod = compiler.Compile();
        }
示例#13
0
        public IGeneratedType GenerateType(ITypeDescription typeDescription)
        {
            if (typeDescription == null)
            {
                throw new ArgumentNullException("typeDescription");
            }

            return(this.GenerateTypes(new[] { typeDescription }).Where(x => x.Name == typeDescription.Name).Single());
        }
示例#14
0
        public TimeoutProxyCreator(ModuleBuilder moduleBuilder, ITypeDescription typeDescription)
        {
            _moduleBuilder   = moduleBuilder;
            _typeDescription = typeDescription;

            var compiler = new TimeoutProxyCompiler(moduleBuilder, typeDescription);

            _factoryMethod = compiler.Compile();
        }
示例#15
0
        private static void CreateQueryGetter(MethodBuilder getterMethod,
                                              Type type,
                                              ITypeDescription typeDescription)
        {
            var ilGenerator = getterMethod.GetILGenerator();

            ilGenerator.Emit(OpCodes.Call, StaticQueryCall(type));
            ilGenerator.Emit(OpCodes.Ret);
        }
示例#16
0
        private void CreateMetaDataGetter(MethodBuilder getterMethod,
                                          Type type,
                                          ITypeDescription typeDescription)
        {
            var returnType = getterMethod.ReturnType;

            CodeGenerationUtils.ReturnNewInstanceILInstructions(
                returnType.GetConstructors().Single(), getterMethod);
        }
            public FallbackCompiler(ModuleBuilder moduleBuilder, ITypeDescription interfaceDescription)
            {
                _interfaceType = typeof(T);
                var proxyTypeName = string.Format("SharpRemote.FaultTolerance.DefaultFallback.{0}", _interfaceType.FullName);

                _typeBuilder = moduleBuilder.DefineType(proxyTypeName, TypeAttributes.Sealed | TypeAttributes.Class);
                _typeBuilder.AddInterfaceImplementation(interfaceDescription.Type);

                _interfaceDescription = interfaceDescription;
            }
        private string NameOfProperty(ITypeDescription typeDescription)
        {
            var name = typeDescription.TypeName.NameWithGenerics.Split('.').Last().Replace('+', '_');

            if (needsAssemblyInName.Contains(typeDescription))
            {
                return(name + "_" + CodeGenerationUtils.NormalizedAssemblyName(typeDescription.TypeName));
            }
            return(name);
        }
 protected override void EmitReadEnum(ILGenerator gen, ITypeDescription typeDescription)
 {
     // TODO: Benchmark and optimize this shit code (there's really no need for any allocation)
     //       Using a switch statement or a dictionary lookup would be much more preferrable
     gen.Emit(OpCodes.Ldtoken, typeDescription.Type);
     gen.Emit(OpCodes.Call, Methods.TypeGetTypeFromHandle);
     gen.Emit(OpCodes.Ldarg_0);
     gen.Emit(OpCodes.Call, XmlSerializerReadString);
     gen.Emit(OpCodes.Call, EnumParse);
     gen.Emit(OpCodes.Unbox_Any, typeDescription.Type);
 }
示例#20
0
        private static ExplorerItem ToTypeExplorerItem(ITypeDescription typeDescription, bool includeAssemblyName)
        {
            var name = typeDescription.Name + (includeAssemblyName ? "_" + CodeGenerationUtils.NormalizedAssemblyName(typeDescription.TypeName) : "");

            return(new ExplorerItem(name,
                                    ExplorerItemKind.QueryableObject,
                                    ExplorerIcon.Table)
            {
                Children = Fields(Maybe.From(typeDescription))
            });
        }
        public AsyncStateMachineCompiler(TypeBuilder typeBuilder,
                                         ITypeDescription interfaceDescription,
                                         IMethodDescription methodDescription)
        {
            _originalMethod = methodDescription.Method;
            var taskType = methodDescription.ReturnType.Type;

            _taskGetAwaiter = taskType.GetMethod(nameof(Task.GetAwaiter));

            _awaiterType        = GetAwaiterType(taskType);
            _awaiterOnCompleted = _awaiterType.GetMethod(nameof(TaskAwaiter.OnCompleted),
                                                         new[] { typeof(Action) });

            var taskReturnType = GetTaskReturnType(taskType);

            _hasReturnValue = taskReturnType != typeof(void);
            if (_hasReturnValue)
            {
                _taskGetResult = taskType.GetProperty(nameof(Task <int> .Result)).GetMethod;
            }

            var interfaceType = interfaceDescription.Type;

            _taskCompletionSourceType         = GetTaskCompletionSourceType(taskType);
            _taskCompletionSourceSetResult    = _taskCompletionSourceType.GetMethod(nameof(TaskCompletionSource <int> .SetResult));
            _taskCompletionSourceSetException = _taskCompletionSourceType.GetMethod(nameof(TaskCompletionSource <int> .SetException),
                                                                                    new [] { typeof(Exception) });
            _taskCompletionSourceSetExceptions = _taskCompletionSourceType.GetMethod(nameof(TaskCompletionSource <int> .SetException),
                                                                                     new [] { typeof(IEnumerable <Exception>) });
            _taskCompletionSourceGetTask = _taskCompletionSourceType.GetProperty(nameof(TaskCompletionSource <int> .Task))
                                           .GetMethod;

            var name = string.Format("{0}_AsyncStateMachine", methodDescription.Name);

            _stateMachine = typeBuilder.DefineNestedType(name);

            _subject  = _stateMachine.DefineField("Subject", taskType, FieldAttributes.Public);
            _fallback = _stateMachine.DefineField("Fallback", interfaceType, FieldAttributes.Public);

            _subjectTask          = _stateMachine.DefineField("_subjectTask", taskType, FieldAttributes.Private);
            _fallbackTask         = _stateMachine.DefineField("_fallbackTask", taskType, FieldAttributes.Private);
            _taskCompletionSource = _stateMachine.DefineField("TaskCompletionSource", _taskCompletionSourceType,
                                                              FieldAttributes.Public | FieldAttributes.InitOnly);

            _parameters = new List <FieldInfo>(methodDescription.Parameters.Count);
            foreach (var parameter in methodDescription.Parameters)
            {
                var parameterName = string.Format("parameter_{0}", parameter.Name);
                var field         = _stateMachine.DefineField(parameterName,
                                                              parameter.ParameterType.Type,
                                                              FieldAttributes.Public);
                _parameters.Add(field);
            }
        }
 private TypeBuilder FindLocationForProperty(ByNameGrouping type,
                                             ITypeDescription forType)
 {
     if (type.HasMultipleValues)
     {
         var typeNameSeparation = forType.TypeName.NameAndNamespace.LastIndexOf('.');
         var namespaceName      = forType.TypeName.NameAndNamespace.Substring(0, typeNameSeparation);
         return(GetOrCreateNamespaceFor(namespaceName));
     }
     return(rootType);
 }
示例#23
0
 private bool Equals(ITypeDescription other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.TypeName, TypeName));
 }
 protected override void EmitWriteEnum(ILGenerator gen, ITypeDescription typeDescription, Action loadMember, Action loadMemberAddress)
 {
     // TODO: Benchmark and optimize this shit code (there's really no need for any allocation)
     //       Using a switch statement or a dictionary lookup would be much more preferrable
     gen.Emit(OpCodes.Ldarg_0);
     gen.Emit(OpCodes.Ldtoken, typeDescription.Type);
     gen.Emit(OpCodes.Call, Methods.TypeGetTypeFromHandle);
     loadMember();
     gen.Emit(OpCodes.Box, typeDescription.Type);
     gen.Emit(OpCodes.Call, EnumGetName);
     gen.Emit(OpCodes.Call, XmlSerializerWriteString);
 }
示例#25
0
 private static void AddNameProperty(TypeBuilder typeBuilder, ITypeDescription type)
 {
     AddLabelProperty(typeBuilder, "ClassName", type.Name);
     AddLabelProperty(typeBuilder, "ClassFullName", type.TypeName.FullName);
     foreach (var field in type.Fields)
     {
         AddLabelProperty(typeBuilder, field.AsPropertyName(), NameWithIndexState(field.Name, field.IndexingState));
         if (!field.IsBackingField)
         {
             AddLabelProperty(typeBuilder, field.Name, NameWithIndexState(field.Name, field.IndexingState));
         }
     }
 }
示例#26
0
        private static void ThrowIfIncompatible(ITypeDescription expectedDescription, TypeDescription actualDescription)
        {
            foreach (var expectedMethod in expectedDescription.Methods)
            {
                var actualMethod = actualDescription.Methods.FirstOrDefault(x => x.Name == expectedMethod.Name);
                if (actualMethod == null)
                {
                    throw new NotImplementedException($"The remote is missing interface method: {expectedDescription.Type.Name}.{expectedMethod.Name}");
                }

                ThrowIfIncompatible(expectedMethod, actualMethod);
            }
        }
示例#27
0
 private static void AddNameProperty(TypeBuilder typeBuilder, ITypeDescription type)
 {
     AddLabelProperty(typeBuilder, "ClassName", type.Name);
     AddLabelProperty(typeBuilder, "ClassFullName", type.TypeName.FullName);
     foreach (var field in type.Fields)
     {
         AddLabelProperty(typeBuilder, field.AsPropertyName(), NameWithIndexState(field.Name, field.IndexingState));
         if(!field.IsBackingField)
         {
             AddLabelProperty(typeBuilder, field.Name, NameWithIndexState(field.Name,field.IndexingState));
         }
     }
 }
示例#28
0
            public FallbackProxyCompiler(ModuleBuilder moduleBuilder, ITypeDescription interfaceDescription)
            {
                _interfaceType = typeof(T);
                var proxyTypeName = string.Format("SharpRemote.FaultTolerance.Fallback.{0}", _interfaceType.FullName);

                _typeBuilder = moduleBuilder.DefineType(proxyTypeName, TypeAttributes.Sealed | TypeAttributes.Class);
                _typeBuilder.AddInterfaceImplementation(interfaceDescription.Type);

                _interfaceDescription = interfaceDescription;
                _subject = _typeBuilder.DefineField("_subject", _interfaceType,
                                                    FieldAttributes.InitOnly | FieldAttributes.Private);
                _fallback = _typeBuilder.DefineField("_fallback", _interfaceType,
                                                     FieldAttributes.InitOnly | FieldAttributes.Private);
            }
示例#29
0
        private static void GetTypeConstraints(XmlNode xmlNode, ITypeDescription colDesc)
        {
            var constraintName = xmlNode.Name;
            var opName         = xmlNode.Attributes?["Operator"].InnerText;

            if (opName == "in")
            {
                var constraintValues = xmlNode.InnerText.Split(',').Select(v => Convert.ToInt32(v));
                colDesc.AddConstraint(constraintName, opName, constraintValues);
            }
            else
            {
                var constraintValue = Convert.ToInt32(xmlNode.InnerText);
                colDesc.AddConstraint(constraintName, opName, constraintValue);
            }
        }
示例#30
0
 private XmlMethodsCompiler(TypeBuilder typeBuilder,
                            ITypeDescription typeDescription,
                            CompilationContext context,
                            XmlWriteValueMethodCompiler writeValueMethodCompiler,
                            XmlWriteObjectMethodCompiler writeObjectMethodCompiler,
                            XmlReadValueMethodCompiler readValueMethodCompiler,
                            XmlReadObjectMethodCompiler readObjectMethodCompiler)
     : base(typeBuilder,
            typeDescription,
            writeValueMethodCompiler,
            writeObjectMethodCompiler,
            readValueMethodCompiler,
            readObjectMethodCompiler)
 {
     _context = context;
 }
示例#31
0
 public BinaryMethodsCompiler(TypeBuilder typeBuilder,
                              ITypeDescription typeDescription,
                              CompilationContext context,
                              BinaryWriteValueMethodCompiler writeValueMethodCompiler,
                              BinaryWriteObjectMethodCompiler writeObjectMethodCompiler,
                              BinaryReadValueMethodCompiler readValueMethodCompiler,
                              BinaryReadObjectMethodCompiler readObjectMethodCompiler)
     : base(typeBuilder,
            typeDescription,
            writeValueMethodCompiler,
            writeObjectMethodCompiler,
            readValueMethodCompiler,
            readObjectMethodCompiler)
 {
     _context = context;
 }
示例#32
0
 private static Type BuildEnum(ITypeDescription typeInfo, IDictionary<ITypeDescription, Type> typeBuildMap, ModuleBuilder modBuilder)
 {
     var enumBuilder  = modBuilder.DefineEnum(BuildName(typeInfo.TypeName), TypeAttributes.Class | TypeAttributes.Public,
                           typeof(int));
     typeBuildMap[typeInfo] = enumBuilder;
     for (int i = -EnumRange; i < EnumRange; i++)
     {
         if(i<0)
         {
             enumBuilder.DefineLiteral("Value_Negative" + Math.Abs(i),i);
         }  else
         {
             enumBuilder.DefineLiteral("Value_" + Math.Abs(i), i);
         }
     }
     return enumBuilder.CreateType();
 }
示例#33
0
        private static void GetTypeAttributes(XmlNode xmlNode, ITypeDescription colDesc)
        {
            var sourceType = xmlNode.Attributes?["Source"]?.InnerText;

            if (string.IsNullOrWhiteSpace(sourceType))
            {
                throw new XmlException("Error with attribute 'Name' for 'Type'");
            }
            var destinationType = xmlNode.Attributes?["Destination"]?.InnerText;

            if (string.IsNullOrWhiteSpace(destinationType))
            {
                throw new XmlException("Error with attribute 'To' for 'Type'");
            }

            colDesc.TypeName  = sourceType;
            colDesc.ConvertTo = destinationType;
        }
示例#34
0
        protected override void EmitWriteEnum(ILGenerator gen, ITypeDescription typeDescription, Action loadMember, Action loadMemberAddress)
        {
            gen.Emit(OpCodes.Ldarg_0);
            loadMember();

            var storageType = typeDescription.StorageType.Type;

            if (storageType == typeof(byte))
            {
                gen.Emit(OpCodes.Call, BinarySerializer2WriteByte);
            }
            else if (storageType == typeof(sbyte))
            {
                gen.Emit(OpCodes.Call, BinarySerializer2WriteSByte);
            }
            else if (storageType == typeof(short))
            {
                gen.Emit(OpCodes.Call, BinarySerializer2WriteInt16);
            }
            else if (storageType == typeof(ushort))
            {
                gen.Emit(OpCodes.Call, BinarySerializer2WriteUInt16);
            }
            else if (storageType == typeof(int))
            {
                gen.Emit(OpCodes.Call, BinarySerializer2WriteInt32);
            }
            else if (storageType == typeof(uint))
            {
                gen.Emit(OpCodes.Call, BinarySerializer2WriteUInt32);
            }
            else if (storageType == typeof(long))
            {
                gen.Emit(OpCodes.Call, BinarySerializer2WriteInt64);
            }
            else if (storageType == typeof(ulong))
            {
                gen.Emit(OpCodes.Call, BinarySerializer2WriteUInt64);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
示例#35
0
        public static XmlMethodsCompiler Create(TypeBuilder typeBuilder, ITypeDescription typeDescription)
        {
            var context = new CompilationContext
            {
                TypeDescription = typeDescription,
                SerializerType  = typeof(XmlSerializer),
                ReaderType      = typeof(XmlReader),
                WriterType      = typeof(XmlWriter),
                TypeBuilder     = typeBuilder
            };

            return(new XmlMethodsCompiler(typeBuilder,
                                          typeDescription,
                                          context,
                                          new XmlWriteValueMethodCompiler(context),
                                          new XmlWriteObjectMethodCompiler(context),
                                          new XmlReadValueMethodCompiler(context),
                                          new XmlReadObjectMethodCompiler(context)));
        }
示例#36
0
        private static Type AddNoNativeType(ITypeDescription typeInfo,
            IDictionary<ITypeDescription, Type> typeBuildMap,
            ModuleBuilder modBuilder)
        {
            var baseType = typeInfo.BaseClass.Convert(bc=>GetOrCreateType(typeBuildMap, modBuilder,bc ));
            if(baseType==typeof(Enum))
            {
                return BuildEnum(typeInfo,typeBuildMap, modBuilder);
            } else
            {
                var defineType = CreateType(modBuilder,
                    typeInfo.TypeName, baseType);
                typeBuildMap[typeInfo] = defineType;

                foreach (var field in typeInfo.Fields)
                {
                    CreateFields(defineType, field, modBuilder, typeBuildMap);
                }
                return defineType;
            }
        }
        private static IGeneratedType GenerateType(ModuleBuilder moduleBuilder, ITypeDescription typeDescription, ITypeMapper typeMapper)
        {
            var typeBuilder = moduleBuilder.DefineType(typeDescription.Name, TypeAttributes.Public | TypeAttributes.Class);

            typeBuilder.DefineDefaultConstructor(MethodAttributes.Public);

            var types = typeDescription.PropertyDescriptions.Select(x => x.Type).ToArray();
            var constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, types);

            var index = 1;
            foreach (var property in typeDescription.PropertyDescriptions)
            {
                constructorBuilder.DefineParameter(index, ParameterAttributes.None, property.Name.LowercaseFirst());
                index++;
            }

            var ctorIl = constructorBuilder.GetILGenerator();
            ctorIl.Emit(OpCodes.Ldarg_0);
            ctorIl.Emit(OpCodes.Call, typeBuilder.BaseType.GetConstructor(Type.EmptyTypes));

            index = 1;
            foreach (var property in typeDescription.PropertyDescriptions)
            {
                var targetPropertyType = typeMapper.GetType(property.Type);
                EmitForPropertyDescription(typeBuilder, property, ctorIl, index, targetPropertyType);
                index++;
            }

            ctorIl.Emit(OpCodes.Ret);

            var type = typeBuilder.CreateType();
            return new GeneratedType(typeDescription.Name, type, typeDescription);
        }
示例#38
0
 private static Type CreateType(IDictionary<ITypeDescription, Type> typeBuildMap,
     ModuleBuilder modBuilder, ITypeDescription typeInfo)
 {
     return typeInfo.TryResolveType(t=>GetOrCreateType(typeBuildMap, modBuilder, t))
         .Convert(t => AddNativeType(typeInfo, t, typeBuildMap))
         .GetValue(() => AddNoNativeType(typeInfo, typeBuildMap, modBuilder));
 }
示例#39
0
 private static Type FindType(ITypeDescription typeInfo, Assembly candidateAssembly)
 {
     return typeInfo.TryResolveType(n => FindType(n, candidateAssembly))
         .Convert(t => t)
         .GetValue(
         () => FindTypeOrArray(typeInfo, candidateAssembly));
 }
示例#40
0
 private static Type FindTypeOrArray(ITypeDescription typeInfo, Assembly candidateAssembly)
 {
     return typeInfo.TryResolveType(t =>FindType(t,candidateAssembly))
         .GetValue(() => candidateAssembly.GetType(BuildName(typeInfo.TypeName)));
 }
 public GeneratedType(string name, Type type, ITypeDescription typeDescription)
 {
     this.Name = name;
     this.Type = type;
     this.TypeDescription = typeDescription;
 }
示例#42
0
 internal static IEnumerable<SimpleFieldDescription> CreateField(string fieldName,
     ITypeDescription type)
 {
     return new[] { SimpleFieldDescription.Create(fieldName, type) };
 }
示例#43
0
 internal static IEnumerable<SimpleFieldDescription> CreateField(ITypeDescription type)
 {
     return CreateField(FieldName, type);
 }
示例#44
0
 private void CreateMetaDataGetter(MethodBuilder getterMethod,
     Type type,
     ITypeDescription typeDescription)
 {
     var returnType = getterMethod.ReturnType;
     CodeGenerationUtils.ReturnNewInstanceILInstructions(
         returnType.GetConstructors().Single(), getterMethod);
 }
示例#45
0
 private static Type AddNativeType(ITypeDescription typeInfo, Type type,
     IDictionary<ITypeDescription, Type> typeBuildMap)
 {
     typeBuildMap[typeInfo] = type;
     return type;
 }
示例#46
0
 private ArrayDescription(TypeName typeName, ITypeDescription innerType)
     : base(typeName, Maybe.From(KnownType.Array))
 {
     this.innerType = innerType;
 }
示例#47
0
 public static ITypeDescription Create(ITypeDescription innerType, int orderOfArray)
 {
     var name = TypeName.CreateArrayOf(innerType.TypeName, orderOfArray);
     return new ArrayDescription(name, innerType);
 }
示例#48
0
 internal static IEnumerable<SimpleFieldDescription> CreateArrayField(ITypeDescription type)
 {
     var arrayType = ArrayDescription.Create(type, 1);
     return new[] { SimpleFieldDescription.Create(FieldName, arrayType) };
 }
示例#49
0
        public IGeneratedType GenerateType(ITypeDescription typeDescription)
        {
            if (typeDescription == null)
            {
                throw new ArgumentNullException("typeDescription");
            }

            return this.GenerateTypes(new[] {typeDescription}).Where(x => x.Name == typeDescription.Name).Single();
        }
示例#50
0
 private static Type GetOrCreateType(IDictionary<ITypeDescription, Type> typeBuildMap,
     ModuleBuilder modBuilder, ITypeDescription typeInfo)
 {
     return typeBuildMap.TryGet(typeInfo)
         .GetValue(() => CreateType(typeBuildMap, modBuilder, typeInfo));
 }
示例#51
0
 internal static IEnumerable<ITypeDescription> CreateSingleFieldClass(ITypeDescription fieldType)
 {
     var type = SimpleClassDescription.Create(SingleFieldType(),
                                                      f => CreateField(fieldType));
     return new[] { type, StringType };
 }
示例#52
0
 private static Type BuildMetaInfoType(ModuleBuilder moduleBuilder, ITypeDescription type)
 {
     var typeBuilder = moduleBuilder.DefineType(MetaDataNameSpace + "." + CodeGenerationUtils.ClassName(type.TypeName), CodeGenerationUtils.PublicClass());
     AddNameProperty(typeBuilder, type);
     return typeBuilder.CreateType();
 }
示例#53
0
 private bool Equals(ITypeDescription other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.TypeName, TypeName);
 }
示例#54
0
 private static void CreateQueryGetter(MethodBuilder getterMethod,
     Type type,
     ITypeDescription typeDescription)
 {
     var ilGenerator = getterMethod.GetILGenerator();
     ilGenerator.Emit(OpCodes.Call, StaticQueryCall(type));
     ilGenerator.Emit(OpCodes.Ret);
 }
 private TypeBuilder FindLocationForProperty(ByNameGrouping type,
     ITypeDescription forType)
 {
     if (type.HasMultipleValues)
     {
         var typeNameSeparation = forType.TypeName.NameAndNamespace.LastIndexOf('.');
         var namespaceName = forType.TypeName.NameAndNamespace.Substring(0, typeNameSeparation);
         return GetOrCreateNamespaceFor(namespaceName);
     }
     return rootType;
 }
 public static SimpleFieldDescription Create(string fieldName,
     ITypeDescription type, IndexingState indexState = IndexingState.Unknown)
 {
     return new SimpleFieldDescription(fieldName, type, indexState);
 }
 public void RegisterNewType(ITypeDescription source, IGeneratedType generatedType)
 {
     typeDescritpions[source] = generatedType;
 }
 private string NameOfProperty(ITypeDescription typeDescription)
 {
     var name = typeDescription.TypeName.NameWithGenerics.Split('.').Last().Replace('+', '_');
     if(needsAssemblyInName.Contains(typeDescription))
     {
         return name + "_" + CodeGenerationUtils.NormalizedAssemblyName(typeDescription.TypeName);
     }
     return name;
 }