private static Union CreateUnion(Type t)
        {
            Union union = new Union();

            object[] args = new object[2];
            args[0]         = t;
            union.TagReader = (FSharpFunction)FSharpUtils.PreComputeUnionTagReader(null, args);
            union.Cases     = new List <UnionCase>();
            object[] objArray2 = new object[2];
            objArray2[0] = t;
            foreach (object obj2 in (object[])FSharpUtils.GetUnionCases(null, objArray2))
            {
                UnionCase item = new UnionCase {
                    Tag    = (int)FSharpUtils.GetUnionCaseInfoTag(obj2),
                    Name   = (string)FSharpUtils.GetUnionCaseInfoName(obj2),
                    Fields = (PropertyInfo[])FSharpUtils.GetUnionCaseInfoFields(obj2, new object[0])
                };
                object[] objArray3 = new object[2];
                objArray3[0]     = obj2;
                item.FieldReader = (FSharpFunction)FSharpUtils.PreComputeUnionReader(null, objArray3);
                object[] objArray4 = new object[2];
                objArray4[0]     = obj2;
                item.Constructor = (FSharpFunction)FSharpUtils.PreComputeUnionConstructor(null, objArray4);
                union.Cases.Add(item);
            }
            return(union);
        }
Exemplo n.º 2
0
        private static Union CreateUnion(Type t)
        {
            Union u = new Union
            {
                TagReader = (FSharpFunction)FSharpUtils.PreComputeUnionTagReader(null, t, null),
                Cases     = new List <UnionCase>()
            };

            object[] cases = (object[])FSharpUtils.GetUnionCases(null, t, null);

            foreach (object unionCaseInfo in cases)
            {
                UnionCase unionCase = new UnionCase
                {
                    Tag         = (int)FSharpUtils.GetUnionCaseInfoTag(unionCaseInfo),
                    Name        = (string)FSharpUtils.GetUnionCaseInfoName(unionCaseInfo),
                    Fields      = (PropertyInfo[])FSharpUtils.GetUnionCaseInfoFields(unionCaseInfo),
                    FieldReader = (FSharpFunction)FSharpUtils.PreComputeUnionReader(null, unionCaseInfo, null),
                    Constructor = (FSharpFunction)FSharpUtils.PreComputeUnionConstructor(null, unionCaseInfo, null)
                };

                u.Cases.Add(unionCase);
            }

            return(u);
        }
Exemplo n.º 3
0
        private static Union CreateUnion(Type t)
        {
            Union u = new Union();

            u.TagReader = (Converter <object, int>)FSharpUtils.PreComputeUnionTagReader(null, t, null);
            u.Cases     = new List <UnionCase>();

            object[] cases = (object[])FSharpUtils.GetUnionCases(null, t, null);

            foreach (object unionCaseInfo in cases)
            {
                UnionCase unionCase = new UnionCase();
                unionCase.Tag         = (int)FSharpUtils.GetUnionCaseInfoTag(unionCaseInfo);
                unionCase.Name        = (string)FSharpUtils.GetUnionCaseInfoName(unionCaseInfo);
                unionCase.Fields      = (PropertyInfo[])FSharpUtils.GetUnionCaseInfoFields(unionCaseInfo);
                unionCase.FieldReader = (Converter <object, object[]>)FSharpUtils.PreComputeUnionReader(null, unionCaseInfo, null);
                unionCase.Constructor = (Converter <object[], object>)FSharpUtils.PreComputeUnionConstructor(null, unionCaseInfo, null);

                u.Cases.Add(unionCase);
            }

            return(u);
        }
Exemplo n.º 4
0
 private static DiscriminatedUnionConverter.Union CreateUnion(Type t)
 {
     DiscriminatedUnionConverter.Union union = new DiscriminatedUnionConverter.Union()
     {
         TagReader = (FSharpFunction)FSharpUtils.PreComputeUnionTagReader(null, new object[] { t, null }),
         Cases     = new List <DiscriminatedUnionConverter.UnionCase>()
     };
     object[] getUnionCases = (object[])FSharpUtils.GetUnionCases(null, new object[] { t, null });
     for (int i = 0; i < (int)getUnionCases.Length; i++)
     {
         object obj = getUnionCases[i];
         DiscriminatedUnionConverter.UnionCase unionCase = new DiscriminatedUnionConverter.UnionCase()
         {
             Tag         = (int)FSharpUtils.GetUnionCaseInfoTag(obj),
             Name        = (string)FSharpUtils.GetUnionCaseInfoName(obj),
             Fields      = (PropertyInfo[])FSharpUtils.GetUnionCaseInfoFields(obj, new object[0]),
             FieldReader = (FSharpFunction)FSharpUtils.PreComputeUnionReader(null, new object[] { obj, null }),
             Constructor = (FSharpFunction)FSharpUtils.PreComputeUnionConstructor(null, new object[] { obj, null })
         };
         union.Cases.Add(unionCase);
     }
     return(union);
 }