當前位置: 首頁>>代碼示例>>C#>>正文


C# StackValue.Equals方法代碼示例

本文整理匯總了C#中ProtoCore.DSASM.StackValue.Equals方法的典型用法代碼示例。如果您正苦於以下問題:C# StackValue.Equals方法的具體用法?C# StackValue.Equals怎麽用?C# StackValue.Equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ProtoCore.DSASM.StackValue的用法示例。


在下文中一共展示了StackValue.Equals方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CompareString

        public static int CompareString(StackValue s1, StackValue s2, RuntimeCore runtimeCore)
        {
            if (!s1.IsString || !s2.IsString)
                return Constants.kInvalidIndex;

            if (s1.Equals(s2))
                return 0;

            string str1 = runtimeCore.RuntimeMemory.Heap.ToHeapObject<DSString>(s1).Value;
            string str2 = runtimeCore.RuntimeMemory.Heap.ToHeapObject<DSString>(s2).Value;
            return string.Compare(str1, str2);
        }
開發者ID:ankushraizada,項目名稱:Dynamo,代碼行數:12,代碼來源:StringUtils.cs

示例2: CompareStackValues

        //this method compares the values of the stack variables passed
        public static bool CompareStackValues(StackValue sv1, StackValue sv2, RuntimeCore rtCore1, RuntimeCore rtCore2, ProtoCore.Runtime.Context context = null)
        {
            if (sv1.optype != sv2.optype)
                return false;

            switch (sv1.optype)
            {
                case AddressType.Invalid:
                    return true;
                case AddressType.Int:
                    return sv1.IntegerValue == sv2.IntegerValue;
                case AddressType.Char:
                    return sv1.CharValue == sv2.CharValue;
                case AddressType.Double:
                    var value1 = sv1.DoubleValue;
                    var value2 = sv2.DoubleValue;

                    if(Double.IsInfinity(value1) && Double.IsInfinity(value2))
                        return true;
                    return MathUtils.Equals(value1, value2);
                case AddressType.Boolean:
                    return sv1.BooleanValue == sv2.BooleanValue;
                case AddressType.ArrayPointer:
                    if (Object.ReferenceEquals(rtCore1, rtCore2) && sv1.ArrayPointer == sv2.ArrayPointer) //if both cores are same and the stack values point to the same heap element, then the stack values are equal
                        return true;

                    DSArray array1 = rtCore1.Heap.ToHeapObject<DSArray>(sv1);
                    DSArray array2 = rtCore2.Heap.ToHeapObject<DSArray>(sv2);
                    return DSArray.CompareFromDifferentCore(array1, array2, rtCore1, rtCore2, context);

                case AddressType.String:
                    if (Object.ReferenceEquals(rtCore1, rtCore2) && sv1.StringPointer == sv2.StringPointer) //if both cores are same and the stack values point to the same heap element, then the stack values are equal
                        return true;
                    DSString s1 = rtCore1.Heap.ToHeapObject<DSString>(sv1);
                    DSString s2 = rtCore1.Heap.ToHeapObject<DSString>(sv2);
                    return s1.Equals(s2);
                case AddressType.Pointer:
                    if (sv1.metaData.type != sv2.metaData.type) //if the type of class is different, then stack values can never be equal
                        return false;
                    if (Object.ReferenceEquals(rtCore1, rtCore2) && sv1.Pointer == sv2.Pointer) //if both cores are same and the stack values point to the same heap element, then the stack values are equal
                        return true;
                    ClassNode classnode = rtCore1.DSExecutable.classTable.ClassNodes[sv1.metaData.type];
                    if (classnode.IsImportedClass)
                    {
                        var helper = ProtoFFI.DLLFFIHandler.GetModuleHelper(ProtoFFI.FFILanguage.CSharp);
                        var marshaller1 = helper.GetMarshaller(rtCore1);
                        var marshaller2 = helper.GetMarshaller(rtCore2);
                        try
                        {
                            //the interpreter is passed as null as it is not expected to be sued while unmarshalling in this scenario
                            object dsObject1 = marshaller1.UnMarshal(sv1, context, null, typeof(Object));
                            object dsObject2 = marshaller2.UnMarshal(sv2, context, null, typeof(Object));
                            //cores are different in debugger nunit testing only. Most of the imported objects don't have implementation of Object.Equals. It
                            //also does not make sense to compare these objects deeply, as only dummy objects are created in nunit testing, and these dummy objects
                            //might have random values. So we just check whether the object tpye is the same for this testing.
                            if (!object.ReferenceEquals(rtCore1, rtCore2))
                                return Object.ReferenceEquals(dsObject1.GetType(), dsObject2.GetType());

                            return Object.Equals(dsObject1, dsObject2);
                        }
                        catch (System.Exception)
                        {
                            return false;
                        }
                    }
                    else
                    {
                        return ComparePointerFromHeap(sv1, sv2, rtCore1, rtCore2, context);
                    }
                default :
                    return sv1.Equals(sv2);
            }
        }
開發者ID:limrzx,項目名稱:Dynamo,代碼行數:74,代碼來源:Stack.cs


注:本文中的ProtoCore.DSASM.StackValue.Equals方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。