当前位置: 首页>>代码示例>>C#>>正文


C# CodeGenerator.GetArg方法代码示例

本文整理汇总了C#中CodeGenerator.GetArg方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.GetArg方法的具体用法?C# CodeGenerator.GetArg怎么用?C# CodeGenerator.GetArg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CodeGenerator的用法示例。


在下文中一共展示了CodeGenerator.GetArg方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateTypedSerializer

        internal string GenerateTypedSerializer(string readMethod, string writeMethod, XmlMapping mapping, CodeIdentifiers classes, string baseSerializer, string readerClass, string writerClass)
        {
            string serializerName = CodeIdentifier.MakeValid(Accessor.UnescapeName(mapping.Accessor.Mapping.TypeDesc.Name));
            serializerName = classes.AddUnique(serializerName + "Serializer", mapping);

            TypeBuilder typedSerializerTypeBuilder = CodeGenerator.CreateTypeBuilder(
                _moduleBuilder,
                CodeIdentifier.GetCSharpName(serializerName),
                TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit,
                CreatedTypes[baseSerializer],
                Array.Empty<Type>()
                );

            ilg = new CodeGenerator(typedSerializerTypeBuilder);
            ilg.BeginMethod(
                typeof(Boolean),
                "CanDeserialize",
                new Type[] { typeof(XmlReader) },
                new string[] { "xmlReader" },
                CodeGenerator.PublicOverrideMethodAttributes
            );

            if (mapping.Accessor.Any)
            {
                ilg.Ldc(true);
                ilg.Stloc(ilg.ReturnLocal);
                ilg.Br(ilg.ReturnLabel);
            }
            else
            {
                MethodInfo XmlReader_IsStartElement = typeof(XmlReader).GetMethod(
                     "IsStartElement",
                     CodeGenerator.InstanceBindingFlags,
                     new Type[] { typeof(String), typeof(String) }
                     );
                ilg.Ldarg(ilg.GetArg("xmlReader"));
                ilg.Ldstr(GetCSharpString(mapping.Accessor.Name));
                ilg.Ldstr(GetCSharpString(mapping.Accessor.Namespace));
                ilg.Call(XmlReader_IsStartElement);
                ilg.Stloc(ilg.ReturnLocal);
                ilg.Br(ilg.ReturnLabel);
            }
            ilg.MarkLabel(ilg.ReturnLabel);
            ilg.Ldloc(ilg.ReturnLocal);
            ilg.EndMethod();

            if (writeMethod != null)
            {
                ilg = new CodeGenerator(typedSerializerTypeBuilder);
                ilg.BeginMethod(
                    typeof(void),
                    "Serialize",
                    new Type[] { typeof(object), typeof(XmlSerializationWriter) },
                    new string[] { "objectToSerialize", "writer" },
                    CodeGenerator.ProtectedOverrideMethodAttributes);
                MethodInfo writerType_writeMethod = CreatedTypes[writerClass].GetMethod(
                    writeMethod,
                    CodeGenerator.InstanceBindingFlags,
                    new Type[] { (mapping is XmlMembersMapping) ? typeof(object[]) : typeof(object) }
                    );
                ilg.Ldarg("writer");
                ilg.Castclass(CreatedTypes[writerClass]);
                ilg.Ldarg("objectToSerialize");
                if (mapping is XmlMembersMapping)
                {
                    ilg.ConvertValue(typeof(object), typeof(object[]));
                }
                ilg.Call(writerType_writeMethod);
                ilg.EndMethod();
            }
            if (readMethod != null)
            {
                ilg = new CodeGenerator(typedSerializerTypeBuilder);
                ilg.BeginMethod(
                    typeof(object),
                    "Deserialize",
                    new Type[] { typeof(XmlSerializationReader) },
                    new string[] { "reader" },
                    CodeGenerator.ProtectedOverrideMethodAttributes);
                MethodInfo readerType_readMethod = CreatedTypes[readerClass].GetMethod(
                    readMethod,
                    CodeGenerator.InstanceBindingFlags,
                    Array.Empty<Type>()
                    );
                ilg.Ldarg("reader");
                ilg.Castclass(CreatedTypes[readerClass]);
                ilg.Call(readerType_readMethod);
                ilg.EndMethod();
            }
            typedSerializerTypeBuilder.DefineDefaultConstructor(CodeGenerator.PublicMethodAttributes);
            Type typedSerializerType = typedSerializerTypeBuilder.CreateTypeInfo().AsType();
            CreatedTypes.Add(typedSerializerType.Name, typedSerializerType);

            return typedSerializerType.Name;
        }
开发者ID:omariom,项目名称:corefx,代码行数:95,代码来源:XmlSerializationILGen.cs

示例2: GenerateCollectionReaderHelper

 CodeGenerator GenerateCollectionReaderHelper(CollectionDataContract collectionContract, bool isGetOnlyCollection)
 {
     ilg = new CodeGenerator();
     bool memberAccessFlag = collectionContract.RequiresMemberAccessForRead(null);
     try
     {
         if (isGetOnlyCollection)
         {
             ilg.BeginMethod("Read" + collectionContract.StableName.Name + "FromXml" + "IsGetOnly", Globals.TypeOfXmlFormatGetOnlyCollectionReaderDelegate, memberAccessFlag);
         }
         else
         {
             ilg.BeginMethod("Read" + collectionContract.StableName.Name + "FromXml" + string.Empty, Globals.TypeOfXmlFormatCollectionReaderDelegate, memberAccessFlag);
         }
     }
     catch (SecurityException securityException)
     {
         if (memberAccessFlag && securityException.PermissionType.Equals(typeof(ReflectionPermission)))
         {
             collectionContract.RequiresMemberAccessForRead(securityException);
         }
         else
         {
             throw;
         }
     }
     InitArgs();
     DemandMemberAccessPermission(memberAccessFlag);
     collectionContractArg = ilg.GetArg(4);
     return ilg;
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:31,代码来源:XmlFormatReaderGenerator.cs

示例3: GenerateInvokeEndDelegate

            internal InvokeEndDelegate GenerateInvokeEndDelegate(MethodInfo method, out int outputParameterCount)
            {
                bool requiresMemberAccess = MethodRequiresMemberAccess(method);

                this.ilg = new CodeGenerator();
                try
                {
                    this.ilg.BeginMethod("AsyncInvokeEnd" + method.Name, typeof(InvokeEndDelegate), requiresMemberAccess);
                }
                catch (SecurityException securityException)
                {
                    if (requiresMemberAccess && securityException.PermissionType.Equals(typeof(ReflectionPermission)))
                    {
                        DiagnosticUtility.TraceHandledException(securityException, TraceEventType.Warning);
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                            new SecurityException(SR.GetString(
                                    SR.PartialTrustServiceMethodNotVisible,
                                    method.DeclaringType.FullName,
                                    method.Name)));
                    }
                    else
                    {
                        throw;
                    }
                }

                ArgBuilder targetArg = ilg.GetArg(0);
                ArgBuilder outputParametersArg = ilg.GetArg(1);
                ArgBuilder resultArg = ilg.GetArg(2);

                ParameterInfo[] parameters = method.GetParameters();
                LocalBuilder returnLocal = ilg.DeclareLocal(ilg.CurrentMethod.ReturnType, "returnParam");
                LocalBuilder[] parameterLocals = new LocalBuilder[parameters.Length - 1];
                DeclareParameterLocals(parameters, parameterLocals);

                LoadZeroValueInputParametersIntoLocals(parameters, parameterLocals);
                LoadTarget(targetArg, method.ReflectedType);
                LoadParameters(parameters, parameterLocals);
                ilg.Load(resultArg);
                InvokeMethod(method, returnLocal);
                LoadOutputParametersIntoArray(parameters, parameterLocals, outputParametersArg, out outputParameterCount);

                ilg.Load(returnLocal);
                return (InvokeEndDelegate)this.ilg.EndMethod();
            }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:45,代码来源:InvokerUtil.cs

示例4: WriteStructMethod

        private void WriteStructMethod(StructMapping mapping)
        {
            string methodName = (string)MethodNames[mapping];

            ilg = new CodeGenerator(this.typeBuilder);
            List<Type> argTypes = new List<Type>(5);
            List<string> argNames = new List<string>(5);
            argTypes.Add(typeof(string));
            argNames.Add("n");
            argTypes.Add(typeof(string));
            argNames.Add("ns");
            argTypes.Add(mapping.TypeDesc.Type);
            argNames.Add("o");
            if (mapping.TypeDesc.IsNullable)
            {
                argTypes.Add(typeof(Boolean));
                argNames.Add("isNullable");
            }
            argTypes.Add(typeof(Boolean));
            argNames.Add("needType");
            ilg.BeginMethod(typeof(void),
                GetMethodBuilder(methodName),
                argTypes.ToArray(),
                argNames.ToArray(),
                CodeGenerator.PrivateMethodAttributes);
            if (mapping.TypeDesc.IsNullable)
            {
                ilg.If(ilg.GetArg("o"), Cmp.EqualTo, null);
                {
                    ilg.If(ilg.GetArg("isNullable"), Cmp.EqualTo, true);
                    {
                        MethodInfo XmlSerializationWriter_WriteNullTagLiteral = typeof(XmlSerializationWriter).GetMethod(
                                "WriteNullTagLiteral",
                                CodeGenerator.InstanceBindingFlags,
                                new Type[] { typeof(String), typeof(String) }
                                );
                        ilg.Ldarg(0);
                        ilg.Ldarg("n");
                        ilg.Ldarg("ns");
                        ilg.Call(XmlSerializationWriter_WriteNullTagLiteral);
                    }
                    ilg.EndIf();
                    ilg.GotoMethodEnd();
                }
                ilg.EndIf();
            }
            ilg.If(ilg.GetArg("needType"), Cmp.NotEqualTo, true); // if (!needType)

            LocalBuilder tLoc = ilg.DeclareLocal(typeof(Type), "t");
            MethodInfo Object_GetType = typeof(object).GetMethod(
                    "GetType",
                    CodeGenerator.InstanceBindingFlags,
                    Array.Empty<Type>()
                    );
            ArgBuilder oArg = ilg.GetArg("o");
            ilg.LdargAddress(oArg);
            ilg.ConvertAddress(oArg.ArgType, typeof(object));
            ilg.Call(Object_GetType);
            ilg.Stloc(tLoc);
            WriteTypeCompare("t", mapping.TypeDesc.Type);
            // Bool on the stack from WriteTypeCompare.
            ilg.If(); // if (t == typeof(...))
            WriteDerivedTypes(mapping);
            if (mapping.TypeDesc.IsRoot)
                WriteEnumAndArrayTypes();
            ilg.Else();
            if (mapping.TypeDesc.IsRoot)
            {
                MethodInfo XmlSerializationWriter_WriteTypedPrimitive = typeof(XmlSerializationWriter).GetMethod(
                        "WriteTypedPrimitive",
                        CodeGenerator.InstanceBindingFlags,
                        new Type[] { typeof(String), typeof(String), typeof(Object), typeof(Boolean) }
                        );
                ilg.Ldarg(0);
                ilg.Ldarg("n");
                ilg.Ldarg("ns");
                ilg.Ldarg("o");
                ilg.Ldc(true);
                ilg.Call(XmlSerializationWriter_WriteTypedPrimitive);
                ilg.GotoMethodEnd();
            }
            else
            {
                MethodInfo XmlSerializationWriter_CreateUnknownTypeException = typeof(XmlSerializationWriter).GetMethod(
                    "CreateUnknownTypeException",
                    CodeGenerator.InstanceBindingFlags,
                    new Type[] { typeof(Object) }
                    );
                ilg.Ldarg(0);
                ilg.Ldarg(oArg);
                ilg.ConvertValue(oArg.ArgType, typeof(Object));
                ilg.Call(XmlSerializationWriter_CreateUnknownTypeException);
                ilg.Throw();
            }
            ilg.EndIf(); // if (t == typeof(...))
            ilg.EndIf(); // if (!needType)

            if (!mapping.TypeDesc.IsAbstract)
            {
                if (mapping.TypeDesc.Type != null && typeof(XmlSchemaObject).IsAssignableFrom(mapping.TypeDesc.Type))
//.........这里部分代码省略.........
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:101,代码来源:XmlSerializationWriterILGen.cs

示例5: GenerateTypeElement

        private string GenerateTypeElement(XmlTypeMapping xmlTypeMapping)
        {
            ElementAccessor element = xmlTypeMapping.Accessor;
            TypeMapping mapping = element.Mapping;
            string methodName = NextMethodName(element.Name);
            ilg = new CodeGenerator(this.typeBuilder);
            ilg.BeginMethod(
                typeof(void),
                methodName,
                new Type[] { typeof(object) },
                new string[] { "o" },
                CodeGenerator.PublicMethodAttributes
                );

            MethodInfo XmlSerializationWriter_WriteStartDocument = typeof(XmlSerializationWriter).GetMethod(
                "WriteStartDocument",
                CodeGenerator.InstanceBindingFlags,
                Array.Empty<Type>()
                );
            ilg.Ldarg(0);
            ilg.Call(XmlSerializationWriter_WriteStartDocument);

            ilg.If(ilg.GetArg("o"), Cmp.EqualTo, null);
            if (element.IsNullable)
            {
                WriteLiteralNullTag(element.Name, (element.Form == XmlSchemaForm.Qualified ? element.Namespace : ""));
            }
            else
                WriteEmptyTag(element.Name, (element.Form == XmlSchemaForm.Qualified ? element.Namespace : ""));
            ilg.GotoMethodEnd();
            ilg.EndIf();

            if (!mapping.TypeDesc.IsValueType && !mapping.TypeDesc.Type.GetTypeInfo().IsPrimitive)
            {
                MethodInfo XmlSerializationWriter_TopLevelElement = typeof(XmlSerializationWriter).GetMethod(
                      "TopLevelElement",
                      CodeGenerator.InstanceBindingFlags,
                      Array.Empty<Type>()
                      );
                ilg.Ldarg(0);
                ilg.Call(XmlSerializationWriter_TopLevelElement);
            }

            WriteMember(new SourceInfo("o", "o", null, typeof(object), ilg), null, new ElementAccessor[] { element }, null, null, mapping.TypeDesc, true);

            ilg.EndMethod();
            return methodName;
        }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:48,代码来源:XmlSerializationWriterILGen.cs

示例6: ILGenForEnumLongValue

 internal void ILGenForEnumLongValue(CodeGenerator ilg, string variable)
 {
     ArgBuilder argV = ilg.GetArg(variable);
     ilg.Ldarg(argV);
     ilg.ConvertValue(argV.ArgType, typeof(long));
 }
开发者ID:shiftkey-tester,项目名称:corefx,代码行数:6,代码来源:XmlSerializationWriterILGen.cs

示例7: GenerateCollectionReaderHelper

 private CodeGenerator GenerateCollectionReaderHelper(CollectionDataContract collectionContract, bool isGetOnlyCollection)
 {
     _ilg = new CodeGenerator();
     bool memberAccessFlag = collectionContract.RequiresMemberAccessForRead(null, Globals.DataContractSerializationPatterns);
     try
     {
         if (isGetOnlyCollection)
         {
             _ilg.BeginMethod("Read" + collectionContract.StableName.Name + "FromXml" + "IsGetOnly", Globals.TypeOfXmlFormatGetOnlyCollectionReaderDelegate, memberAccessFlag);
         }
         else
         {
             _ilg.BeginMethod("Read" + collectionContract.StableName.Name + "FromXml" + string.Empty, Globals.TypeOfXmlFormatCollectionReaderDelegate, memberAccessFlag);
         }
     }
     catch (SecurityException securityException)
     {
         if (memberAccessFlag)
         {
             collectionContract.RequiresMemberAccessForRead(securityException, Globals.DataContractSerializationPatterns);
         }
         else
         {
             throw;
         }
     }
     InitArgs();
     _collectionContractArg = _ilg.GetArg(4);
     return _ilg;
 }
开发者ID:jsalvadorp,项目名称:corefx,代码行数:30,代码来源:XmlFormatReaderGenerator.cs


注:本文中的CodeGenerator.GetArg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。