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


C# Compiler.EmitCtor方法代码示例

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


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

示例1: EmitRead

 protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
 {
     Tail.EmitRead(ctx, valueFrom);
     ctx.CopyValue();
     Compiler.CodeLabel @nonEmpty = ctx.DefineLabel(), @end = ctx.DefineLabel();
     ctx.LoadValue(typeof(string).GetProperty("Length"));
     ctx.BranchIfTrue(@nonEmpty, true);
     ctx.DiscardValue();
     ctx.LoadNullRef();
     ctx.Branch(@end, true);
     ctx.MarkLabel(@nonEmpty);
     ctx.EmitCtor(typeof(Uri), typeof(string));
     ctx.MarkLabel(@end);
     
 }
开发者ID:Rasarack,项目名称:SteamBot,代码行数:15,代码来源:UriDecorator.cs

示例2: EmitRead

        public void EmitRead(Compiler.CompilerContext ctx, Compiler.Local incoming)
        {
            using (Compiler.Local objValue = ctx.GetLocalWithValue(ExpectedType, incoming))
            {
                Compiler.Local[] locals = new Compiler.Local[members.Length];
                try
                {
                    for (int i = 0; i < locals.Length; i++)
                    {
                        Type type = GetMemberType(i);
                        bool store = true;
                        locals[i] = new Compiler.Local(ctx, type);
                        if (!Helpers.IsValueType(ExpectedType))
                        {
                            // value-types always read the old value
                            if (Helpers.IsValueType(type))
                            {
                                switch (Helpers.GetTypeCode(type))
                                {
                                    case ProtoTypeCode.Boolean:
                                    case ProtoTypeCode.Byte:
                                    case ProtoTypeCode.Int16:
                                    case ProtoTypeCode.Int32:
                                    case ProtoTypeCode.SByte:
                                    case ProtoTypeCode.UInt16:
                                    case ProtoTypeCode.UInt32:
                                        ctx.LoadValue(0);
                                        break;
                                    case ProtoTypeCode.Int64:
                                    case ProtoTypeCode.UInt64:
                                        ctx.LoadValue(0L);
                                        break;
                                    case ProtoTypeCode.Single:
                                        ctx.LoadValue(0.0F);
                                        break;
                                    case ProtoTypeCode.Double:
                                        ctx.LoadValue(0.0D);
                                        break;
                                    case ProtoTypeCode.Decimal:
                                        ctx.LoadValue(0M);
                                        break;
                                    case ProtoTypeCode.Guid:
                                        ctx.LoadValue(Guid.Empty);
                                        break;
                                    default:
                                        ctx.LoadAddress(locals[i], type);
                                        ctx.EmitCtor(type);
                                        store = false;
                                        break;
                                }
                            }
                            else
                            {
                                ctx.LoadNullRef();
                            }
                            if (store)
                            {
                                ctx.StoreValue(locals[i]);
                            }
                        }
                    }

                    Compiler.CodeLabel skipOld = Helpers.IsValueType(ExpectedType)
                                                        ? new Compiler.CodeLabel()
                                                        : ctx.DefineLabel();
                    if (!Helpers.IsValueType(ExpectedType))
                    {
                        ctx.LoadAddress(objValue, ExpectedType);
                        ctx.BranchIfFalse(skipOld, false);
                    }
                    for (int i = 0; i < members.Length; i++)
                    {
                        ctx.LoadAddress(objValue, ExpectedType);
                        if (members[i] is FieldInfo)
                        {
                            ctx.LoadValue((FieldInfo)members[i]);
                        }
                        else if (members[i] is PropertyInfo)
                        {
                            ctx.LoadValue((PropertyInfo)members[i]);
                        }
                        ctx.StoreValue(locals[i]);
                    }

                    if (!Helpers.IsValueType(ExpectedType)) ctx.MarkLabel(skipOld);

                    using (Compiler.Local fieldNumber = new Compiler.Local(ctx, ctx.MapType(typeof(int))))
                    {
                        Compiler.CodeLabel @continue = ctx.DefineLabel(),
                                           processField = ctx.DefineLabel(),
                                           notRecognised = ctx.DefineLabel();
                        ctx.Branch(@continue, false);

                        Compiler.CodeLabel[] handlers = new Compiler.CodeLabel[members.Length];
                        for (int i = 0; i < members.Length; i++)
                        {
                            handlers[i] = ctx.DefineLabel();
                        }

                        ctx.MarkLabel(processField);
//.........这里部分代码省略.........
开发者ID:GeorchW,项目名称:protobuf-net,代码行数:101,代码来源:TupleSerializer.cs

示例3: EmitRead

        protected override void EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
        {
            using (Compiler.Local oldValue = ctx.GetLocalWithValue(expectedType, valueFrom))
            using (Compiler.Local token = new Compiler.Local(ctx, ctx.MapType(typeof(SubItemToken))))
            using (Compiler.Local field = new Compiler.Local(ctx, ctx.MapType(typeof(int))))
            {
                ctx.LoadReaderWriter();
                ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("StartSubItem"));
                ctx.StoreValue(token);

                Compiler.CodeLabel next = ctx.DefineLabel(), processField = ctx.DefineLabel(), end = ctx.DefineLabel();

                ctx.MarkLabel(next);

                ctx.EmitBasicRead("ReadFieldHeader", ctx.MapType(typeof(int)));
                ctx.CopyValue();
                ctx.StoreValue(field);
                ctx.LoadValue(Tag); // = 1 - process
                ctx.BranchIfEqual(processField, true);
                ctx.LoadValue(field);
                ctx.LoadValue(1); // < 1 - exit
                ctx.BranchIfLess(end, false);

                // default: skip
                ctx.LoadReaderWriter();
                ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("SkipField"));
                ctx.Branch(next, true);

                // process
                ctx.MarkLabel(processField);
                if (Tail.RequiresOldValue)
                {
                    if (Helpers.IsValueType(expectedType))
                    {
                        ctx.LoadAddress(oldValue, expectedType);
                        ctx.EmitCall(expectedType.GetMethod("GetValueOrDefault", Helpers.EmptyTypes));
                    }
                    else
                    {
                        ctx.LoadValue(oldValue);
                    }
                }
                Tail.EmitRead(ctx, null);
                // note we demanded always returns a value
                if (Helpers.IsValueType(expectedType))
                {
                    ctx.EmitCtor(expectedType, Tail.ExpectedType); // re-nullable<T> it
                }
                ctx.StoreValue(oldValue);
                ctx.Branch(next, false);

                // outro
                ctx.MarkLabel(end);
               
                ctx.LoadValue(token);
                ctx.LoadReaderWriter();
                ctx.EmitCall(ctx.MapType(typeof(ProtoReader)).GetMethod("EndSubItem"));
                ctx.LoadValue(oldValue); // load the old value
            }
        }
开发者ID:gezidan,项目名称:ZYSOCKET,代码行数:60,代码来源:NullDecorator.cs

示例4: EmitReadAndAddItem

 private static void EmitReadAndAddItem(Compiler.CompilerContext ctx, Compiler.Local list, IProtoSerializer tail, MethodInfo add)
 {
     ctx.LoadValue(list);
     Type itemType = tail.ExpectedType;
     if (tail.RequiresOldValue)
     {
         if (itemType.IsValueType || !tail.ReturnsValue)
         {
             // going to need a variable
             using (Compiler.Local item = new Compiler.Local(ctx, itemType))
             {
                 if (itemType.IsValueType)
                 {   // initialise the struct
                     ctx.LoadAddress(item, itemType);
                     ctx.EmitCtor(itemType);
                 }
                 else
                 {   // assign null
                     ctx.LoadNullRef();
                     ctx.StoreValue(item);
                 }
                 tail.EmitRead(ctx, item);
                 if (!tail.ReturnsValue) { ctx.LoadValue(item); }
             }
         }
         else
         {    // no variable; pass the null on the stack and take the value *off* the stack
             ctx.LoadNullRef();
             tail.EmitRead(ctx, null);
         }
     }
     else
     {
         if (tail.ReturnsValue)
         {   // out only (on the stack); just emit it
             tail.EmitRead(ctx, null);
         }
         else
         {   // doesn't take anything in nor return anything! WTF?
             throw new InvalidOperationException();
         }
     }
     // our "Add" is chosen either to take the correct type, or to take "object";
     // we may need to box the value
         
     Type addParamType = add.GetParameters()[0].ParameterType;
     if(addParamType != itemType) {
         if (addParamType == typeof(object))
         {
             ctx.CastToObject(itemType);
         }
         else
         {
             throw new InvalidOperationException("Conflicting item/add type");
         }
     }
     ctx.EmitCall(add);
     if (add.ReturnType != typeof(void))
     {
         ctx.DiscardValue();
     }
 }
开发者ID:KimimaroTsukimiya,项目名称:SteamBot-1,代码行数:62,代码来源:ListDecorator.cs

示例5: EmitCreateIfNull

        private void EmitCreateIfNull(Compiler.CompilerContext ctx, Type type, Compiler.Local storage)
        {
            Helpers.DebugAssert(storage != null);
            if (!type.IsValueType)
            {
                Compiler.CodeLabel afterNullCheck = ctx.DefineLabel();
                ctx.LoadValue(storage);
                ctx.BranchIfTrue(afterNullCheck, true);

                // different ways of creating a new instance
                bool callNoteObject = true;
                if (!useConstructor)
                {   // DataContractSerializer style
                    ctx.LoadValue(constructType);
                    ctx.EmitCall(typeof(BclHelpers).GetMethod("GetUninitializedObject"));
                    ctx.Cast(forType);
                }
                else if (constructType.IsClass && hasConstructor)
                {   // XmlSerializer style
                    ctx.EmitCtor(constructType);
                }
                else
                {
                    ctx.LoadValue(type);
                    ctx.EmitCall(typeof(TypeModel).GetMethod("ThrowCannotCreateInstance",
                        BindingFlags.Static | BindingFlags.Public));
                    ctx.LoadNullRef();
                    callNoteObject = false;
                }
                if (callNoteObject)
                {
                // track root object creation
                ctx.CopyValue();
                ctx.LoadReaderWriter();
                ctx.EmitCall(typeof(ProtoReader).GetMethod("NoteObject",
                        BindingFlags.Static | BindingFlags.Public));
                }
                if (baseCtorCallbacks != null) {
                    for (int i = 0; i < baseCtorCallbacks.Length; i++) {
                        EmitInvokeCallback(ctx, baseCtorCallbacks[i]);
                    }
                }
                if (callbacks != null) EmitInvokeCallback(ctx, callbacks.BeforeDeserialize);
                ctx.StoreValue(storage);
                ctx.MarkLabel(afterNullCheck);
            }
        }
开发者ID:helios57,项目名称:anrl,代码行数:47,代码来源:TypeSerializer.cs

示例6: EmitRead

        public void EmitRead(Compiler.CompilerContext ctx, Compiler.Local incoming)
        {
			bool issueReferenceDirectives = !baseTupleAsReference && asReference;
        	
			Compiler.CodeLabel @end = ctx.DefineLabel();

			using (Compiler.Local tupleKey = new Compiler.Local(ctx, typeof(int)))
			using (Compiler.Local oldTuple = new Compiler.Local(ctx, typeof(object)))
			using (Compiler.Local objValue = ctx.GetLocalWithValue(ExpectedType, incoming))
			{
				Compiler.Local[] locals = new Compiler.Local[members.Length];
				try
				{
					if (issueReferenceDirectives)
					{
						//int tupleKey = 0;
						ctx.LoadValue(0);
						ctx.StoreValue(tupleKey);

						//object oldTuple = null;
						ctx.LoadNullRef();
						ctx.StoreValue(oldTuple);

						//tupleKey = (int)source.ReadUInt32();
						ctx.LoadReaderWriter();
						ctx.EmitCall(typeof (ProtoReader).GetMethod("ReadUInt32"));
						//ctx.CastToObject(typeof (int));
						ctx.StoreValue(tupleKey);

						Compiler.CodeLabel @objectNotFound = ctx.DefineLabel();

						ctx.LoadValue(tupleKey);
						ctx.LoadValue(0);
						ctx.BranchIfEqual(@objectNotFound, true);

						//// return source.NetCache.GetKeyedObject(tupleKey);
						ctx.LoadReaderWriter();
						ctx.LoadValue(typeof (ProtoReader).GetProperty("NetCache"));
						ctx.LoadValue(tupleKey);
						ctx.EmitCall(typeof (NetObjectCache).GetMethod("GetKeyedObject"));
						ctx.CastFromObject(ExpectedType);
						ctx.StoreValue(objValue);
						ctx.Branch(@end, false);

						ctx.MarkLabel(@objectNotFound);

						ctx.EmitCtor(typeof (object));
						ctx.StoreValue(oldTuple);

						// tupleKey = source.NetCache.AddObjectKey(oldTuple, out dummy);
						using (Compiler.Local dummy = new Compiler.Local(ctx, typeof (bool)))
						{
							ctx.LoadReaderWriter();
							ctx.LoadValue(typeof (ProtoReader).GetProperty("NetCache"));
							ctx.LoadValue(oldTuple);
							ctx.LoadAddress(dummy, typeof (bool));
							ctx.EmitCall(typeof (NetObjectCache).GetMethod("AddObjectKey", new Type[] { typeof(object), typeof(bool).MakeByRefType() }));
							ctx.StoreValue(tupleKey);
						}
					}

					for (int i = 0; i < locals.Length; i++)
					{
						Type type = GetMemberType(i);
						bool store = true;
						locals[i] = new Compiler.Local(ctx, type);
						if (!ExpectedType.IsValueType)
						{
							// value-types always read the old value
							if (type.IsValueType)
							{
								switch (Helpers.GetTypeCode(type))
								{
									case ProtoTypeCode.Boolean:
									case ProtoTypeCode.Byte:
									case ProtoTypeCode.Int16:
									case ProtoTypeCode.Int32:
									case ProtoTypeCode.SByte:
									case ProtoTypeCode.UInt16:
									case ProtoTypeCode.UInt32:
										ctx.LoadValue(0);
										break;
									case ProtoTypeCode.Int64:
									case ProtoTypeCode.UInt64:
										ctx.LoadValue(0L);
										break;
									case ProtoTypeCode.Single:
										ctx.LoadValue(0.0F);
										break;
									case ProtoTypeCode.Double:
										ctx.LoadValue(0.0D);
										break;
									case ProtoTypeCode.Decimal:
										ctx.LoadValue(0M);
										break;
									case ProtoTypeCode.Guid:
										ctx.LoadValue(Guid.Empty);
										break;
									default:
										ctx.LoadAddress(locals[i], type);
//.........这里部分代码省略.........
开发者ID:JayCap,项目名称:Protobuf-net-Patch-and-T4-TypeModel-Generator,代码行数:101,代码来源:TupleSerializer.cs

示例7: EmitCreateIfNull

        private void EmitCreateIfNull(Compiler.CompilerContext ctx, Type type, Compiler.Local storage)
        {
            Helpers.DebugAssert(storage != null);
            if (!type.IsValueType)
            {
                Compiler.CodeLabel afterNullCheck = ctx.DefineLabel();
                ctx.LoadValue(storage);
                ctx.BranchIfTrue(afterNullCheck, true);

                // different ways of creating a new instance
                if (!useConstructor)
                {   // DataContractSerializer style
                    ctx.LoadValue(forType);
                    ctx.EmitCall(typeof(BclHelpers).GetMethod("GetUninitializedObject"));
                    ctx.Cast(forType);
                } else if (type.IsClass && !type.IsAbstract && (
                    (type.GetConstructor(
                    BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public,
                    null, Helpers.EmptyTypes, null)) != null))
                {   // XmlSerializer style
                    ctx.EmitCtor(type);
                }
                else
                {
                    ctx.LoadValue(type);
                    ctx.EmitCall(typeof(TypeModel).GetMethod("ThrowCannotCreateInstance",
                        BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
                    ctx.LoadNullRef();
                }
                if (baseCtorCallbacks != null) {
                    for (int i = 0; i < baseCtorCallbacks.Length; i++) {
                        EmitInvokeCallback(ctx, baseCtorCallbacks[i]);
                    }
                }
                if (callbacks != null) EmitInvokeCallback(ctx, callbacks.BeforeDeserialize);
                ctx.StoreValue(storage);
                ctx.MarkLabel(afterNullCheck);
            }
        }
开发者ID:martindevans,项目名称:DistributedServiceProvider,代码行数:39,代码来源:TypeSerializer.cs

示例8: EmitInvokeCallback

        static void EmitInvokeCallback(Compiler.CompilerContext ctx, MethodInfo method)
        {
            if (method != null)
            {
                ctx.CopyValue(); // assumes the target is on the stack, and that we want to *retain* it on the stack
#if PLAT_BINARYFORMATTER
                if (method.GetParameters().Length == 1)
                {
                    ctx.LoadValue((int)StreamingContextState);
                    ctx.EmitCtor(typeof(System.Runtime.Serialization.StreamingContext), new Type[] { typeof(System.Runtime.Serialization.StreamingContextStates) });
                }
#endif
                ctx.EmitCall(method);
            }
        }
开发者ID:martindevans,项目名称:DistributedServiceProvider,代码行数:15,代码来源:TypeSerializer.cs


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