Пример #1
0
        private static void AddLabelProperty(TypeBuilder typeBuilder, string propertyName,
                                             string valueToReturn)
        {
            var property      = CodeGenerationUtils.DefineProperty(typeBuilder, propertyName, typeof(string));
            var methodBuilder = CodeGenerationUtils.GetterMethodFor(typeBuilder, property, CodeGenerationUtils.PublicGetter());

            var ilCode = methodBuilder.GetILGenerator();

            ilCode.Emit(OpCodes.Ldstr, valueToReturn);
            ilCode.Emit(OpCodes.Ret);
        }
Пример #2
0
 private void CreateEntries(ByNameGrouping type)
 {
     foreach (var typeToBuildFor in type.Members)
     {
         var definePropertyOn = FindLocationForProperty(type, typeToBuildFor.Key);
         var querableType     = propertyTypeBuilder(typeToBuildFor.Value, typeToBuildFor.Key);
         var nameOfProperty   = NameOfProperty(typeToBuildFor.Key);
         var property         = CodeGenerationUtils.DefineProperty(definePropertyOn, nameOfProperty, querableType);
         var getterMethod     = CodeGenerationUtils.GetterMethodFor(definePropertyOn, property, QueryPropertyAccessRights(definePropertyOn));
         buildPropertyOnType(getterMethod, typeToBuildFor.Value,
                             typeToBuildFor.Key);
     }
 }
Пример #3
0
        private void CreateMetaDataStructure(IEnumerable <ByNameGrouping> typesGroupesByName)
        {
            var metaInfoType = CreateMetaInfoProperty(typesGroupesByName);
            var constructorOfMetaInfoType = metaInfoType.GetConstructors().Single();

            var property = CodeGenerationUtils.DefineProperty(rootType, MetaDataProperty, metaInfoType);

            var getterMethod = CodeGenerationUtils.GetterMethodFor(rootType, property, CodeGenerationUtils.StaticPublicGetter());
            var lambda       = Expression.Lambda(typeof(Func <>).MakeGenericType(metaInfoType),
                                                 Expression.New(constructorOfMetaInfoType), new ParameterExpression[0]);

            lambda.CompileToMethod(getterMethod);
        }
Пример #4
0
        private TypeBuilder BuildNamespaceContext(string lastNameSpace,
                                                  string forNamespace, string ns)
        {
            var parentNS = nameSpaceHolder.TryGet(lastNameSpace).GetValue(rootType);

            var currentType = BuildNSContextType(forNamespace);

            var property = CodeGenerationUtils.DefineProperty(parentNS, ns, currentType.Item1);

            property.SetGetMethod(CreateNewInstanceGetter(parentNS, property, currentType.Item2, QueryPropertyAccessRights(parentNS)));

            nameSpaceHolder[forNamespace] = currentType.Item1;
            return(currentType.Item1);
        }