public override CimProperty this[string propertyName]
 {
     get
     {
         int num = 0;
         if (!string.IsNullOrWhiteSpace(propertyName))
         {
             MiResult elementGetIndex = InstanceMethods.GetElement_GetIndex(this._instanceHandle.Handle, propertyName, out num);
             MiResult miResult        = elementGetIndex;
             if (miResult != MiResult.NO_SUCH_PROPERTY)
             {
                 CimException.ThrowIfMiResultFailure(elementGetIndex);
                 return(new CimPropertyOfInstance(this._instanceHandle, this._instance, num));
             }
             else
             {
                 return(null);
             }
         }
         else
         {
             throw new ArgumentNullException("propertyName");
         }
     }
 }
        /// <summary>
        /// Process method calls and translate them into OData.
        /// </summary>
        /// <param name="expression">
        /// The expression to visit.
        /// </param>
        /// <returns>
        /// The visited expression.
        /// </returns>
        private Expression VisitMethodCall(MethodCallExpression expression)
        {
            // Look for either an instance or static method
            string        methodName    = null;
            MemberInfoKey methodInfoKey = new MemberInfoKey(expression.Method);

            if (InstanceMethods.TryGetValue(methodInfoKey, out methodName))
            {
                this.VisitODataMethodCall(expression, methodName, false);
            }
            else if (StaticMethods.TryGetValue(methodInfoKey, out methodName))
            {
                this.VisitODataMethodCall(expression, methodName, true);
            }
            else if (expression.Method.GetRuntimeBaseDefinition().Equals(toStringMethod))
            {
                // handle the ToString method here
                // toString will only occur on expression that rely on a parameter,
                // because otherwise the partial evaluator would have already evaluated it
                // we get the base definition to detect overrides of ToString, which are pretty common
                this.Visit(expression.Object);
            }
            else
            {
                this.VisitCustomMethodCall(expression);
            }

            return(expression);
        }
Example #3
0
        public CimInstance(CimClass cimClass)
        {
            InstanceHandle instanceHandle = null;

            this._CimSessionInstanceID = Guid.Empty;
            if (cimClass != null)
            {
                MiResult miResult = ApplicationMethods.NewInstance(CimApplication.Handle, cimClass.CimSystemProperties.ClassName, cimClass.ClassHandle, out instanceHandle);
                if (miResult != MiResult.INVALID_PARAMETER)
                {
                    CimException.ThrowIfMiResultFailure(miResult);
                    this._myHandle = new SharedInstanceHandle(instanceHandle);
                    miResult       = InstanceMethods.SetNamespace(this._myHandle.Handle, cimClass.CimSystemProperties.Namespace);
                    CimException.ThrowIfMiResultFailure(miResult);
                    miResult = InstanceMethods.SetServerName(this._myHandle.Handle, cimClass.CimSystemProperties.ServerName);
                    CimException.ThrowIfMiResultFailure(miResult);
                    return;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("cimClass");
                }
            }
            else
            {
                throw new ArgumentNullException("cimClass");
            }
        }
Example #4
0
        public CimInstance(string className, string namespaceName)
        {
            InstanceHandle instanceHandle = null;

            this._CimSessionInstanceID = Guid.Empty;
            if (className != null)
            {
                MiResult miResult  = ApplicationMethods.NewInstance(CimApplication.Handle, className, null, out instanceHandle);
                MiResult miResult1 = miResult;
                if (miResult1 != MiResult.INVALID_PARAMETER)
                {
                    CimException.ThrowIfMiResultFailure(miResult);
                    this._myHandle = new SharedInstanceHandle(instanceHandle);
                    if (namespaceName != null)
                    {
                        miResult = InstanceMethods.SetNamespace(this._myHandle.Handle, namespaceName);
                        CimException.ThrowIfMiResultFailure(miResult);
                    }
                    return;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("className");
                }
            }
            else
            {
                throw new ArgumentNullException("className");
            }
        }
Example #5
0
        public override void Freeze()
        {
            base.Freeze();

            NamedConstructors    = NamedConstructors.AsReadOnly();
            InstanceMethods      = InstanceMethods.AsReadOnly();
            StaticMethods        = StaticMethods.AsReadOnly();
            StaticInitStatements = StaticInitStatements.AsReadOnly();
        }
Example #6
0
        public override void Freeze()
        {
            base.Freeze();

            TypeArgumentNames     = TypeArgumentNames.AsReadOnly();
            ImplementedInterfaces = ImplementedInterfaces.AsReadOnly();
            NamedConstructors     = NamedConstructors.AsReadOnly();
            InstanceMethods       = InstanceMethods.AsReadOnly();
            StaticMethods         = StaticMethods.AsReadOnly();
            StaticInitStatements  = StaticInitStatements.AsReadOnly();
        }
 public override void Add(CimProperty newProperty)
 {
     if (newProperty != null)
     {
         MiResult miResult = InstanceMethods.AddElement(this._instanceHandle.Handle, newProperty.Name, CimInstance.ConvertToNativeLayer(newProperty.Value), newProperty.CimType.ToMiType(), newProperty.Flags.ToMiFlags());
         CimException.ThrowIfMiResultFailure(miResult);
         return;
     }
     else
     {
         throw new ArgumentNullException("newProperty");
     }
 }
Example #8
0
        public void Merge(KumaClass klass)
        {
            foreach (var key in klass.ClassMethods.Keys)
            {
                KumaMethodTable table;
                if (ClassMethods.ContainsKey(key))
                {
                    table = ClassMethods[key];
                }
                else
                {
                    table = new KumaMethodTable(key);
                }
                foreach (var func in klass.ClassMethods[key].Functions)
                {
                    table.AddFunction(func);
                }
            }

            foreach (var key in klass.InstanceMethods.Keys)
            {
                KumaMethodTable table;
                if (InstanceMethods.ContainsKey(key))
                {
                    table = InstanceMethods[key];
                }
                else
                {
                    table = new KumaMethodTable(key);
                }
                foreach (var func in klass.InstanceMethods[key].Functions)
                {
                    table.AddFunction(func);
                }
            }

            Context.MergeWithScope(klass.Context);
        }
Example #9
0
        static void Main(string[] args)
        {
            // Language INtergrated Query : 데이터 질의 기능.
            // 기존 Loop와 Linq Code비교.
            ReplacingLoopByusingLinq replaceLoop = new ReplacingLoopByusingLinq();

            replaceLoop.Run();

            int luckyNumber   = 7;
            int unluckyNumber = 4;
            int value         = 0;
            int sum           = 0;

            int multipleLuckyNumber1 = luckyNumber.multiplyByTwo();                //Extension
            int multipleLuckyNumber2 = InstanceMethods.multiplyByTwo(luckyNumber); //Instance

            Func <int, int, int> Plus  = (a, b) => a + b;                          //Return 존재
            Action <int, int>    Minus = (a, b) => value = a - b;                  // Void

            // (a,b ) = a+b ;
            // Lamda Expression : (input parameters) => expression
            // Linq Query식을 만드는데 유용하게 사용.
            Console.WriteLine(sum);
            sum = Plus(luckyNumber, unluckyNumber);
            Console.WriteLine(sum);

            Minus(luckyNumber, unluckyNumber);
            Console.WriteLine(value);

            DeferredVsImmediate obj = new DeferredVsImmediate();

            obj.ImmediateRun();
            obj.DeferredRun();


            Console.ReadKey();
        }
Example #10
0
        /// <summary>
        /// Initialize generic method instances with argument types and runtime function indices from InstanceMethodEntrypoints
        /// </summary>
        private void ParseInstanceMethodEntrypoints(bool[] isEntryPoint)
        {
            if (!R2RHeader.Sections.ContainsKey(R2RSection.SectionType.READYTORUN_SECTION_INSTANCE_METHOD_ENTRYPOINTS))
            {
                return;
            }
            R2RSection      instMethodEntryPointSection = R2RHeader.Sections[R2RSection.SectionType.READYTORUN_SECTION_INSTANCE_METHOD_ENTRYPOINTS];
            int             instMethodEntryPointsOffset = GetOffset(instMethodEntryPointSection.RelativeVirtualAddress);
            NativeParser    parser = new NativeParser(Image, (uint)instMethodEntryPointsOffset);
            NativeHashtable instMethodEntryPoints = new NativeHashtable(Image, parser, (uint)(instMethodEntryPointsOffset + instMethodEntryPointSection.Size));

            NativeHashtable.AllEntriesEnumerator allEntriesEnum = instMethodEntryPoints.EnumerateAllEntries();
            NativeParser curParser = allEntriesEnum.GetNext();

            while (!curParser.IsNull())
            {
                SignatureDecoder decoder  = new SignatureDecoder(_assemblyResolver, this, (int)curParser.Offset);
                MetadataReader   mdReader = MetadataReader;

                string owningType = null;

                uint methodFlags = decoder.ReadUInt();
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0)
                {
                    mdReader   = decoder.GetMetadataReaderFromModuleOverride();
                    owningType = decoder.ReadTypeSignatureNoEmit();
                }
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_SlotInsteadOfToken) != 0)
                {
                    throw new NotImplementedException();
                }
                EntityHandle methodHandle;
                int          rid = (int)decoder.ReadUInt();
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MemberRefToken) != 0)
                {
                    methodHandle = MetadataTokens.MemberReferenceHandle(rid);
                }
                else
                {
                    methodHandle = MetadataTokens.MethodDefinitionHandle(rid);
                }
                string[] methodTypeArgs = null;
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MethodInstantiation) != 0)
                {
                    uint typeArgCount = decoder.ReadUInt();
                    methodTypeArgs = new string[typeArgCount];
                    for (int typeArgIndex = 0; typeArgIndex < typeArgCount; typeArgIndex++)
                    {
                        methodTypeArgs[typeArgIndex] = decoder.ReadTypeSignatureNoEmit();
                    }
                }

                string constrainedType = null;
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_Constrained) != 0)
                {
                    constrainedType = decoder.ReadTypeSignatureNoEmit();
                }

                int         runtimeFunctionId;
                FixupCell[] fixups;
                GetRuntimeFunctionIndexFromOffset((int)decoder.Offset, out runtimeFunctionId, out fixups);
                R2RMethod method = new R2RMethod(
                    R2RMethods.Count,
                    mdReader == null ? MetadataReader : mdReader,
                    methodHandle,
                    runtimeFunctionId,
                    owningType,
                    constrainedType,
                    methodTypeArgs,
                    fixups);
                if (method.EntryPointRuntimeFunctionId >= 0 && method.EntryPointRuntimeFunctionId < isEntryPoint.Length)
                {
                    isEntryPoint[method.EntryPointRuntimeFunctionId] = true;
                }
                R2RMethods.Add(method);
                InstanceMethods.Add(new InstanceMethod(curParser.LowHashcode, method));
                curParser = allEntriesEnum.GetNext();
            }
        }
Example #11
0
        /// <summary>
        /// Initialize generic method instances with argument types and runtime function indices from InstanceMethodEntrypoints
        /// </summary>
        private void ParseInstanceMethodEntrypoints(bool[] isEntryPoint)
        {
            if (!ReadyToRunHeader.Sections.TryGetValue(ReadyToRunSectionType.InstanceMethodEntryPoints, out ReadyToRunSection instMethodEntryPointSection))
            {
                return;
            }
            int             instMethodEntryPointsOffset = GetOffset(instMethodEntryPointSection.RelativeVirtualAddress);
            NativeParser    parser = new NativeParser(Image, (uint)instMethodEntryPointsOffset);
            NativeHashtable instMethodEntryPoints = new NativeHashtable(Image, parser, (uint)(instMethodEntryPointsOffset + instMethodEntryPointSection.Size));

            NativeHashtable.AllEntriesEnumerator allEntriesEnum = instMethodEntryPoints.EnumerateAllEntries();
            NativeParser curParser = allEntriesEnum.GetNext();

            while (!curParser.IsNull())
            {
                SignatureDecoder decoder  = new SignatureDecoder(_assemblyResolver, this, (int)curParser.Offset);
                MetadataReader   mdReader = _composite ? null : _assemblyCache[0];

                string owningType = null;

                uint methodFlags = decoder.ReadUInt();
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0)
                {
                    mdReader = decoder.GetMetadataReaderFromModuleOverride();
                    if (mdReader == null)
                    {
                        // The only types that don't have module overrides on them in composite images are primitive types within System.Private.CoreLib
                        mdReader = _assemblyResolver.FindAssembly("System.Private.CoreLib", Filename);
                    }
                    owningType = decoder.ReadTypeSignatureNoEmit();
                }
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_SlotInsteadOfToken) != 0)
                {
                    throw new NotImplementedException();
                }
                EntityHandle methodHandle;
                int          rid = (int)decoder.ReadUInt();
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MemberRefToken) != 0)
                {
                    methodHandle = MetadataTokens.MemberReferenceHandle(rid);
                }
                else
                {
                    methodHandle = MetadataTokens.MethodDefinitionHandle(rid);
                }
                string[] methodTypeArgs = null;
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_MethodInstantiation) != 0)
                {
                    uint typeArgCount = decoder.ReadUInt();
                    methodTypeArgs = new string[typeArgCount];
                    for (int typeArgIndex = 0; typeArgIndex < typeArgCount; typeArgIndex++)
                    {
                        methodTypeArgs[typeArgIndex] = decoder.ReadTypeSignatureNoEmit();
                    }
                }

                string constrainedType = null;
                if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_Constrained) != 0)
                {
                    constrainedType = decoder.ReadTypeSignatureNoEmit();
                }

                int runtimeFunctionId;
                int?fixupOffset;
                GetRuntimeFunctionIndexFromOffset((int)decoder.Offset, out runtimeFunctionId, out fixupOffset);
                ReadyToRunMethod method = new ReadyToRunMethod(
                    this,
                    Methods.Count,
                    mdReader,
                    methodHandle,
                    runtimeFunctionId,
                    owningType,
                    constrainedType,
                    methodTypeArgs,
                    fixupOffset);
                if (method.EntryPointRuntimeFunctionId >= 0 && method.EntryPointRuntimeFunctionId < isEntryPoint.Length)
                {
                    isEntryPoint[method.EntryPointRuntimeFunctionId] = true;
                }
                Methods.Add(method);
                InstanceMethods.Add(new InstanceMethod(curParser.LowHashcode, method));
                curParser = allEntriesEnum.GetNext();
            }
        }