UWP 프로젝트에 동적 수학 평가자를 포함하는 방법은 무엇입니까?

해피 피그 375

Windows Forms에서 식을 계산하고 입력 코드를 실행하기 위해 JScript.NET을 사용해 왔습니다.

이렇게 : (55 % 6) + Math.acos(0.4) - ~ 9 * Math.PI + Math.random()=33.72725296117653

이제 Xamarin Forms에서 동일한 것을 원하지만 라이브러리는 Android (iOS 아직 테스트되지 않음)에서만 작동하며 UWP 프로젝트는 ApplicationException을 찾을 수 없다고 계속 표시합니다.

JScript.NET 라이브러리를 업데이트하지 않으므로 더 이상 사용되지 않는 Vsa 엔진은 문제가되지 않습니다.

지금까지 시도한 것

ILSpy로 lbrary를 디 컴파일했지만 mscorlib.dll을 너무 많이 참조하여 포기했습니다. 나는 마치 ... 와우.Javascript 평가자를 찾았지만 mscorlib.dll도 참조합니다.

Microsoft에서 허용하지 않는 것처럼 보이기 때문에 프로젝트에 mscorlib를 포함해야하는지 모르겠습니다.

해결책이 있습니까? 미리 감사드립니다.

편집하다:

도움이되는 경우 JScript 8.0 라이브러리 사용.

가능하면 Win8.1 / WinPhone 8.1 프로젝트와도 호환되는 솔루션을 제안하십시오.

해피 피그 375

결국 저는 Javascript 인터프리터 인 무료 오픈 소스 인 Jint 를 사용하게되었으며 (라이선스에 대해 걱정할 필요가 없습니다!) Type에 대한 약간의 확장 메서드를 사용하면 Win8.1에서도 작동하는 것 같습니다.

#if WINDOWS_APP || WINDOWS_PHONE_APP
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodInfos = System.Collections.Generic.IEnumerable<System.Reflection.MethodInfo>;
namespace System.Reflection
{
    public static class CustomExtensions
    {
        public static Assembly Assembly(this Type T) { return T.GetTypeInfo().Assembly; }
        public static MethodInfos GetDeclaredMethods(this Type T) { return T.GetTypeInfo().DeclaredMethods; }
        public static MethodInfo GetDeclaredMethod(this Type T, string name) { return T.GetTypeInfo().GetDeclaredMethod(name); }
        public static bool IsInstanceOfType(this Type T, object o)
        {
            if (o == null)
                return false;

            // No need for transparent proxy casting check here
            // because it never returns true for a non-rutnime type.

            return T.GetTypeInfo().IsAssignableFrom(o.GetType().GetTypeInfo());
        }
        public static bool IsAssignableFrom(this Type T1, Type T2)
        { return T1.GetTypeInfo().IsAssignableFrom(T2.GetType().GetTypeInfo()); }
        public static bool IsEnum(this Type type)
        {
            return type.GetTypeInfo().IsEnum;
        }

        public static bool IsGenericType(this Type type)
        {
            return type.GetTypeInfo().IsGenericType;
        }

        public static bool IsValueType(this Type type)
        {
            return type.GetTypeInfo().IsValueType;
        }

        public static bool HasAttribute<T>(this ParameterInfo member) where T : Attribute
        {
            return member.GetCustomAttributes<T>().Any();
        }

        public static Type[] GetGenericArguments(this Type T)
        { return T.GetTypeInfo().GenericTypeArguments; }
        public static MethodInfo GetMethod(this Type T, string Name)
        { return T.GetTypeInfo().GetDeclaredMethod(Name); }
        public static MethodInfo GetMethod(this Type T, string Name, Type[] Types)
        {
            var Params = T.GetTypeInfo().GetDeclaredMethods(Name);
            foreach (var Item in Params)
            {
                bool Yes = false;
                for (int i = 0; i < Types.Count(); i++)
                    Yes |= Types[i] == Item.GetParameters()[i].ParameterType;
                if (Yes) return Item;
            }
            return null;
        }
        public static IEnumerable<Type> GetNestedTypes(this Type T)
        { foreach (TypeInfo Info in T.GetTypeInfo().DeclaredNestedTypes)
                yield return Info.AsType();
        }
        public static IEnumerable<Type> GetNestedTypes(this Type T, BindingFlags Flags)
        {
            foreach (TypeInfo Info in T.GetTypeInfo().DeclaredNestedTypes)
                if(Filter(T.GetTypeInfo(), Flags)) yield return Info.AsType();
        }
        private static bool Filter(TypeInfo Info, BindingFlags Flags)
        {
            bool Return = false;
            if (Flags.HasFlag(BindingFlags.DeclaredOnly)) Return |= Info.IsNested;
            if (Flags.HasFlag(BindingFlags.Instance)) Return |= !(Info.IsAbstract | Info.IsSealed);
            if (Flags.HasFlag(BindingFlags.Static)) Return |= Info.IsAbstract | Info.IsSealed;
            if (Flags.HasFlag(BindingFlags.Public)) Return |= Info.IsPublic;
            if (Flags.HasFlag(BindingFlags.NonPublic)) Return |= Info.IsNotPublic;
            return Return;
        }
        private static bool Filter(MethodInfo Info, BindingFlags Flags)
        {
            bool Return = false;
            if (Flags.HasFlag(BindingFlags.DeclaredOnly)) Return |= Info.IsFamily;
            if (Flags.HasFlag(BindingFlags.Instance)) Return |= !Info.IsStatic;
            if (Flags.HasFlag(BindingFlags.Static)) Return |= Info.IsStatic;
            if (Flags.HasFlag(BindingFlags.Public)) Return |= Info.IsPublic;
            if (Flags.HasFlag(BindingFlags.NonPublic)) Return |= !Info.IsPublic;
            return Return;
        }
        public static IEnumerable<Type> GetTypes(this Assembly A)
        { return A.ExportedTypes; }
    }
    /// <summary>Specifies flags that control binding and the way in which the search for members and types is conducted by reflection.</summary>
    [Flags, Runtime.InteropServices.ComVisible(true)]
    public enum BindingFlags
    {
        /// <summary>Specifies no binding flag.</summary>
        Default = 0,
        /// <summary>Specifies that the case of the member name should not be considered when binding.</summary>
        //IgnoreCase = 1,
        /// <summary>Specifies that only members declared at the level of the supplied type's hierarchy should be considered. Inherited members are not considered.</summary>
        DeclaredOnly = 2,
        /// <summary>Specifies that instance members are to be included in the search.</summary>
        Instance = 4,
        /// <summary>Specifies that static members are to be included in the search.</summary>
        Static = 8,
        /// <summary>Specifies that public members are to be included in the search.</summary>
        Public = 16,
        /// <summary>Specifies that non-public members are to be included in the search.</summary>
        NonPublic = 32,
        /*
        /// <summary>Specifies that public and protected static members up the hierarchy should be returned. Private static members in inherited classes are not returned. Static members include fields, methods, events, and properties. Nested types are not returned.</summary>
        FlattenHierarchy = 64,
        /// <summary>Specifies that a method is to be invoked. This must not be a constructor or a type initializer.</summary>
        InvokeMethod = 256,
        /// <summary>Specifies that Reflection should create an instance of the specified type. Calls the constructor that matches the given arguments. The supplied member name is ignored. If the type of lookup is not specified, (Instance | Public) will apply. It is not possible to call a type initializer.</summary>
        CreateInstance = 512,
        /// <summary>Specifies that the value of the specified field should be returned.</summary>
        GetField = 1024,
        /// <summary>Specifies that the value of the specified field should be set.</summary>
        SetField = 2048,
        /// <summary>Specifies that the value of the specified property should be returned.</summary>
        GetProperty = 4096,
        /// <summary>Specifies that the value of the specified property should be set. For COM properties, specifying this binding flag is equivalent to specifying PutDispProperty and PutRefDispProperty.</summary>
        SetProperty = 8192,
        /// <summary>Specifies that the PROPPUT member on a COM object should be invoked. PROPPUT specifies a property-setting function that uses a value. Use PutDispProperty if a property has both PROPPUT and PROPPUTREF and you need to distinguish which one is called.</summary>
        PutDispProperty = 16384,
        /// <summary>Specifies that the PROPPUTREF member on a COM object should be invoked. PROPPUTREF specifies a property-setting function that uses a reference instead of a value. Use PutRefDispProperty if a property has both PROPPUT and PROPPUTREF and you need to distinguish which one is called.</summary>
        PutRefDispProperty = 32768,
        /// <summary>Specifies that types of the supplied arguments must exactly match the types of the corresponding formal parameters. Reflection throws an exception if the caller supplies a non-null Binder object, since that implies that the caller is supplying BindToXXX implementations that will pick the appropriate method.</summary>
        ExactBinding = 65536,
        /// <summary>Not implemented.</summary>
        SuppressChangeType = 131072,
        /// <summary>Returns the set of members whose parameter count matches the number of supplied arguments. This binding flag is used for methods with parameters that have default values and methods with variable arguments (varargs). This flag should only be used with <see cref="M:System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[])" />.</summary>
        OptionalParamBinding = 262144,
        /// <summary>Used in COM interop to specify that the return value of the member can be ignored.</summary>
        IgnoreReturn = 16777216
        */
    }
}
#endif

이제 예제 코드를 변경하고 어디에서나 원활하게 평가할 필요가 없습니다 (Jint가 DLR 또는 IL 방출 방법을 사용하지 않기 때문에 Xamarin.iOS도 마찬가지입니다. 이는 또 다른 이점입니다)

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

숫자를 수학적으로 결합하는 방법은 무엇입니까?

분류에서Dev

탄력적 검색에서 수학적 표현을 포함하는 문서를 색인화하는 가장 좋은 방법은 무엇입니까?

분류에서Dev

노드 값에 수학 함수를 적용하는 방법은 무엇입니까?

분류에서Dev

dplyr tibble 문자 변수에 수학 기호를 포함하는 방법은 무엇입니까?

분류에서Dev

함수를 동적으로 호출하는 방법은 무엇입니까?

분류에서Dev

문자열을 수학 연산을 포함하는 숫자로 변환하는 방법은 무엇입니까?

분류에서Dev

PEDMAS (수학적 연산 순서)를 위반하지 않도록 SQL 쿼리에 계산을 포함하지 않는 방법은 무엇입니까?

분류에서Dev

다른 프로젝트 Xamarin 프로젝트에 BroadcastReceiver를 포함하는 방법은 무엇입니까?

분류에서Dev

Chrome에서 Eclipse의 동적 웹 프로젝트를 실행하는 방법은 무엇입니까?

분류에서Dev

프로젝트에 CMS를 자동으로 포함 / 복원하면서 버전 관리에서 CMS를 생략하는 방법은 무엇입니까?

분류에서Dev

docker-compose.yml 파일에서 동적 변수를 평가하는 방법은 무엇입니까?

분류에서Dev

프로젝트 어셈블리-프로젝트 어셈블리 "학습 모음 문자"코드에 마크를 추가하는 방법은 무엇입니까?

분류에서Dev

프로젝트 루트에서 프로젝트 루트 / 트렁크로 프로젝트를 이동하는 방법은 무엇입니까?

분류에서Dev

Kotlin Android Studio에서 문자열 리소스 ID를 포함하는 변수를 동적으로 설정하는 방법은 무엇입니까?

분류에서Dev

Eclipse Kepler에서 동적 웹 프로젝트를 만드는 방법은 무엇입니까?

분류에서Dev

uwp에서 이와 같은 자동 적응 패널을 작성하는 방법은 무엇입니까?

분류에서Dev

UWP의 DataGrid에 동적으로 행을 추가하는 방법은 무엇입니까?

분류에서Dev

프로젝트를 실행하는 동안 xcode AppDelegate 오류를 수정하는 방법은 무엇입니까?

분류에서Dev

R microbenchmark : 평가 된 함수에 동일한 인수를 전달하는 방법은 무엇입니까?

분류에서Dev

Visual Studio에서 프로젝트에 파일을 자동으로 추가하는 방법은 무엇입니까?

분류에서Dev

Bigquery가 포함 된 Tableau 8.2, 자동 인증 새로 고침을 수행하는 방법은 무엇입니까?

분류에서Dev

클라우드 함수 typescript 프로젝트에서 내 eslintrc를 구성하는 방법은 무엇입니까?

분류에서Dev

C에서 과학적 표기법없이 큰 이중 수를 표시하는 방법은 무엇입니까?

분류에서Dev

동적으로 채워진 div에 onClick 함수를 추가하는 방법은 무엇입니까?

분류에서Dev

내 자신의 자바 스크립트 수학 방법을 작동시키는 방법은 무엇입니까?

분류에서Dev

LaTeX 수학 모드 방정식을 Python / Numpy 코드로 자동 변환하는 방법은 무엇입니까?

분류에서Dev

프로젝트에 부트 스트랩을 포함하는 가장 좋은 방법은 무엇입니까?

분류에서Dev

수학적 관점에서 고차 함수와 IO 동작을 보는 방법은 무엇입니까?

분류에서Dev

Android 프로젝트의 예외를 Firebase에 자동으로보고하는 방법은 무엇입니까?

Related 관련 기사

  1. 1

    숫자를 수학적으로 결합하는 방법은 무엇입니까?

  2. 2

    탄력적 검색에서 수학적 표현을 포함하는 문서를 색인화하는 가장 좋은 방법은 무엇입니까?

  3. 3

    노드 값에 수학 함수를 적용하는 방법은 무엇입니까?

  4. 4

    dplyr tibble 문자 변수에 수학 기호를 포함하는 방법은 무엇입니까?

  5. 5

    함수를 동적으로 호출하는 방법은 무엇입니까?

  6. 6

    문자열을 수학 연산을 포함하는 숫자로 변환하는 방법은 무엇입니까?

  7. 7

    PEDMAS (수학적 연산 순서)를 위반하지 않도록 SQL 쿼리에 계산을 포함하지 않는 방법은 무엇입니까?

  8. 8

    다른 프로젝트 Xamarin 프로젝트에 BroadcastReceiver를 포함하는 방법은 무엇입니까?

  9. 9

    Chrome에서 Eclipse의 동적 웹 프로젝트를 실행하는 방법은 무엇입니까?

  10. 10

    프로젝트에 CMS를 자동으로 포함 / 복원하면서 버전 관리에서 CMS를 생략하는 방법은 무엇입니까?

  11. 11

    docker-compose.yml 파일에서 동적 변수를 평가하는 방법은 무엇입니까?

  12. 12

    프로젝트 어셈블리-프로젝트 어셈블리 "학습 모음 문자"코드에 마크를 추가하는 방법은 무엇입니까?

  13. 13

    프로젝트 루트에서 프로젝트 루트 / 트렁크로 프로젝트를 이동하는 방법은 무엇입니까?

  14. 14

    Kotlin Android Studio에서 문자열 리소스 ID를 포함하는 변수를 동적으로 설정하는 방법은 무엇입니까?

  15. 15

    Eclipse Kepler에서 동적 웹 프로젝트를 만드는 방법은 무엇입니까?

  16. 16

    uwp에서 이와 같은 자동 적응 패널을 작성하는 방법은 무엇입니까?

  17. 17

    UWP의 DataGrid에 동적으로 행을 추가하는 방법은 무엇입니까?

  18. 18

    프로젝트를 실행하는 동안 xcode AppDelegate 오류를 수정하는 방법은 무엇입니까?

  19. 19

    R microbenchmark : 평가 된 함수에 동일한 인수를 전달하는 방법은 무엇입니까?

  20. 20

    Visual Studio에서 프로젝트에 파일을 자동으로 추가하는 방법은 무엇입니까?

  21. 21

    Bigquery가 포함 된 Tableau 8.2, 자동 인증 새로 고침을 수행하는 방법은 무엇입니까?

  22. 22

    클라우드 함수 typescript 프로젝트에서 내 eslintrc를 구성하는 방법은 무엇입니까?

  23. 23

    C에서 과학적 표기법없이 큰 이중 수를 표시하는 방법은 무엇입니까?

  24. 24

    동적으로 채워진 div에 onClick 함수를 추가하는 방법은 무엇입니까?

  25. 25

    내 자신의 자바 스크립트 수학 방법을 작동시키는 방법은 무엇입니까?

  26. 26

    LaTeX 수학 모드 방정식을 Python / Numpy 코드로 자동 변환하는 방법은 무엇입니까?

  27. 27

    프로젝트에 부트 스트랩을 포함하는 가장 좋은 방법은 무엇입니까?

  28. 28

    수학적 관점에서 고차 함수와 IO 동작을 보는 방법은 무엇입니까?

  29. 29

    Android 프로젝트의 예외를 Firebase에 자동으로보고하는 방법은 무엇입니까?

뜨겁다태그

보관